summaryrefslogtreecommitdiff
path: root/src/stat.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-09-16 07:50:33 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-09-16 07:50:33 +0000
commit158d982669d3d05079da2b9cc8d8fcd8adf35a4b (patch)
tree038bcb1def910a55323b86f5ee12bad2839161a5 /src/stat.c
parent3ecd35f56fbb7f9b3f43cd12f862336acf7dca56 (diff)
downloadcoreutils-158d982669d3d05079da2b9cc8d8fcd8adf35a4b.tar.xz
Include stat-time.h, and use its functions instead of the obsolete
TIMESPEC_NS macro.
Diffstat (limited to 'src/stat.c')
-rw-r--r--src/stat.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/stat.c b/src/stat.c
index 90f02bf27..c9c71c555 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -52,6 +52,7 @@
#include "inttostr.h"
#include "quote.h"
#include "quotearg.h"
+#include "stat-time.h"
#include "strftime.h"
#include "xreadlink.h"
@@ -280,18 +281,18 @@ human_access (struct stat const *statbuf)
}
static char *
-human_time (time_t t, int t_ns)
+human_time (struct timespec t)
{
static char str[MAX (INT_BUFSIZE_BOUND (intmax_t),
(INT_STRLEN_BOUND (int) /* YYYY */
+ 1 /* because YYYY might equal INT_MAX + 1900 */
+ sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +ZZZZ"))];
- struct tm const *tm = localtime (&t);
+ struct tm const *tm = localtime (&t.tv_sec);
if (tm == NULL)
return (TYPE_SIGNED (time_t)
- ? imaxtostr (t, str)
- : umaxtostr (t, str));
- nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, t_ns);
+ ? imaxtostr (t.tv_sec, str)
+ : umaxtostr (t.tv_sec, str));
+ nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, t.tv_nsec);
return str;
}
@@ -506,8 +507,7 @@ print_stat (char *pformat, size_t buf_len, char m,
break;
case 'x':
xstrcat (pformat, buf_len, "s");
- printf (pformat, human_time (statbuf->st_atime,
- TIMESPEC_NS (statbuf->st_atim)));
+ printf (pformat, human_time (get_stat_atime (statbuf)));
break;
case 'X':
xstrcat (pformat, buf_len, TYPE_SIGNED (time_t) ? "ld" : "lu");
@@ -515,8 +515,7 @@ print_stat (char *pformat, size_t buf_len, char m,
break;
case 'y':
xstrcat (pformat, buf_len, "s");
- printf (pformat, human_time (statbuf->st_mtime,
- TIMESPEC_NS (statbuf->st_mtim)));
+ printf (pformat, human_time (get_stat_mtime (statbuf)));
break;
case 'Y':
xstrcat (pformat, buf_len, TYPE_SIGNED (time_t) ? "ld" : "lu");
@@ -524,8 +523,7 @@ print_stat (char *pformat, size_t buf_len, char m,
break;
case 'z':
xstrcat (pformat, buf_len, "s");
- printf (pformat, human_time (statbuf->st_ctime,
- TIMESPEC_NS (statbuf->st_ctim)));
+ printf (pformat, human_time (get_stat_ctime (statbuf)));
break;
case 'Z':
xstrcat (pformat, buf_len, TYPE_SIGNED (time_t) ? "ld" : "lu");