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.
This commit is contained in:
Paul Eggert
2024-11-01 20:03:53 -07:00
parent ef95115f61
commit 04c1b85872
3 changed files with 25 additions and 27 deletions

View File

@@ -933,17 +933,15 @@ pid_t sys_child_open_for_compress (void);
pid_t sys_child_open_for_uncompress (void); pid_t sys_child_open_for_uncompress (void);
idx_t sys_write_archive_buffer (void); idx_t sys_write_archive_buffer (void);
bool sys_get_archive_stat (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); void sys_wait_command (void);
int sys_exec_info_script (const char **archive_name, intmax_t volume_number); int sys_exec_info_script (const char **archive_name, intmax_t volume_number);
void sys_exec_checkpoint_script (const char *script_name, void sys_exec_checkpoint_script (const char *script_name,
const char *archive_name, const char *archive_name,
intmax_t checkpoint_number); intmax_t checkpoint_number);
bool mtioseek (bool count_files, off_t count); bool mtioseek (bool count_files, off_t count);
int sys_exec_setmtime_script (const char *script_name, bool sys_exec_setmtime_script (const char *script_name, int dirfd,
int dirfd, const char *file_name, const char *fmt,
const char *file_name,
const char *fmt,
struct timespec *ts); struct timespec *ts);
/* Module compare.c */ /* Module compare.c */

View File

@@ -814,7 +814,7 @@ start_header (struct tar_stat_info *st)
break; break;
case COMMAND_MTIME: case COMMAND_MTIME:
if (sys_exec_setmtime_script (set_mtime_command, if (!sys_exec_setmtime_script (set_mtime_command,
chdir_fd, chdir_fd,
st->orig_file_name, st->orig_file_name,
set_mtime_format, set_mtime_format,

View File

@@ -157,7 +157,7 @@ sys_child_open_for_uncompress (void)
paxfatal (0, _("Cannot use compressed or remote archives")); paxfatal (0, _("Cannot use compressed or remote archives"));
} }
int bool
sys_exec_setmtime_script (const char *script_name, sys_exec_setmtime_script (const char *script_name,
int dirfd, int dirfd,
const char *file_name, const char *file_name,
@@ -293,15 +293,15 @@ sys_truncate (int fd)
return pos < 0 ? -1 : ftruncate (fd, pos); 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). */ does not exist (so it would be created as a regular file). */
static int static bool
is_regular_file (const char *name) is_regular_file (const char *name)
{ {
struct stat stbuf; struct stat stbuf;
if (stat (name, &stbuf) == 0) if (stat (name, &stbuf) == 0)
return S_ISREG (stbuf.st_mode); return !!S_ISREG (stbuf.st_mode);
else else
return errno == ENOENT; return errno == ENOENT;
} }
@@ -747,7 +747,7 @@ static pid_t global_pid;
static void (*pipe_handler) (int sig); static void (*pipe_handler) (int sig);
int 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]; int p[2];
@@ -914,7 +914,7 @@ sys_exec_checkpoint_script (const char *script_name,
xexec (script_name); xexec (script_name);
} }
int bool
sys_exec_setmtime_script (const char *script_name, sys_exec_setmtime_script (const char *script_name,
int dirfd, int dirfd,
const char *file_name, const char *file_name,
@@ -923,14 +923,14 @@ sys_exec_setmtime_script (const char *script_name,
{ {
pid_t pid; pid_t pid;
int p[2]; int p[2];
int stop = 0; bool stop = false;
struct pollfd pfd; struct pollfd pfd;
char *buffer = NULL; char *buffer = NULL;
idx_t buflen = 0; idx_t buflen = 0;
idx_t bufsize = 0; idx_t bufsize = 0;
char *cp; char *cp;
int rc = 0; bool rc = true;
if (pipe (p) < 0) if (pipe (p) < 0)
paxfatal (errno, _("pipe failed")); paxfatal (errno, _("pipe failed"));
@@ -974,7 +974,7 @@ sys_exec_setmtime_script (const char *script_name,
if (errno != EINTR) if (errno != EINTR)
{ {
paxerror (errno, _("poll failed")); paxerror (errno, _("poll failed"));
stop = 1; stop = true;
break; break;
} }
} }
@@ -988,7 +988,7 @@ sys_exec_setmtime_script (const char *script_name,
if (nread < 0) if (nread < 0)
{ {
paxerror (errno, _("error reading output of %s"), script_name); paxerror (errno, _("error reading output of %s"), script_name);
stop = 1; stop = true;
break; break;
} }
if (nread == 0) if (nread == 0)
@@ -1008,13 +1008,13 @@ sys_exec_setmtime_script (const char *script_name,
if (stop) if (stop)
{ {
free (buffer); free (buffer);
return -1; return false;
} }
if (buflen == 0) if (buflen == 0)
{ {
paxerror (0, _("empty output from \"%s %s\""), script_name, file_name); paxerror (0, _("empty output from \"%s %s\""), script_name, file_name);
return -1; return false;
} }
cp = memchr (buffer, '\n', buflen); 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:" paxerror (0, _("output from \"%s %s\" does not satisfy format string:"
" %s"), " %s"),
script_name, file_name, buffer); script_name, file_name, buffer);
rc = -1; rc = false;
} }
else if (*cp != 0) else if (*cp != 0)
{ {
paxwarn (0, _("unconsumed output from \"%s %s\": %s"), paxwarn (0, _("unconsumed output from \"%s %s\": %s"),
script_name, file_name, cp); script_name, file_name, cp);
rc = -1; rc = false;
} }
else else
{ {
@@ -1052,7 +1052,7 @@ sys_exec_setmtime_script (const char *script_name,
if (tm.tm_wday < 0) if (tm.tm_wday < 0)
{ {
paxerror (errno, _("mktime failed")); paxerror (errno, _("mktime failed"));
rc = -1; rc = false;
} }
else else
{ {
@@ -1065,7 +1065,7 @@ sys_exec_setmtime_script (const char *script_name,
{ {
paxerror (0, _("unparsable output from \"%s %s\": %s"), paxerror (0, _("unparsable output from \"%s %s\": %s"),
script_name, file_name, buffer); script_name, file_name, buffer);
rc = -1; rc = false;
} }
free (buffer); free (buffer);