diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2022-09-10 15:13:28 -0500 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2022-09-10 15:39:38 -0500 |
commit | 2bf63fcba72c4f4bc54a4caf53d7923c1f9f174f (patch) | |
tree | a466361955cef6e34765fbec4734d91d23029222 /paxlib/error.c | |
parent | 9ae062098da4383a6c9b39e245c1a2888a645352 (diff) | |
download | paxutils-2bf63fcba72c4f4bc54a4caf53d7923c1f9f174f.tar.gz |
Modernize integer handling
It’s now safe to assume C99 sprintf %jd, etc.
* am/system.m4 (PU_SYSTEM): Do not require gl_INTTOSTR.
* gnulib.modules, paxlib.modules:
Remove inttostr. Add strtoimax, strtoumax.
* lib/system.h (UINTMAX_STRSIZE_BOUND): Remove.
* paxlib/error.c (chown_error_details, read_error_details)
(read_warn_details, read_fatal_details, seek_error_details)
(seek_warn_details, write_error_details):
* paxlib/rtape.c (rmt_read, rmt_write, rmt_lseek, rmt_ioctl):
* rmt/rmt.c (rmt_reply):
* tests/genfile.c (verify_file, print_stat):
Use C99 printf formats instead of doing it by hand.
* paxlib/paxlib.h, rmt/rmt.c, tests/genfile.c:
Do not include inttostr.h.
* paxlib/paxlib.h (STRINGIFY_BIGINT): Remove.
* tests/argcv.c (xtonum): Use strtol for signed int, not strtoul.
* tests/genfile.c (checkpoint, verify_file, parse_opt)
(exec_checkpoint, process_checkpoint, exec_command):
Prefer uintmax_t to size_t for counters unrelated to object size.
(PRINT_INT): New macro.
(print_stat): Prefer uintmax_t to unsigned for modes.
Diffstat (limited to 'paxlib/error.c')
-rw-r--r-- | paxlib/error.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/paxlib/error.c b/paxlib/error.c index 134cef3..f363d84 100644 --- a/paxlib/error.c +++ b/paxlib/error.c @@ -99,9 +99,10 @@ chmod_error_details (char const *name, mode_t mode) void chown_error_details (char const *name, uid_t uid, gid_t gid) { + uintmax_t u = uid, g = gid; int e = errno; - ERROR ((0, e, _("%s: Cannot change ownership to uid %lu, gid %lu"), - quotearg_colon (name), (unsigned long) uid, (unsigned long) gid)); + ERROR ((0, e, _("%s: Cannot change ownership to uid %ju, gid %ju"), + quotearg_colon (name), u, g)); } void @@ -175,27 +176,25 @@ read_error (char const *name) void read_error_details (char const *name, off_t offset, size_t size) { - char buf[UINTMAX_STRSIZE_BOUND]; + intmax_t off = offset; int e = errno; ERROR ((0, e, - ngettext ("%s: Read error at byte %s, while reading %lu byte", - "%s: Read error at byte %s, while reading %lu bytes", + ngettext ("%s: Read error at byte %jd, while reading %zu byte", + "%s: Read error at byte %jd, while reading %zu bytes", size), - quotearg_colon (name), STRINGIFY_BIGINT (offset, buf), - (unsigned long) size)); + quotearg_colon (name), off, size)); } void read_warn_details (char const *name, off_t offset, size_t size) { - char buf[UINTMAX_STRSIZE_BOUND]; + intmax_t off = offset; int e = errno; WARN ((0, e, - ngettext ("%s: Warning: Read error at byte %s, while reading %lu byte", - "%s: Warning: Read error at byte %s, while reading %lu bytes", + ngettext ("%s: Warning: Read error at byte %jd, while reading %zu byte", + "%s: Warning: Read error at byte %jd, while reading %zu bytes", size), - quotearg_colon (name), STRINGIFY_BIGINT (offset, buf), - (unsigned long) size)); + quotearg_colon (name), off, size)); } void @@ -207,14 +206,13 @@ read_fatal (char const *name) void read_fatal_details (char const *name, off_t offset, size_t size) { - char buf[UINTMAX_STRSIZE_BOUND]; + intmax_t off = offset; int e = errno; FATAL_ERROR ((0, e, - ngettext ("%s: Read error at byte %s, while reading %lu byte", - "%s: Read error at byte %s, while reading %lu bytes", + ngettext ("%s: Read error at byte %jd, while reading %zu byte", + "%s: Read error at byte %jd, while reading %zu bytes", size), - quotearg_colon (name), STRINGIFY_BIGINT (offset, buf), - (unsigned long) size)); + quotearg_colon (name), off, size)); } void @@ -256,11 +254,9 @@ seek_error (char const *name) void seek_error_details (char const *name, off_t offset) { - char buf[UINTMAX_STRSIZE_BOUND]; + intmax_t off = offset; int e = errno; - ERROR ((0, e, _("%s: Cannot seek to %s"), - quotearg_colon (name), - STRINGIFY_BIGINT (offset, buf))); + ERROR ((0, e, _("%s: Cannot seek to %jd"), quotearg_colon (name), off)); } void @@ -272,11 +268,10 @@ seek_warn (char const *name) void seek_warn_details (char const *name, off_t offset) { - char buf[UINTMAX_STRSIZE_BOUND]; + int off = offset; int e = errno; - WARN ((0, e, _("%s: Warning: Cannot seek to %s"), - quotearg_colon (name), - STRINGIFY_BIGINT (offset, buf))); + WARN ((0, e, _("%s: Warning: Cannot seek to %jd"), + quotearg_colon (name), off)); } void @@ -348,10 +343,10 @@ write_error_details (char const *name, size_t status, size_t size) write_error (name); else ERROR ((0, 0, - ngettext ("%s: Wrote only %lu of %lu byte", - "%s: Wrote only %lu of %lu bytes", + ngettext ("%s: Wrote only %zu of %zu byte", + "%s: Wrote only %zu of %zu bytes", size), - name, (unsigned long int) status, (unsigned long int) size)); + name, status, size)); } void |