From: Paul Eggert Date: Sat, 2 Nov 2024 03:03:53 +0000 (-0700) Subject: Prefer other types to int in system.c X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04c1b85872b14ab70b4015c413f1839e9730304a;p=thirdparty%2Ftar.git Prefer other types to int in system.c * src/system.c (is_regular_file, sys_exec_setmtime_script): Prefer bool for boolean. (sys_exec_command): Prefer char for char. --- diff --git a/src/common.h b/src/common.h index e62420d5..3a9e51b6 100644 --- a/src/common.h +++ b/src/common.h @@ -933,18 +933,16 @@ pid_t sys_child_open_for_compress (void); pid_t sys_child_open_for_uncompress (void); idx_t sys_write_archive_buffer (void); bool sys_get_archive_stat (void); -int sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st); +int sys_exec_command (char *file_name, char typechar, struct tar_stat_info *st); void sys_wait_command (void); int sys_exec_info_script (const char **archive_name, intmax_t volume_number); void sys_exec_checkpoint_script (const char *script_name, const char *archive_name, intmax_t checkpoint_number); bool mtioseek (bool count_files, off_t count); -int sys_exec_setmtime_script (const char *script_name, - int dirfd, - const char *file_name, - const char *fmt, - struct timespec *ts); +bool sys_exec_setmtime_script (const char *script_name, int dirfd, + const char *file_name, const char *fmt, + struct timespec *ts); /* Module compare.c */ void report_difference (struct tar_stat_info *st, const char *message, ...) diff --git a/src/create.c b/src/create.c index edda90b2..028b18dc 100644 --- a/src/create.c +++ b/src/create.c @@ -814,11 +814,11 @@ start_header (struct tar_stat_info *st) break; case COMMAND_MTIME: - if (sys_exec_setmtime_script (set_mtime_command, - chdir_fd, - st->orig_file_name, - set_mtime_format, - &mtime)) + if (!sys_exec_setmtime_script (set_mtime_command, + chdir_fd, + st->orig_file_name, + set_mtime_format, + &mtime)) mtime = st->mtime; break; } diff --git a/src/system.c b/src/system.c index fd2a290e..c0211642 100644 --- a/src/system.c +++ b/src/system.c @@ -157,7 +157,7 @@ sys_child_open_for_uncompress (void) paxfatal (0, _("Cannot use compressed or remote archives")); } -int +bool sys_exec_setmtime_script (const char *script_name, int dirfd, const char *file_name, @@ -293,15 +293,15 @@ sys_truncate (int fd) return pos < 0 ? -1 : ftruncate (fd, pos); } -/* Return nonzero if NAME is the name of a regular file, or if the file +/* Return true if NAME is the name of a regular file, or if the file does not exist (so it would be created as a regular file). */ -static int +static bool is_regular_file (const char *name) { struct stat stbuf; if (stat (name, &stbuf) == 0) - return S_ISREG (stbuf.st_mode); + return !!S_ISREG (stbuf.st_mode); else return errno == ENOENT; } @@ -747,7 +747,7 @@ static pid_t global_pid; static void (*pipe_handler) (int sig); int -sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st) +sys_exec_command (char *file_name, char typechar, struct tar_stat_info *st) { int p[2]; @@ -914,7 +914,7 @@ sys_exec_checkpoint_script (const char *script_name, xexec (script_name); } -int +bool sys_exec_setmtime_script (const char *script_name, int dirfd, const char *file_name, @@ -923,14 +923,14 @@ sys_exec_setmtime_script (const char *script_name, { pid_t pid; int p[2]; - int stop = 0; + bool stop = false; struct pollfd pfd; char *buffer = NULL; idx_t buflen = 0; idx_t bufsize = 0; char *cp; - int rc = 0; + bool rc = true; if (pipe (p) < 0) paxfatal (errno, _("pipe failed")); @@ -974,7 +974,7 @@ sys_exec_setmtime_script (const char *script_name, if (errno != EINTR) { paxerror (errno, _("poll failed")); - stop = 1; + stop = true; break; } } @@ -988,7 +988,7 @@ sys_exec_setmtime_script (const char *script_name, if (nread < 0) { paxerror (errno, _("error reading output of %s"), script_name); - stop = 1; + stop = true; break; } if (nread == 0) @@ -1008,13 +1008,13 @@ sys_exec_setmtime_script (const char *script_name, if (stop) { free (buffer); - return -1; + return false; } if (buflen == 0) { paxerror (0, _("empty output from \"%s %s\""), script_name, file_name); - return -1; + return false; } cp = memchr (buffer, '\n', buflen); @@ -1037,13 +1037,13 @@ sys_exec_setmtime_script (const char *script_name, paxerror (0, _("output from \"%s %s\" does not satisfy format string:" " %s"), script_name, file_name, buffer); - rc = -1; + rc = false; } else if (*cp != 0) { paxwarn (0, _("unconsumed output from \"%s %s\": %s"), script_name, file_name, cp); - rc = -1; + rc = false; } else { @@ -1052,7 +1052,7 @@ sys_exec_setmtime_script (const char *script_name, if (tm.tm_wday < 0) { paxerror (errno, _("mktime failed")); - rc = -1; + rc = false; } else { @@ -1065,7 +1065,7 @@ sys_exec_setmtime_script (const char *script_name, { paxerror (0, _("unparsable output from \"%s %s\": %s"), script_name, file_name, buffer); - rc = -1; + rc = false; } free (buffer);