]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: remove unnecessary inttostr usage in printf
authorCollin Funk <collin.funk1@gmail.com>
Tue, 30 Jul 2024 04:16:36 +0000 (21:16 -0700)
committerPádraig Brady <P@draigBrady.com>
Tue, 30 Jul 2024 07:53:59 +0000 (08:53 +0100)
* src/cksum.c (output_crc): Use '%ju' instead of umaxtostr.
* src/shred.c (dopass): Likewise.
* src/csplit.c (handle_line_error, regexp_error, close_output_file)
(parse_patterns): Use '%jd' instead of offtostr.
* src/tail.c (xlseek): Likewise.
* src/head.c (elseek): Likewise.
* src/group-list.c (gidtostr_ptr): Remove function.
(gidtostr): Remove macro.
(print_group): Use '%ju' instead of umaxtostr.
* src/id.c (gidtostr_ptr, uidtostr_ptr): Remove functions.
(gidtostr, uidtostr): Remove macros.
(print_user, print_full_info): Use '%ju' instead of umaxtostr.
* src/sort.c (specify_nmerge): Use '%u' instead of uinttostr.

src/cksum.c
src/csplit.c
src/group-list.c
src/head.c
src/id.c
src/shred.c
src/sort.c
src/tail.c

index 9909b14f5a9eb690d03ed50310ad6404533776d3..a97ffc26f4a1915101d4f7385c10f573f7650184 100644 (file)
@@ -257,8 +257,7 @@ output_crc (char const *file, int binary_file, void const *digest, bool raw,
       return;
     }
 
-  char length_buf[INT_BUFSIZE_BOUND (uintmax_t)];
-  printf ("%u %s", *(unsigned int *)digest, umaxtostr (length, length_buf));
+  printf ("%u %ju", *(unsigned int *)digest, length);
   if (args)
     printf (" %s", file);
   putchar (delim);
index 4767d8aa05178da5b9c76cc904f11dc2b858634b..acde48bbdb5aae4ab019a5c7686235e27c4f00d4 100644 (file)
@@ -673,7 +673,7 @@ handle_line_error (const struct control *p, intmax_t repetition)
   fprintf (stderr, _("%s: %s: line number out of range"),
            program_name, quote (imaxtostr (p->lines_required, buf)));
   if (repetition)
-    fprintf (stderr, _(" on repetition %s\n"), imaxtostr (repetition, buf));
+    fprintf (stderr, _(" on repetition %jd\n"), repetition);
   else
     fprintf (stderr, "\n");
 
@@ -726,10 +726,7 @@ regexp_error (struct control *p, intmax_t repetition, bool ignore)
            program_name, quote (global_argv[p->argnum]));
 
   if (repetition)
-    {
-      char buf[INT_BUFSIZE_BOUND (intmax_t)];
-      fprintf (stderr, _(" on repetition %s\n"), imaxtostr (repetition, buf));
-    }
+    fprintf (stderr, _(" on repetition %jd\n"), repetition);
   else
     fprintf (stderr, "\n");
 
@@ -988,10 +985,7 @@ close_output_file (void)
       else
         {
           if (!suppress_count)
-            {
-              char buf[INT_BUFSIZE_BOUND (intmax_t)];
-              fprintf (stdout, "%s\n", imaxtostr (bytes_written, buf));
-            }
+            fprintf (stdout, "%jd\n", bytes_written);
         }
       output_stream = nullptr;
     }
@@ -1152,13 +1146,9 @@ parse_patterns (int argc, int start, char **argv)
             error (EXIT_FAILURE, 0,
                    _("%s: line number must be greater than zero"), argv[i]);
           if (val < last_val)
-            {
-              char buf[INT_BUFSIZE_BOUND (intmax_t)];
-              error (EXIT_FAILURE, 0,
-                     _("line number %s is smaller than preceding line number,"
-                       " %s"),
-                     quote (argv[i]), imaxtostr (last_val, buf));
-            }
+            error (EXIT_FAILURE, 0,
+                   _("line number %s is smaller than preceding line number,"
+                     " %jd"), quote (argv[i]), last_val);
 
           if (val == last_val)
             error (0, 0,
index d6af680ef8975aa806bb806cfb66bc0c092daa85..e8c9a002ceebd722c79636bacf8197abce80473a 100644 (file)
@@ -86,17 +86,6 @@ print_group_list (char const *username,
   return ok;
 }
 
-/* Convert a gid_t to string.  Do not use this function directly.
-   Instead, use it via the gidtostr macro.
-   Beware that it returns a pointer to static storage.  */
-static char *
-gidtostr_ptr (gid_t const *gid)
-{
-  static char buf[INT_BUFSIZE_BOUND (uintmax_t)];
-  return umaxtostr (*gid, buf);
-}
-#define gidtostr(g) gidtostr_ptr (&(g))
-
 /* Print the name or value of group ID GID. */
 extern bool
 print_group (gid_t gid, bool use_name)
@@ -123,7 +112,9 @@ print_group (gid_t gid, bool use_name)
         }
     }
 
-  char *s = grp ? grp->gr_name : gidtostr (gid);
-  fputs (s, stdout);
+  if (grp)
+    printf ("%s", grp->gr_name);
+  else
+    printf ("%ju", (uintmax_t) gid);
   return ok;
 }
index 4612a8e10f3562f4e5e9f557b38e4f582bb6bfb9..9feda5653cc2111a7414f4817b93f9ab317e90be 100644 (file)
@@ -224,15 +224,14 @@ static off_t
 elseek (int fd, off_t offset, int whence, char const *filename)
 {
   off_t new_offset = lseek (fd, offset, whence);
-  char buf[INT_BUFSIZE_BOUND (offset)];
 
   if (new_offset < 0)
     error (0, errno,
            _(whence == SEEK_SET
-             ? N_("%s: cannot seek to offset %s")
-             : N_("%s: cannot seek to relative offset %s")),
+             ? N_("%s: cannot seek to offset %jd")
+             : N_("%s: cannot seek to relative offset %jd")),
            quotef (filename),
-           offtostr (offset, buf));
+           (intmax_t) offset);
 
   return new_offset;
 }
index 38d5517bd8cc1a99be18b290817cb96abd4ceb70..80a116e7a4f200b3ba2782322b657a49dc61d240 100644 (file)
--- a/src/id.c
+++ b/src/id.c
@@ -303,28 +303,6 @@ main (int argc, char **argv)
   return ok ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-/* Convert a gid_t to string.  Do not use this function directly.
-   Instead, use it via the gidtostr macro.
-   Beware that it returns a pointer to static storage.  */
-static char *
-gidtostr_ptr (gid_t const *gid)
-{
-  static char buf[INT_BUFSIZE_BOUND (uintmax_t)];
-  return umaxtostr (*gid, buf);
-}
-#define gidtostr(g) gidtostr_ptr (&(g))
-
-/* Convert a uid_t to string.  Do not use this function directly.
-   Instead, use it via the uidtostr macro.
-   Beware that it returns a pointer to static storage.  */
-static char *
-uidtostr_ptr (uid_t const *uid)
-{
-  static char buf[INT_BUFSIZE_BOUND (uintmax_t)];
-  return umaxtostr (*uid, buf);
-}
-#define uidtostr(u) uidtostr_ptr (&(u))
-
 /* Print the name or value of user ID UID. */
 
 static void
@@ -337,14 +315,15 @@ print_user (uid_t uid)
       pwd = getpwuid (uid);
       if (pwd == nullptr)
         {
-          error (0, 0, _("cannot find name for user ID %s"),
-                 uidtostr (uid));
+          error (0, 0, _("cannot find name for user ID %ju"), (uintmax_t) uid);
           ok &= false;
         }
     }
 
-  char *s = pwd ? pwd->pw_name : uidtostr (uid);
-  fputs (s, stdout);
+  if (pwd)
+    printf ("%s", pwd->pw_name);
+  else
+    printf ("%ju", (uintmax_t) uid);
 }
 
 /* Print all of the info about the user's user and group IDs. */
@@ -355,19 +334,19 @@ print_full_info (char const *username)
   struct passwd *pwd;
   struct group *grp;
 
-  printf (_("uid=%s"), uidtostr (ruid));
+  printf (_("uid=%ju"), (uintmax_t) ruid);
   pwd = getpwuid (ruid);
   if (pwd)
     printf ("(%s)", pwd->pw_name);
 
-  printf (_(" gid=%s"), gidtostr (rgid));
+  printf (_(" gid=%ju"), (uintmax_t) rgid);
   grp = getgrgid (rgid);
   if (grp)
     printf ("(%s)", grp->gr_name);
 
   if (euid != ruid)
     {
-      printf (_(" euid=%s"), uidtostr (euid));
+      printf (_(" euid=%ju"), (uintmax_t) euid);
       pwd = getpwuid (euid);
       if (pwd)
         printf ("(%s)", pwd->pw_name);
@@ -375,7 +354,7 @@ print_full_info (char const *username)
 
   if (egid != rgid)
     {
-      printf (_(" egid=%s"), gidtostr (egid));
+      printf (_(" egid=%ju"), (uintmax_t) egid);
       grp = getgrgid (egid);
       if (grp)
         printf ("(%s)", grp->gr_name);
@@ -408,7 +387,7 @@ print_full_info (char const *username)
       {
         if (i > 0)
           putchar (',');
-        fputs (gidtostr (groups[i]), stdout);
+        printf ("%ju", (uintmax_t) groups[i]);
         grp = getgrgid (groups[i]);
         if (grp)
           printf ("(%s)", grp->gr_name);
index 564d3cc6204f5107ea04e46fa55977158217b841..ecb207a8b42c45cddf0e44e547e45f1db7dc0d65 100644 (file)
@@ -485,7 +485,6 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep,
               else
                 {
                   int errnum = errno;
-                  char buf[INT_BUFSIZE_BOUND (uintmax_t)];
 
                   /* Retry without direct I/O since this may not be supported
                      at all on some (file) systems, or with the current size.
@@ -498,8 +497,9 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep,
                       try_without_directio = true;
                       continue;
                     }
-                  error (0, errnum, _("%s: error writing at offset %s"),
-                         qname, umaxtostr (offset + soff, buf));
+                  uintmax_t error_offset = offset + soff;
+                  error (0, errnum, _("%s: error writing at offset %ju"),
+                         qname, error_offset);
 
                   /* 'shred' is often used on bad media, before throwing it
                      out.  Thus, it shouldn't give up on bad blocks.  This
index 6c273fab994ecd48d080fe862b68ab84ec9f57f7..3357733c109262222d80ed598a70a11e57cf3a7b 100644 (file)
@@ -1368,13 +1368,11 @@ specify_nmerge (int oi, char c, char const *s)
 
   if (e == LONGINT_OVERFLOW)
     {
-      char max_nmerge_buf[INT_BUFSIZE_BOUND (max_nmerge)];
       error (0, 0, _("--%s argument %s too large"),
              long_options[oi].name, quote (s));
       error (SORT_FAILURE, 0,
-             _("maximum --%s argument with current rlimit is %s"),
-             long_options[oi].name,
-             uinttostr (max_nmerge, max_nmerge_buf));
+             _("maximum --%s argument with current rlimit is %u"),
+             long_options[oi].name, max_nmerge);
     }
   else
     xstrtol_fatal (e, oi, c, long_options, s);
index a3b46ca2d93dc95dd61805da999f4206c1147312..f373f768e1da5430afa24d625b861238dc438be8 100644 (file)
@@ -481,27 +481,24 @@ static off_t
 xlseek (int fd, off_t offset, int whence, char const *filename)
 {
   off_t new_offset = lseek (fd, offset, whence);
-  char buf[INT_BUFSIZE_BOUND (offset)];
-  char *s;
 
   if (0 <= new_offset)
     return new_offset;
 
-  s = offtostr (offset, buf);
   switch (whence)
     {
     case SEEK_SET:
-      error (EXIT_FAILURE, errno, _("%s: cannot seek to offset %s"),
-             quotef (filename), s);
+      error (EXIT_FAILURE, errno, _("%s: cannot seek to offset %jd"),
+             quotef (filename), (intmax_t) offset);
       break;
     case SEEK_CUR:
-      error (EXIT_FAILURE, errno, _("%s: cannot seek to relative offset %s"),
-             quotef (filename), s);
+      error (EXIT_FAILURE, errno, _("%s: cannot seek to relative offset %jd"),
+             quotef (filename), (intmax_t) offset);
       break;
     case SEEK_END:
       error (EXIT_FAILURE, errno,
-             _("%s: cannot seek to end-relative offset %s"),
-             quotef (filename), s);
+             _("%s: cannot seek to end-relative offset %jd"),
+             quotef (filename), (intmax_t) offset);
       break;
     default:
       unreachable ();