summaryrefslogtreecommitdiff
path: root/src/stat.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-02-01 09:59:09 +0000
committerJim Meyering <jim@meyering.net>2003-02-01 09:59:09 +0000
commit442dbd2429ef6d209833c2eaffb6ec18e5ba2c1f (patch)
treef07735a54bdffbc57cee4db280725cd3d19265a0 /src/stat.c
parent3507d9868f20c80f13d797c22286a4f7709c3a45 (diff)
downloadcoreutils-442dbd2429ef6d209833c2eaffb6ec18e5ba2c1f.tar.xz
(G_fail): New global.
(human_time): Diagnose failed localtime, not failed nstrftime. (main): Fail if G_fail is set.
Diffstat (limited to 'src/stat.c')
-rw-r--r--src/stat.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/stat.c b/src/stat.c
index 8018735c0..71b8bb725 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -94,6 +94,9 @@ static struct option const long_options[] = {
{NULL, 0, NULL, 0}
};
+/* Nonzero means we should exit with EXIT_FAILURE upon completion. */
+static int G_fail;
+
char *program_name;
/* Return the type of the specified file system.
@@ -315,19 +318,14 @@ static char *
human_time (time_t const *t)
{
static char str[80];
- char *s;
-
-#if 0 /* %c is too locale-dependent. */
- if (strftime (str, 40, "%c", localtime (t)) > 0)
-#else
- if (nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z",
- localtime (t), 0, 0) > 0)
-#endif
- s = str;
- else
- s = _("Cannot calculate human readable time, sorry");
-
- return s;
+ struct tm *tm = localtime (t);
+ if (tm == NULL)
+ {
+ G_fail = 1;
+ return (char *) _("*** invalid date/time ***");
+ }
+ nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, 0);
+ return str;
}
/* print statfs info */
@@ -807,5 +805,5 @@ main (int argc, char *argv[])
do_statfs (argv[i], terse, format);
}
- exit (EXIT_SUCCESS);
+ exit (G_fail ? EXIT_FAILURE : EXIT_SUCCESS);
}