maint: remove unnecessary inttostr usage in printf

* 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.
This commit is contained in:
Collin Funk authored and Pádraig Brady committed 2024-07-30 08:53:59 +01:00
1 parent 83ec7a706a
commit 1ae98dbda7
8 files changed
+35 -82

No files matched your search

+1 -2
View 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);
+6 -16
View 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,
+4 -13
View 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;
}
+3 -4
View 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;
}
+10 -31
View File
@@ -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);
+3 -3
View 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
+2 -4
View 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);
+6 -9
View 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 ();