diff options
author | Jim Meyering <meyering@redhat.com> | 2008-06-27 10:54:23 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2008-06-27 10:54:23 +0200 |
commit | a67685628504d92b80eabe7cdc02c500f12b4873 (patch) | |
tree | 55f09b93cd3d7454edf9b235815f0922c10a4d59 | |
parent | e2dbcee444e90e4289bd4bdc36783a5ef00af396 (diff) | |
download | coreutils-a67685628504d92b80eabe7cdc02c500f12b4873.tar.xz |
factor out time_t-to-string conversion idiom
* src/system.h: Include "inttostr.h".
(timetostr): New function, factored out of...
* src/date.c (show_date): Use timetostr.
* src/du.c (show_date): Likewise.
* src/ls.c (print_long_format): Likewise.
* src/pinky.c (time_string): Likewise.
* src/stat.c (human_time): Likewise.
* src/*.c: Don't include inttostr.h, since system.h does.
* src/c99-to-c89.diff: Adjust offsets.
-rw-r--r-- | src/c99-to-c89.diff | 2 | ||||
-rw-r--r-- | src/chown-core.c | 1 | ||||
-rw-r--r-- | src/cksum.c | 1 | ||||
-rw-r--r-- | src/csplit.c | 1 | ||||
-rw-r--r-- | src/date.c | 6 | ||||
-rw-r--r-- | src/df.c | 1 | ||||
-rw-r--r-- | src/du.c | 6 | ||||
-rw-r--r-- | src/expr.c | 1 | ||||
-rw-r--r-- | src/factor.c | 1 | ||||
-rw-r--r-- | src/head.c | 1 | ||||
-rw-r--r-- | src/ls.c | 5 | ||||
-rw-r--r-- | src/pinky.c | 3 | ||||
-rw-r--r-- | src/shred.c | 1 | ||||
-rw-r--r-- | src/sort.c | 1 | ||||
-rw-r--r-- | src/split.c | 1 | ||||
-rw-r--r-- | src/stat.c | 5 | ||||
-rw-r--r-- | src/system.h | 10 | ||||
-rw-r--r-- | src/tail.c | 1 | ||||
-rw-r--r-- | src/test.c | 1 | ||||
-rw-r--r-- | src/wc.c | 1 | ||||
-rw-r--r-- | src/who.c | 3 |
21 files changed, 17 insertions, 36 deletions
diff --git a/src/c99-to-c89.diff b/src/c99-to-c89.diff index 9268d387d..51b0a42ca 100644 --- a/src/c99-to-c89.diff +++ b/src/c99-to-c89.diff @@ -159,7 +159,7 @@ diff -upr src/seq.c src/seq.c diff -upr src/shred.c src/shred.c --- src/shred.c 1970-01-01 00:00:00.000000000 +0000 +++ src/shred.c 1970-01-01 00:00:00.000000000 +0000 -@@ -469,7 +469,7 @@ dopass (int fd, char const *qname, off_t +@@ -468,7 +468,7 @@ dopass (int fd, char const *qname, off_t out. Thus, it shouldn't give up on bad blocks. This code works because lim is always a multiple of SECTOR_SIZE, except at the end. */ diff --git a/src/chown-core.c b/src/chown-core.c index d915ae45e..4ab52ac53 100644 --- a/src/chown-core.c +++ b/src/chown-core.c @@ -25,7 +25,6 @@ #include "system.h" #include "chown-core.h" #include "error.h" -#include "inttostr.h" #include "quote.h" #include "root-dev-ino.h" #include "xfts.h" diff --git a/src/cksum.c b/src/cksum.c index ce6e9c056..a2d49c5b3 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -108,7 +108,6 @@ main (void) # include <getopt.h> # include "long-options.h" # include "error.h" -# include "inttostr.h" /* Number of bytes to read at once. */ # define BUFLEN (1 << 16) diff --git a/src/csplit.c b/src/csplit.c index 7e63ca831..55489c3ab 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -29,7 +29,6 @@ #include "error.h" #include "fd-reopen.h" -#include "inttostr.h" #include "quote.h" #include "safe-read.h" #include "stdio--.h" diff --git a/src/date.c b/src/date.c index 24390529c..9592bf816 100644 --- a/src/date.c +++ b/src/date.c @@ -28,7 +28,6 @@ #include "argmatch.h" #include "error.h" #include "getdate.h" -#include "inttostr.h" #include "posixtm.h" #include "quote.h" #include "stat-time.h" @@ -540,10 +539,7 @@ show_date (const char *format, struct timespec when) if (! tm) { char buf[INT_BUFSIZE_BOUND (intmax_t)]; - error (0, 0, _("time %s is out of range"), - (TYPE_SIGNED (time_t) - ? imaxtostr (when.tv_sec, buf) - : umaxtostr (when.tv_sec, buf))); + error (0, 0, _("time %s is out of range"), timetostr (when.tv_sec, buf)); return false; } @@ -28,7 +28,6 @@ #include "error.h" #include "fsusage.h" #include "human.h" -#include "inttostr.h" #include "mountlist.h" #include "quote.h" #include "save-cwd.h" @@ -35,7 +35,6 @@ #include "fprintftime.h" #include "hash.h" #include "human.h" -#include "inttostr.h" #include "quote.h" #include "quotearg.h" #include "readtokens0.h" @@ -413,10 +412,7 @@ show_date (const char *format, struct timespec when) if (! tm) { char buf[INT_BUFSIZE_BOUND (intmax_t)]; - error (0, 0, _("time %s is out of range"), - (TYPE_SIGNED (time_t) - ? imaxtostr (when.tv_sec, buf) - : umaxtostr (when.tv_sec, buf))); + error (0, 0, _("time %s is out of range"), timetostr (when.tv_sec, buf)); fputs (buf, stdout); return; } diff --git a/src/expr.c b/src/expr.c index bbcb5a922..c342291dc 100644 --- a/src/expr.c +++ b/src/expr.c @@ -35,7 +35,6 @@ #include <regex.h> #include "long-options.h" #include "error.h" -#include "inttostr.h" #include "quotearg.h" #include "strnumcmp.h" #include "xstrtol.h" diff --git a/src/factor.c b/src/factor.c index f46953c8b..08fa2a5c1 100644 --- a/src/factor.c +++ b/src/factor.c @@ -27,7 +27,6 @@ #include "system.h" #include "error.h" -#include "inttostr.h" #include "long-options.h" #include "quote.h" #include "readtokens.h" diff --git a/src/head.c b/src/head.c index 7a0e2ada9..0ef912a58 100644 --- a/src/head.c +++ b/src/head.c @@ -34,7 +34,6 @@ #include "error.h" #include "full-write.h" #include "full-read.h" -#include "inttostr.h" #include "quote.h" #include "safe-read.h" #include "xstrtol.h" @@ -91,7 +91,6 @@ #include "human.h" #include "filemode.h" #include "idcache.h" -#include "inttostr.h" #include "ls.h" #include "lstat.h" #include "mbswidth.h" @@ -3596,9 +3595,7 @@ print_long_format (const struct fileinfo *f) sprintf (p, "%*s ", long_time_expected_width (), (! f->stat_ok ? "?" - : (TYPE_SIGNED (time_t) - ? imaxtostr (when_timespec.tv_sec, hbuf) - : umaxtostr (when_timespec.tv_sec, hbuf)))); + : timetostr (when_timespec.tv_sec, hbuf))); /* FIXME: (maybe) We discarded when_timespec.tv_nsec. */ p += strlen (p); } diff --git a/src/pinky.c b/src/pinky.c index 9c80d94d5..382f30fcd 100644 --- a/src/pinky.c +++ b/src/pinky.c @@ -27,7 +27,6 @@ #include "canon-host.h" #include "error.h" #include "hard-locale.h" -#include "inttostr.h" #include "readutmp.h" /* The official name of this program (e.g., no `g' prefix). */ @@ -197,7 +196,7 @@ time_string (const STRUCT_UTMP *utmp_ent) return buf; } else - return TYPE_SIGNED (time_t) ? imaxtostr (t, buf) : umaxtostr (t, buf); + return timetostr (t, buf); } /* Display a line of information about UTMP_ENT. */ diff --git a/src/shred.c b/src/shred.c index 765e1b515..9e82cf2f0 100644 --- a/src/shred.c +++ b/src/shred.c @@ -97,7 +97,6 @@ #include "error.h" #include "fcntl--.h" #include "human.h" -#include "inttostr.h" #include "quotearg.h" /* For quotearg_colon */ #include "randint.h" #include "randread.h" diff --git a/src/sort.c b/src/sort.c index 2039dabf8..9f998a6a4 100644 --- a/src/sort.c +++ b/src/sort.c @@ -31,7 +31,6 @@ #include "error.h" #include "hard-locale.h" #include "hash.h" -#include "inttostr.h" #include "md5.h" #include "physmem.h" #include "posixver.h" diff --git a/src/split.c b/src/split.c index 181d83783..c70e0c4f2 100644 --- a/src/split.c +++ b/src/split.c @@ -32,7 +32,6 @@ #include "fcntl--.h" #include "full-read.h" #include "full-write.h" -#include "inttostr.h" #include "quote.h" #include "safe-read.h" #include "xstrtol.h" diff --git a/src/stat.c b/src/stat.c index 0124c545e..a97687a87 100644 --- a/src/stat.c +++ b/src/stat.c @@ -62,7 +62,6 @@ #include "file-type.h" #include "fs.h" #include "getopt.h" -#include "inttostr.h" #include "quote.h" #include "quotearg.h" #include "stat-time.h" @@ -415,9 +414,7 @@ human_time (struct timespec t) + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +ZZZZ"))]; struct tm const *tm = localtime (&t.tv_sec); if (tm == NULL) - return (TYPE_SIGNED (time_t) - ? imaxtostr (t.tv_sec, str) - : umaxtostr (t.tv_sec, str)); + return timetostr (t.tv_sec, str); nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, t.tv_nsec); return str; } diff --git a/src/system.h b/src/system.h index c69ddca34..4b8e58e1f 100644 --- a/src/system.h +++ b/src/system.h @@ -619,3 +619,13 @@ emit_bug_reporting_address (void) bugs (typically your translation team's web or email address). */ printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); } + +#include "inttostr.h" + +static inline char * +timetostr (time_t t, char *buf) +{ + return (TYPE_SIGNED (time_t) + ? imaxtostr (t, buf) + : umaxtostr (t, buf)); +} diff --git a/src/tail.c b/src/tail.c index 1ce207e52..2fcd4cfdf 100644 --- a/src/tail.c +++ b/src/tail.c @@ -35,7 +35,6 @@ #include "c-strtod.h" #include "error.h" #include "fcntl--.h" -#include "inttostr.h" #include "isapipe.h" #include "posixver.h" #include "quote.h" diff --git a/src/test.c b/src/test.c index 858a837e5..833b254b6 100644 --- a/src/test.c +++ b/src/test.c @@ -39,7 +39,6 @@ #include "system.h" #include "euidaccess.h" -#include "inttostr.h" #include "quote.h" #include "stat-time.h" #include "strnumcmp.h" @@ -27,7 +27,6 @@ #include "system.h" #include "error.h" -#include "inttostr.h" #include "mbchar.h" #include "quote.h" #include "quotearg.h" @@ -34,7 +34,6 @@ #include "readutmp.h" #include "error.h" #include "hard-locale.h" -#include "inttostr.h" #include "quote.h" /* The official name of this program (e.g., no `g' prefix). */ @@ -231,7 +230,7 @@ time_string (const STRUCT_UTMP *utmp_ent) return buf; } else - return TYPE_SIGNED (time_t) ? imaxtostr (t, buf) : umaxtostr (t, buf); + return timetostr (t, buf); } /* Print formatted output line. Uses mostly arbitrary field sizes, probably |