bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

coreutils int fixes for printf, readlink, shred, split, stat


From: Paul Eggert
Subject: coreutils int fixes for printf, readlink, shred, split, stat
Date: Tue, 03 Aug 2004 12:11:46 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

I installed this patch.  The only externally-visible change is that
the "stat" command now can print wider numbers in some cases, instead
of artificially truncating them.  For example, on 64-bit hosts "stat"
can now print correctly file time stamps outside the 32-bit range.

2004-08-03  Paul Eggert  <address@hidden>

        * src/printf.c (posixly_correct): Use bool for booleans.
        (verify, main): Use EXIT_FAILURE/EXIT_SUCCESS instead of 1/0.
        (STRTOX): Rewrite to avoid casts.
        (print_esc_char): Arg is char, not int.
        * src/readlink.c (canonicalize): Remove.  All uses now merely inspect
        can_mode.
        (no_newline, verbose): Use bool for booleans.
        (can_mode): Now of type int; use -1 to denote otherwise-uninitialized.
        * src/shred.c (struct Options, main): Use bool for booleans.
        (isaac_seed_data, fillpattern, wipefile): Rewrite to avoid casts.
        * src/split.c (cwrite, bytes_split, lines_split, line_bytes_split):
        Use bool for booleans.
        * src/stat.c (G_fail): Remove.
        (print_statfs): Print various gotta-be-nonnegative values using
        unsigned long int, not long int or int.
        (do_statfs, do_stat): Return a boolean success flag.
        (do_stat, main): Use bool for booleans.

Index: src/printf.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/printf.c,v
retrieving revision 1.93
diff -p -u -r1.93 printf.c
--- src/printf.c        28 Jul 2004 06:58:25 -0000      1.93
+++ src/printf.c        28 Jul 2004 19:27:19 -0000
@@ -77,8 +77,8 @@ uintmax_t strtoumax ();
 /* The value to return to the calling program.  */
 static int exit_status;
 
-/* Non-zero if the POSIXLY_CORRECT environment variable is set.  */
-static int posixly_correct;
+/* True if the POSIXLY_CORRECT environment variable is set.  */
+static bool posixly_correct;
 
 /* This message appears in N_() here rather than just in _() below because
    the sole use would have been in a #define.  */
@@ -152,7 +152,7 @@ verify (const char *s, const char *end)
   if (errno)
     {
       error (0, errno, "%s", s);
-      exit_status = 1;
+      exit_status = EXIT_FAILURE;
     }
   else if (*end)
     {
@@ -160,7 +160,7 @@ verify (const char *s, const char *end)
        error (0, 0, _("%s: expected a numeric value"), s);
       else
        error (0, 0, _("%s: value not completely converted"), s);
-      exit_status = 1;
+      exit_status = EXIT_FAILURE;
     }
 }
 
@@ -173,7 +173,8 @@ FUNC_NAME (char const *s)                                   
         \
                                                                         \
   if (*s == '\"' || *s == '\'')                                                
 \
     {                                                                   \
-      val = *(unsigned char *) ++s;                                     \
+      unsigned char ch = *++s;                                          \
+      val = ch;                                                                
 \
       /* If POSIXLY_CORRECT is not set, then give a warning that there  \
         are characters following the character constant and that GNU    \
         printf is ignoring those characters.  If POSIXLY_CORRECT *is*   \
@@ -197,7 +198,7 @@ STRTOX (long double, vstrtold,   c_strto
 /* Output a single-character \ escape.  */
 
 static void
-print_esc_char (int c)
+print_esc_char (char c)
 {
   switch (c)
     {
@@ -647,7 +648,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  exit_status = 0;
+  exit_status = EXIT_SUCCESS;
 
   posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
 
Index: src/readlink.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/readlink.c,v
retrieving revision 1.12
diff -p -u -r1.12 readlink.c
--- src/readlink.c      6 Jul 2004 16:11:03 -0000       1.12
+++ src/readlink.c      16 Jul 2004 16:32:13 -0000
@@ -37,14 +37,14 @@
 /* Name this program was run with.  */
 char *program_name;
 
-  /* If nonzero, canonicalize file name. */
-static int canonicalize;
-  /* If nonzero, do not output the trailing newline. */
-static int no_newline;
-  /* If nonzero, report error messages. */
-static int verbose;
-  /* In canonicalize mode, use this method. */
-canonicalize_mode_t can_mode = CAN_ALL_BUT_LAST;
+/* If true, do not output the trailing newline.  */
+static bool no_newline;
+
+/* If true, report error messages.  */
+static bool verbose;
+
+/* If not -1, use this method to canonicalize.  */
+int can_mode = -1;
 
 static struct option const longopts[] =
 {
@@ -121,26 +121,23 @@ main (int argc, char *const argv[])
        case 0:
          break;
        case 'e':
-         canonicalize = 1;
          can_mode = CAN_EXISTING;
          break;
        case 'f':
-         canonicalize = 1;
          can_mode = CAN_ALL_BUT_LAST;
          break;
        case 'm':
-         canonicalize = 1;
          can_mode = CAN_MISSING;
          break;
        case 'n':
-         no_newline = 1;
+         no_newline = true;
          break;
        case 'q':
        case 's':
-         verbose = 0;
+         verbose = false;
          break;
        case 'v':
-         verbose = 1;
+         verbose = true;
          break;
        case_GETOPT_HELP_CHAR;
        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -163,7 +160,7 @@ main (int argc, char *const argv[])
       usage (EXIT_FAILURE);
     }
 
-  value = (canonicalize
+  value = (can_mode != -1
           ? canonicalize_fname (fname)
           : xreadlink (fname, 1024));
   if (value)
Index: src/shred.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/shred.c,v
retrieving revision 1.100
diff -p -u -r1.100 shred.c
--- src/shred.c 2 Aug 2004 05:26:01 -0000       1.100
+++ src/shred.c 2 Aug 2004 05:41:36 -0000
@@ -120,13 +120,13 @@
 
 struct Options
 {
-  int force;           /* -f flag: chmod files if necessary */
+  bool force;          /* -f flag: chmod files if necessary */
   size_t n_iterations; /* -n flag: Number of iterations */
   off_t size;          /* -s flag: size of file */
-  int remove_file;     /* -u flag: remove file after shredding */
-  int verbose;         /* -v flag: Print progress */
-  int exact;           /* -x flag: Do not round up file size */
-  int zero_fill;       /* -z flag: Add a final zero pass */
+  bool remove_file;    /* -u flag: remove file after shredding */
+  bool verbose;                /* -v flag: Print progress */
+  bool exact;          /* -x flag: Do not round up file size */
+  bool zero_fill;      /* -z flag: Add a final zero pass */
 };
 
 static struct option const long_opts[] =
@@ -455,8 +455,9 @@ isaac_seed_start (struct isaac_state *s)
 
 /* Add a buffer of seed material */
 static void
-isaac_seed_data (struct isaac_state *s, void const *buf, size_t size)
+isaac_seed_data (struct isaac_state *s, void const *buffer, size_t size)
 {
+  unsigned char const *buf = buffer;
   unsigned char *p;
   size_t avail;
   size_t i;
@@ -468,8 +469,8 @@ isaac_seed_data (struct isaac_state *s, 
     {
       p = (unsigned char *) s->mm + s->c;
       for (i = 0; i < avail; i++)
-       p[i] ^= ((unsigned char const *) buf)[i];
-      buf = (char const *) buf + avail;
+       p[i] ^= buf[i];
+      buf += avail;
       size -= avail;
       isaac_mix (s, s->mm);
       s->c = 0;
@@ -479,7 +480,7 @@ isaac_seed_data (struct isaac_state *s, 
   /* And the final partial block */
   p = (unsigned char *) s->mm + s->c;
   for (i = 0; i < size; i++)
-    p[i] ^= ((unsigned char const *) buf)[i];
+    p[i] ^= buf[i];
   s->c = size;
 }
 
@@ -537,7 +538,7 @@ isaac_seed_machdep (struct isaac_state *
       __asm__ __volatile__ ("rdtsc" : "=a" (t[0]), "=d" (t[1]));
 # endif
 # if __alpha__
-      unsigned long t;
+      unsigned long int t;
       __asm__ __volatile__ ("rpcc %0" : "=r" (t));
 # endif
 # if _ARCH_PPC
@@ -553,7 +554,7 @@ isaac_seed_machdep (struct isaac_state *
 # endif
 # if __sparc__
       /* This doesn't compile on all platforms yet.  How to fix? */
-      unsigned long t;
+      unsigned long int t;
       __asm__ __volatile__ ("rd        %%tick, %0" : "=r" (t));
 # endif
      signal (SIGILL, old_handler[0]);
@@ -636,7 +637,7 @@ isaac_seed (struct isaac_state *s)
 struct irand_state
 {
   uint32_t r[ISAAC_WORDS];
-  unsigned numleft;
+  unsigned int numleft;
   struct isaac_state *s;
 };
 
@@ -702,12 +703,12 @@ static void
 fillpattern (int type, unsigned char *r, size_t size)
 {
   size_t i;
-  unsigned bits = type & 0xfff;
+  unsigned int bits = type & 0xfff;
 
   bits |= bits << 12;
-  ((unsigned char *) r)[0] = (bits >> 4) & 255;
-  ((unsigned char *) r)[1] = (bits >> 8) & 255;
-  ((unsigned char *) r)[2] = bits & 255;
+  r[0] = (bits >> 4) & 255;
+  r[1] = (bits >> 8) & 255;
+  r[2] = bits & 255;
   for (i = 3; i < size / 2; i *= 2)
     memcpy ((char *) r + i, (char *) r, i);
   if (i < size)
@@ -824,7 +825,7 @@ direct_mode (int fd, bool enable)
  */
 static int
 dopass (int fd, char const *qname, off_t *sizep, int type,
-       struct isaac_state *s, unsigned long k, unsigned long n)
+       struct isaac_state *s, unsigned long int k, unsigned long int n)
 {
   off_t size = *sizep;
   off_t offset;                        /* Current file posiiton */
@@ -1235,13 +1236,13 @@ do_wipefd (int fd, char const *qname, st
   size_t i;
   struct stat st;
   off_t size;                  /* Size to write, size to read */
-  unsigned long n;             /* Number of passes for printing purposes */
+  unsigned long int n;         /* Number of passes for printing purposes */
   int *passarray;
   bool ok = true;
 
   n = 0;               /* dopass takes n -- 0 to mean "don't print progress" */
   if (flags->verbose)
-    n = flags->n_iterations + ((flags->zero_fill) != 0);
+    n = flags->n_iterations + flags->zero_fill;
 
   if (fstat (fd, &st))
     {
@@ -1537,7 +1538,7 @@ wipefile (char *name, char const *qname,
        {
          /* We accept /dev/fd/# even if the OS doesn't support it */
          int errnum = errno;
-         unsigned long num;
+         unsigned long int num;
          char *p;
          errno = 0;
          num = strtoul (name + 8, &p, 10);
@@ -1546,7 +1547,7 @@ wipefile (char *name, char const *qname,
              (('1' <= name[8] && name[8] <= '9')
               || (name[8] == '0' && !name[9])))
            {
-             return wipefd ((int) num, qname, s, flags);
+             return wipefd (num, qname, s, flags);
            }
          errno = errnum;
        }
@@ -1602,7 +1603,7 @@ main (int argc, char **argv)
          break;
 
        case 'f':
-         flags.force = 1;
+         flags.force = true;
          break;
 
        case 'n':
@@ -1620,7 +1621,7 @@ main (int argc, char **argv)
          break;
 
        case 'u':
-         flags.remove_file = 1;
+         flags.remove_file = true;
          break;
 
        case 's':
@@ -1637,15 +1638,15 @@ main (int argc, char **argv)
          break;
 
        case 'v':
-         flags.verbose = 1;
+         flags.verbose = true;
          break;
 
        case 'x':
-         flags.exact = 1;
+         flags.exact = true;
          break;
 
        case 'z':
-         flags.zero_fill = 1;
+         flags.zero_fill = true;
          break;
 
        case_GETOPT_HELP_CHAR;
Index: src/split.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/split.c,v
retrieving revision 1.99
diff -p -u -r1.99 split.c
--- src/split.c 21 Jun 2004 15:03:35 -0000      1.99
+++ src/split.c 19 Jul 2004 04:41:05 -0000
@@ -190,11 +190,11 @@ next_file_name (void)
 }
 
 /* Write BYTES bytes at BP to an output file.
-   If NEW_FILE_FLAG is nonzero, open the next output file.
+   If NEW_FILE_FLAG is true, open the next output file.
    Otherwise add to the same output file already in use.  */
 
 static void
-cwrite (int new_file_flag, const char *bp, size_t bytes)
+cwrite (bool new_file_flag, const char *bp, size_t bytes)
 {
   if (new_file_flag)
     {
@@ -220,7 +220,7 @@ static void
 bytes_split (uintmax_t n_bytes, char *buf, size_t bufsize)
 {
   size_t n_read;
-  int new_file_flag = 1;
+  bool new_file_flag = true;
   size_t to_read;
   uintmax_t to_write = n_bytes;
   char *bp_out;
@@ -240,7 +240,7 @@ bytes_split (uintmax_t n_bytes, char *bu
                {
                  cwrite (new_file_flag, bp_out, to_read);
                  to_write -= to_read;
-                 new_file_flag = 0;
+                 new_file_flag = false;
                }
              break;
            }
@@ -250,7 +250,7 @@ bytes_split (uintmax_t n_bytes, char *bu
              cwrite (new_file_flag, bp_out, w);
              bp_out += w;
              to_read -= w;
-             new_file_flag = 1;
+             new_file_flag = true;
              to_write = n_bytes;
            }
        }
@@ -266,7 +266,7 @@ lines_split (uintmax_t n_lines, char *bu
 {
   size_t n_read;
   char *bp, *bp_out, *eob;
-  int new_file_flag = 1;
+  bool new_file_flag = true;
   uintmax_t n = 0;
 
   do
@@ -286,7 +286,7 @@ lines_split (uintmax_t n_lines, char *bu
                {
                  size_t len = eob - bp_out;
                  cwrite (new_file_flag, bp_out, len);
-                 new_file_flag = 0;
+                 new_file_flag = false;
                }
              break;
            }
@@ -296,7 +296,7 @@ lines_split (uintmax_t n_lines, char *bu
            {
              cwrite (new_file_flag, bp_out, bp - bp_out);
              bp_out = bp;
-             new_file_flag = 1;
+             new_file_flag = true;
              n = 0;
            }
        }
@@ -315,7 +315,7 @@ line_bytes_split (size_t n_bytes)
 {
   size_t n_read;
   char *bp;
-  int eof = 0;
+  bool eof = false;
   size_t n_buffered = 0;
   char *buf = xmalloc (n_bytes);
 
@@ -329,7 +329,7 @@ line_bytes_split (size_t n_bytes)
 
       n_buffered += n_read;
       if (n_buffered != n_bytes)
-       eof = 1;
+       eof = true;
 
       /* Find where to end this chunk.  */
       bp = buf + n_buffered;
@@ -344,7 +344,7 @@ line_bytes_split (size_t n_bytes)
        bp = buf + n_buffered;
 
       /* Output the chars as one output file.  */
-      cwrite (1, buf, bp - buf);
+      cwrite (true, buf, bp - buf);
 
       /* Discard the chars we just output; move rest of chunk
         down to be the start of the next chunk.  Source and
Index: src/stat.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/stat.c,v
retrieving revision 1.72
diff -p -u -r1.72 stat.c
--- src/stat.c  30 Jun 2004 22:31:43 -0000      1.72
+++ src/stat.c  20 Jul 2004 05:14:07 -0000
@@ -102,9 +102,6 @@ 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.
@@ -312,7 +309,7 @@ human_fstype (STRUCT_STATVFS const *stat
   {
     static char buf[sizeof "UNKNOWN (0x%lx)" - 3
                    + 2 * sizeof (statfsbuf->f_type)];
-    sprintf (buf, "UNKNOWN (0x%lx)", (unsigned long) statfsbuf->f_type);
+    sprintf (buf, "UNKNOWN (0x%lx)", (unsigned long int) statfsbuf->f_type);
     return buf;
   }
 #endif
@@ -375,7 +372,8 @@ print_statfs (char *pformat, char m, cha
     case 't':
 #if HAVE_STRUCT_STATXFS_F_TYPE
       strcat (pformat, "lx");
-      printf (pformat, (long int) (statfsbuf->f_type));  /* no equiv. */
+      printf (pformat,
+             (unsigned long int) (statfsbuf->f_type));  /* no equiv. */
 #else
       fputc ('*', stdout);
 #endif
@@ -397,8 +395,8 @@ print_statfs (char *pformat, char m, cha
       printf (pformat, (intmax_t) (statfsbuf->f_bavail));
       break;
     case 's':
-      strcat (pformat, "ld");
-      printf (pformat, (long int) (statfsbuf->f_bsize));
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) (statfsbuf->f_bsize));
       break;
     case 'c':
       strcat (pformat, PRIdMAX);
@@ -452,40 +450,41 @@ print_stat (char *pformat, char m, char 
        }
       break;
     case 'd':
-      strcat (pformat, "d");
-      printf (pformat, (int) statbuf->st_dev);
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) statbuf->st_dev);
       break;
     case 'D':
-      strcat (pformat, "x");
-      printf (pformat, (int) statbuf->st_dev);
+      strcat (pformat, "lx");
+      printf (pformat, (unsigned long int) statbuf->st_dev);
       break;
     case 'i':
-      strcat (pformat, "d");
-      printf (pformat, (int) statbuf->st_ino);
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) statbuf->st_ino);
       break;
     case 'a':
-      strcat (pformat, "o");
-      printf (pformat, statbuf->st_mode & 07777);
+      strcat (pformat, "lo");
+      printf (pformat,
+             (unsigned long int) (statbuf->st_mode & CHMOD_MODE_BITS));
       break;
     case 'A':
       strcat (pformat, "s");
       printf (pformat, human_access (statbuf));
       break;
     case 'f':
-      strcat (pformat, "x");
-      printf (pformat, statbuf->st_mode);
+      strcat (pformat, "lx");
+      printf (pformat, (unsigned long int) statbuf->st_mode);
       break;
     case 'F':
       strcat (pformat, "s");
       printf (pformat, file_type (statbuf));
       break;
     case 'h':
-      strcat (pformat, "d");
-      printf (pformat, (int) statbuf->st_nlink);
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) statbuf->st_nlink);
       break;
     case 'u':
-      strcat (pformat, "d");
-      printf (pformat, statbuf->st_uid);
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) statbuf->st_uid);
       break;
     case 'U':
       strcat (pformat, "s");
@@ -494,8 +493,8 @@ print_stat (char *pformat, char m, char 
       printf (pformat, (pw_ent != 0L) ? pw_ent->pw_name : "UNKNOWN");
       break;
     case 'g':
-      strcat (pformat, "d");
-      printf (pformat, statbuf->st_gid);
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) statbuf->st_gid);
       break;
     case 'G':
       strcat (pformat, "s");
@@ -504,28 +503,28 @@ print_stat (char *pformat, char m, char 
       printf (pformat, (gw_ent != 0L) ? gw_ent->gr_name : "UNKNOWN");
       break;
     case 't':
-      strcat (pformat, "x");
-      printf (pformat, major (statbuf->st_rdev));
+      strcat (pformat, "lx");
+      printf (pformat, (unsigned long int) major (statbuf->st_rdev));
       break;
     case 'T':
-      strcat (pformat, "x");
-      printf (pformat, minor (statbuf->st_rdev));
+      strcat (pformat, "lx");
+      printf (pformat, (unsigned long int) minor (statbuf->st_rdev));
       break;
     case 's':
       strcat (pformat, PRIuMAX);
       printf (pformat, (uintmax_t) (statbuf->st_size));
       break;
     case 'B':
-      strcat (pformat, "u");
-      printf (pformat, (unsigned int) ST_NBLOCKSIZE);
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) ST_NBLOCKSIZE);
       break;
     case 'b':
-      strcat (pformat, "u");
-      printf (pformat, (unsigned int) ST_NBLOCKS (*statbuf));
+      strcat (pformat, PRIuMAX);
+      printf (pformat, (uintmax_t) ST_NBLOCKS (*statbuf));
       break;
     case 'o':
-      strcat (pformat, "d");
-      printf (pformat, (int) statbuf->st_blksize);
+      strcat (pformat, "lu");
+      printf (pformat, (unsigned long int) statbuf->st_blksize);
       break;
     case 'x':
       strcat (pformat, "s");
@@ -533,8 +532,8 @@ print_stat (char *pformat, char m, char 
                                   TIMESPEC_NS (statbuf->st_atim)));
       break;
     case 'X':
-      strcat (pformat, "d");
-      printf (pformat, (int) statbuf->st_atime);
+      strcat (pformat, TYPE_SIGNED (time_t) ? "ld" : "lu");
+      printf (pformat, (unsigned long int) statbuf->st_atime);
       break;
     case 'y':
       strcat (pformat, "s");
@@ -542,8 +541,8 @@ print_stat (char *pformat, char m, char 
                                   TIMESPEC_NS (statbuf->st_mtim)));
       break;
     case 'Y':
-      strcat (pformat, "d");
-      printf (pformat, (int) statbuf->st_mtime);
+      strcat (pformat, TYPE_SIGNED (time_t) ? "ld" : "lu");
+      printf (pformat, (unsigned long int) statbuf->st_mtime);
       break;
     case 'z':
       strcat (pformat, "s");
@@ -551,8 +550,8 @@ print_stat (char *pformat, char m, char 
                                   TIMESPEC_NS (statbuf->st_ctim)));
       break;
     case 'Z':
-      strcat (pformat, "d");
-      printf (pformat, (int) statbuf->st_ctime);
+      strcat (pformat, TYPE_SIGNED (time_t) ? "ld" : "lu");
+      printf (pformat, (unsigned long int) statbuf->st_ctime);
       break;
     default:
       strcat (pformat, "c");
@@ -614,17 +613,16 @@ print_it (char const *masterformat, char
 }
 
 /* Stat the file system and print what we find.  */
-static void
-do_statfs (char const *filename, int terse, char const *format)
+static bool
+do_statfs (char const *filename, bool terse, char const *format)
 {
   STRUCT_STATVFS statfsbuf;
-  int i = statfs (filename, &statfsbuf);
 
-  if (i == -1)
+  if (statfs (filename, &statfsbuf) != 0)
     {
       error (0, errno, _("cannot read file system information for %s"),
             quote (filename));
-      return;
+      return false;
     }
 
   if (format == NULL)
@@ -638,35 +636,33 @@ do_statfs (char const *filename, int ter
     }
 
   print_it (format, filename, print_statfs, &statfsbuf);
+  return true;
 }
 
 /* stat the file and print what we find */
-static void
-do_stat (char const *filename, int follow_links, int terse,
+static bool
+do_stat (char const *filename, bool follow_links, bool terse,
         char const *format)
 {
   struct stat statbuf;
-  int i = ((follow_links == 1)
-          ? stat (filename, &statbuf)
-          : lstat (filename, &statbuf));
 
-  if (i == -1)
+  if ((follow_links ? stat : lstat) (filename, &statbuf) != 0)
     {
       error (0, errno, _("cannot stat %s"), quote (filename));
-      return;
+      return false;
     }
 
   if (format == NULL)
     {
-      if (terse != 0)
+      if (terse)
        {
          format = "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %o\n";
        }
       else
        {
-         /* tmp hack to match orignal output until conditional implemented */
-         i = statbuf.st_mode & S_IFMT;
-         if (i == S_IFCHR || i == S_IFBLK)
+         /* Temporary hack to match original output until conditional
+            implemented.  */
+         if (S_ISBLK (statbuf.st_mode) || S_ISCHR (statbuf.st_mode))
            {
              format =
                "  File: %N\n"
@@ -688,6 +684,7 @@ do_stat (char const *filename, int follo
        }
     }
   print_it (format, filename, print_stat, &statbuf);
+  return true;
 }
 
 void
@@ -775,10 +772,11 @@ main (int argc, char *argv[])
 {
   int c;
   int i;
-  int follow_links = 0;
-  int fs = 0;
-  int terse = 0;
+  bool follow_links = false;
+  bool fs = false;
+  bool terse = false;
   char *format = NULL;
+  bool ok = true;
 
   initialize_main (&argc, &argv);
   program_name = argv[0];
@@ -800,15 +798,15 @@ main (int argc, char *argv[])
          error (0, 0, _("Warning: `-l' is deprecated; use `-L' instead"));
          /* fall through */
        case 'L':
-         follow_links = 1;
+         follow_links = true;
          break;
 
        case 'f':
-         fs = 1;
+         fs = true;
          break;
 
        case 't':
-         terse = 1;
+         terse = true;
          break;
 
        case_GETOPT_HELP_CHAR;
@@ -827,12 +825,9 @@ main (int argc, char *argv[])
     }
 
   for (i = optind; i < argc; i++)
-    {
-      if (fs == 0)
-       do_stat (argv[i], follow_links, terse, format);
-      else
-       do_statfs (argv[i], terse, format);
-    }
+    ok &= (fs
+          ? do_statfs (argv[i], terse, format)
+          : do_stat (argv[i], follow_links, terse, format));
 
-  exit (G_fail ? EXIT_FAILURE : EXIT_SUCCESS);
+  exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]