summaryrefslogtreecommitdiff
path: root/paxlib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-09-10 15:13:28 -0500
committerPaul Eggert <eggert@cs.ucla.edu>2022-09-10 15:39:38 -0500
commit2bf63fcba72c4f4bc54a4caf53d7923c1f9f174f (patch)
treea466361955cef6e34765fbec4734d91d23029222 /paxlib
parent9ae062098da4383a6c9b39e245c1a2888a645352 (diff)
downloadpaxutils-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')
-rw-r--r--paxlib/error.c51
-rw-r--r--paxlib/paxlib.h5
-rw-r--r--paxlib/rtape.c34
3 files changed, 30 insertions, 60 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
diff --git a/paxlib/paxlib.h b/paxlib/paxlib.h
index c6e8382..5e82d8f 100644
--- a/paxlib/paxlib.h
+++ b/paxlib/paxlib.h
@@ -21,8 +21,6 @@
#ifndef _paxlib_h_
#define _paxlib_h_
-#include <inttostr.h>
-
/* Error reporting functions and definitions */
/* Exit status for paxutils app. Let's try to keep this list as simple as
@@ -121,9 +119,6 @@ void write_error_details (char const *, size_t, size_t);
_Noreturn void pax_exit (void);
_Noreturn void fatal_exit (void);
-
-#define STRINGIFY_BIGINT(i, b) umaxtostr (i, b)
-
/* Name-related functions */
bool removed_prefixes_p (void);
diff --git a/paxlib/rtape.c b/paxlib/rtape.c
index 2cd0c36..70d69ac 100644
--- a/paxlib/rtape.c
+++ b/paxlib/rtape.c
@@ -598,7 +598,7 @@ rmt_read (int handle, char *buffer, size_t length)
size_t rlen;
size_t counter;
- sprintf (command_buffer, "R%lu\n", (unsigned long) length);
+ sprintf (command_buffer, "R%zu\n", length);
if (do_command (handle, command_buffer) == -1
|| (status = get_status (handle)) == SAFE_READ_ERROR)
return SAFE_READ_ERROR;
@@ -625,7 +625,7 @@ rmt_write (int handle, char *buffer, size_t length)
void (*pipe_handler) ();
size_t written;
- sprintf (command_buffer, "W%lu\n", (unsigned long) length);
+ sprintf (command_buffer, "W%zu\n", length);
if (do_command (handle, command_buffer) == -1)
return 0;
@@ -654,16 +654,7 @@ off_t
rmt_lseek (int handle, off_t offset, int whence)
{
char command_buffer[COMMAND_BUFFER_SIZE];
- char operand_buffer[UINTMAX_STRSIZE_BOUND];
- uintmax_t u = offset < 0 ? - (uintmax_t) offset : (uintmax_t) offset;
- char *p = operand_buffer + sizeof operand_buffer;
-
- *--p = 0;
- do
- *--p = '0' + (int) (u % 10);
- while ((u /= 10) != 0);
- if (offset < 0)
- *--p = '-';
+ intmax_t off = offset;
switch (whence)
{
@@ -683,7 +674,7 @@ rmt_lseek (int handle, off_t offset, int whence)
abort ();
}
- sprintf (command_buffer, "L%s\n%d\n", p, whence);
+ sprintf (command_buffer, "L%jd\n%d\n", off, whence);
if (do_command (handle, command_buffer) == -1)
return -1;
@@ -705,24 +696,13 @@ rmt_ioctl (int handle, unsigned long int operation, char *argument)
#ifdef MTIOCTOP
case MTIOCTOP:
{
+ struct mtop *arg = (struct mtop *) argument;
char command_buffer[COMMAND_BUFFER_SIZE];
- char operand_buffer[UINTMAX_STRSIZE_BOUND];
- uintmax_t u = (((struct mtop *) argument)->mt_count < 0
- ? - (uintmax_t) ((struct mtop *) argument)->mt_count
- : (uintmax_t) ((struct mtop *) argument)->mt_count);
- char *p = operand_buffer + sizeof operand_buffer;
-
- *--p = 0;
- do
- *--p = '0' + (int) (u % 10);
- while ((u /= 10) != 0);
- if (((struct mtop *) argument)->mt_count < 0)
- *--p = '-';
+ intmax_t count = arg->mt_count;
/* MTIOCTOP is the easy one. Nothing is transferred in binary. */
- sprintf (command_buffer, "I%d\n%s\n",
- ((struct mtop *) argument)->mt_op, p);
+ sprintf (command_buffer, "I%d\n%jd\n", arg->mt_op, count);
if (do_command (handle, command_buffer) == -1)
return -1;