Fewer macros in extract.c

* src/extract.c (ALL_MODE_BITS, RECOVER_NO, RECOVER_OK)
(RECOVER_SKIP): Now constants or inline functions, not macros.
(maybe_recoverable): Return enum recover, not int.
This commit is contained in:
Paul Eggert
2024-08-19 09:42:59 -07:00
parent da109fae7a
commit 79cb9aaab6

View File

@@ -36,7 +36,7 @@ static bool we_are_root; /* true if our effective uid == 0 */
static mode_t newdir_umask; /* umask when creating new directories */
static mode_t current_umask; /* current umask (which is set to 0 if -p) */
#define ALL_MODE_BITS ((mode_t) ~ (mode_t) 0)
static mode_t const all_mode_bits = ~ (mode_t) 0;
#if ! HAVE_FCHMOD && ! defined fchmod
# define fchmod(fd, mode) (errno = ENOSYS, -1)
@@ -645,7 +645,7 @@ repair_delayed_set_stat (char const *dir,
data->atime = current_stat_info.atime;
data->mtime = current_stat_info.mtime;
data->current_mode = st.st_mode;
data->current_mode_mask = ALL_MODE_BITS;
data->current_mode_mask = all_mode_bits;
data->interdir = false;
return;
}
@@ -830,9 +830,7 @@ file_newer_p (const char *file_name, struct stat const *stp,
&& tar_timespec_cmp (tar_stat->mtime, get_stat_mtime (stp)) <= 0);
}
#define RECOVER_NO 0
#define RECOVER_OK 1
#define RECOVER_SKIP 2
enum recover { RECOVER_NO, RECOVER_OK, RECOVER_SKIP };
/* Attempt repairing what went wrong with the extraction. Delete an
already existing file or create missing intermediate directories.
@@ -846,7 +844,7 @@ file_newer_p (const char *file_name, struct stat const *stp,
Set *INTERDIR_MADE if an intermediate directory is made as part of
the recovery process. */
static int
static enum recover
maybe_recoverable (char *file_name, bool regular, bool *interdir_made)
{
int e = errno;
@@ -994,7 +992,7 @@ apply_nonancestor_delayed_set_stat (char const *file_name, bool after_links)
else
{
current_mode = st.st_mode;
current_mode_mask = ALL_MODE_BITS;
current_mode_mask = all_mode_bits;
if (! (st.st_dev == data->dev && st.st_ino == data->ino))
{
paxerror (0,
@@ -1122,7 +1120,7 @@ extract_dir (char *file_name, int typeflag)
|| deref_stat (file_name, &st) == 0)
{
current_mode = st.st_mode;
current_mode_mask = ALL_MODE_BITS;
current_mode_mask = all_mode_bits;
if (S_ISDIR (current_mode))
{
@@ -1265,7 +1263,7 @@ open_output_file (char const *file_name, int typeflag, mode_t mode,
return -1;
}
*current_mode = st.st_mode;
*current_mode_mask = ALL_MODE_BITS;
*current_mode_mask = all_mode_bits;
}
}
@@ -1312,7 +1310,8 @@ extract_file (char *file_name, int typeflag)
&current_mode_mask))
< 0))
{
int recover = maybe_recoverable (file_name, true, &interdir_made);
enum recover recover
= maybe_recoverable (file_name, true, &interdir_made);
if (recover != RECOVER_OK)
{
skip_member ();
@@ -1521,7 +1520,7 @@ extract_link (char *file_name, MAYBE_UNUSED int typeflag)
{
bool interdir_made = false;
char const *link_name;
int rc;
enum recover rc;
link_name = current_stat_info.link_name;