]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
factor out time_t-to-string conversion idiom
authorJim Meyering <meyering@redhat.com>
Fri, 27 Jun 2008 08:54:23 +0000 (10:54 +0200)
committerJim Meyering <meyering@redhat.com>
Fri, 27 Jun 2008 08:54:23 +0000 (10:54 +0200)
* 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.

21 files changed:
src/c99-to-c89.diff
src/chown-core.c
src/cksum.c
src/csplit.c
src/date.c
src/df.c
src/du.c
src/expr.c
src/factor.c
src/head.c
src/ls.c
src/pinky.c
src/shred.c
src/sort.c
src/split.c
src/stat.c
src/system.h
src/tail.c
src/test.c
src/wc.c
src/who.c

index 9268d387d7c306b0e9b76f08159cf8b4847c9575..51b0a42ca3451b923269d5974555c1e34eaa642a 100644 (file)
@@ -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.  */
index d915ae45edca40b761cb02c27f59f98a46fc8549..4ab52ac537e034b90e74b10e5fd1dc81e8ef2331 100644 (file)
@@ -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"
index ce6e9c0565d456a90c4e293787e8aeca39830a57..a2d49c5b30ad480d0d80e4a56463717d9d203d34 100644 (file)
@@ -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)
index 7e63ca831e560d39e915eab9e1a8ce0bc5e55ef5..55489c3abd59efa9d21e117bd73afd3a54eeb34a 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "error.h"
 #include "fd-reopen.h"
-#include "inttostr.h"
 #include "quote.h"
 #include "safe-read.h"
 #include "stdio--.h"
index 24390529c9cf80eb79493e2da8ad5a8186ea01da..9592bf816ce2453df8eabf683793d7addc0394ca 100644 (file)
@@ -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;
     }
 
index 66e920774ddcef81e642e06dacdf7acf24ee0ae7..0769a1eb5bdbd2f35fea382eec2fe8afee60e146 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -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"
index d9749919ed822c9d9b54e5af07abbcfe6eac7068..ee2426927a761df1179e6ab148ad46bbaf8c6375 100644 (file)
--- a/src/du.c
+++ b/src/du.c
@@ -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;
     }
index bbcb5a922c474cc0e2c2eec3ab518fdfb42f7c06..c342291dc40584f7a07ed589ba82e068c0aa5024 100644 (file)
@@ -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"
index f46953c8b50efa3125cb7dc558784bd6cab48100..08fa2a5c1389b866fce268645330931498536470 100644 (file)
@@ -27,7 +27,6 @@
 
 #include "system.h"
 #include "error.h"
-#include "inttostr.h"
 #include "long-options.h"
 #include "quote.h"
 #include "readtokens.h"
index 7a0e2ada9d4d7e7db6612627dfc7dbff203d43da..0ef912a58c7f0c545fe3bd0516f91c8f55a11974 100644 (file)
@@ -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"
index 4e044a93b47b5a9c9cb39e41db7984bbab37e6da..4b69f7d22a88dff1bad9918481de56f625669be4 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -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);
     }
index 9c80d94d536300176a1632c45d4cade9f7c8113a..382f30fcd7e7286b4eabd7b8fe1b766176cdc295 100644 (file)
@@ -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. */
index 765e1b51597e8056b20b1268c8b7149318dc5570..9e82cf2f0137c6d6cf9cd71891427bd8e6029b89 100644 (file)
@@ -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"
index 2039dabf8b4266f831cce32da5beadbe7a87f486..9f998a6a41613a41e074e31baf514280f3694726 100644 (file)
@@ -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"
index 181d8378309519c903733b85016b289a31f28119..c70e0c4f2370ad953ce114aad2d8828a92cd06ac 100644 (file)
@@ -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"
index 0124c545e30171f94f78821822001b98aa3d93c0..a97687a873eab8c4ca2ffbb999fb4c3b9697890e 100644 (file)
@@ -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;
 }
index c69ddca34ec281fbdd5556c8600b90d24db5c650..4b8e58e1f206b1d13e93c4562fb3952ed7875dbc 100644 (file)
@@ -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));
+}
index 1ce207e524ee64c66fff00de04b546050e424f26..2fcd4cfdfd69b4d6b2dbba5bbddec72372903210 100644 (file)
@@ -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"
index 858a837e5833580784a63ecf8eff2af55d61aa42..833b254b69bdec045e75dbc34582fa9387e29c73 100644 (file)
@@ -39,7 +39,6 @@
 
 #include "system.h"
 #include "euidaccess.h"
-#include "inttostr.h"
 #include "quote.h"
 #include "stat-time.h"
 #include "strnumcmp.h"
index e6b9a1ebbc0c1ab9277575938a9dd4ba18c1efa9..0bb1929f488b6ba18e957d7201648c39197dad92 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -27,7 +27,6 @@
 
 #include "system.h"
 #include "error.h"
-#include "inttostr.h"
 #include "mbchar.h"
 #include "quote.h"
 #include "quotearg.h"
index 9bf437c066a36cb32537a23ea406f3ea36c2c2ba..5529618d983ce2ef2b8e62f1211af8d3f737ecfd 100644 (file)
--- a/src/who.c
+++ b/src/who.c
@@ -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