bool cmdline; /* true if this name was given in the
command line */
- int change_dir; /* Number of the directory to change to.
+ idx_t change_dir; /* Number of the directory to change to.
Set with the -C option. */
uintmax_t found_count; /* number of times a matching file has
been found */
#define ASSIGN_STRING_N(s,v) assign_string_n (s, v, sizeof (v))
int unquote_string (char *str);
char *zap_slashes (char *name);
-char *normalize_filename (int cdidx, const char *name);
+char *normalize_filename (idx_t, char const *);
void normalize_filename_x (char *name);
void replace_prefix (char **pname, const char *samp, size_t slen,
const char *repl, size_t rlen);
size_t blocking_read (int fd, void *buf, size_t count);
size_t blocking_write (int fd, void const *buf, size_t count);
-extern int chdir_current;
+extern idx_t chdir_current;
extern int chdir_fd;
-int chdir_arg (char const *dir);
-void chdir_do (int dir);
-int chdir_count (void);
+idx_t chdir_arg (char const *dir);
+void chdir_do (idx_t dir);
+idx_t chdir_count (void);
void close_diag (char const *name);
void open_diag (char const *name);
void name_init (void);
void name_add_name (const char *name);
void name_term (void);
-const char *name_next (int change_dirs);
+char const *name_next (bool);
void name_gather (void);
-struct name *addname (char const *string, int change_dir,
- bool cmdline, struct name *parent);
+struct name *addname (char const *, idx_t, bool, struct name *);
void add_starting_file (char const *file_name);
void remname (struct name *name);
bool name_match (const char *name);
else
{
const char *name;
- while ((name = name_next (1)) != NULL)
+ while ((name = name_next (true)))
if (!excluded_name (name, NULL))
dump_file (0, name, name);
}
bool after_links;
/* Directory that the name is relative to. */
- int change_dir;
+ idx_t change_dir;
/* extended attributes*/
char *cntx_name;
struct timespec mtime;
/* The directory that the sources and target are relative to. */
- int change_dir;
+ idx_t change_dir;
/* A list of sources for this link. The sources are all to be
hard-linked together. */
(see NOTICE in the comment to delay_set_stat above) */
if (!delay_directory_restore_option)
{
- int dir = chdir_current;
+ idx_t dir = chdir_current;
apply_nonancestor_delayed_set_stat (current_stat_info.file_name, false);
chdir_do (dir);
}
static void namebuf_add_dir (namebuf_t, char const *);
static char *namebuf_finish (namebuf_t);
-static const char *tar_getcdpath (int);
+static const char *tar_getcdpath (idx_t);
char const *
quote_n_colon (int n, char const *arg)
Return a normalized newly-allocated copy. */
char *
-normalize_filename (int cdidx, const char *name)
+normalize_filename (idx_t cdidx, const char *name)
{
char *copy = NULL;
static struct wd *wd;
/* The number of working directories in the vector. */
-static size_t wd_count;
+static idx_t wd_count;
/* The allocated size of the vector. */
static size_t wd_alloc;
/* Number of nonzero entries in WDCACHE. */
static size_t wdcache_count;
-int
+idx_t
chdir_count (void)
{
- if (wd_count == 0)
- return wd_count;
- return wd_count - 1;
+ return wd_count - !!wd_count;
}
/* DIR is the operand of a -C option; add it to vector of chdir targets,
and return the index of its location. */
-int
+idx_t
chdir_arg (char const *dir)
{
if (wd_count == wd_alloc)
}
/* Index of current directory. */
-int chdir_current;
+idx_t chdir_current;
/* Value suitable for use as the first argument to openat, and in
similar locations for fstatat, etc. This is an open file
working directory; otherwise, I must be a value returned by
chdir_arg. */
void
-chdir_do (int i)
+chdir_do (idx_t i)
{
if (chdir_current != i)
{
process's actual cwd. (Note that in this case IDX is ignored,
since it should always be 0.) */
static const char *
-tar_getcdpath (int idx)
+tar_getcdpath (idx_t idx)
{
if (!wd)
{
if (!wd[idx].abspath)
{
- int i;
- int save_cwdi = chdir_current;
-
- for (i = idx; i >= 0; i--)
- if (wd[i].abspath)
- break;
+ idx_t save_cwdi = chdir_current, i = idx;
+ while (0 < i && !wd[i - 1].abspath)
+ i--;
- while (++i <= idx)
+ for (; i <= idx; i++)
{
chdir_do (i);
if (i == 0)
*/
static struct name_elt *
-name_next_elt (int change_dirs)
+name_next_elt (bool change_dirs)
{
static struct name_elt entry;
struct name_elt *ep;
}
const char *
-name_next (int change_dirs)
+name_next (bool change_dirs)
{
struct name_elt *nelt = name_next_elt (change_dirs);
return nelt ? nelt->v.name : NULL;
if (same_order_option)
{
- static int change_dir;
+ static idx_t change_dir;
- while ((ep = name_next_elt (0)) && ep->type == NELT_CHDIR)
+ while ((ep = name_next_elt (false)) && ep->type == NELT_CHDIR)
change_dir = chdir_arg (xstrdup (ep->v.name));
if (ep)
else
{
/* Non sorted names -- read them all in. */
- int change_dir = 0;
+ idx_t change_dir = 0;
for (;;)
{
- int change_dir0 = change_dir;
- while ((ep = name_next_elt (0)) && ep->type == NELT_CHDIR)
+ idx_t change_dir0 = change_dir;
+ while ((ep = name_next_elt (false)) && ep->type == NELT_CHDIR)
change_dir = chdir_arg (xstrdup (ep->v.name));
if (ep)
/* Add a name to the namelist. */
struct name *
-addname (char const *string, int change_dir, bool cmdline, struct name *parent)
+addname (char const *string, idx_t change_dir, bool cmdline,
+ struct name *parent)
{
struct name *name = make_name (string);
{
const char *name;
- while ((name = name_next (1)) != NULL)
+ while ((name = name_next (true)))
{
regex_usage_warning (name);
ERROR ((0, 0, _("%s: Not found in archive"),
{
const char *name;
- while ((name = name_next (1)) != NULL
+ while ((name = name_next (true))
&& regex_usage_warning (name) == 0)
;
}
char *namebuf = xmalloc (allocated_length);
const char *string;
size_t string_length;
- int change_dir = name->change_dir;
+ idx_t change_dir = name->change_dir;
strcpy (namebuf, name->name);
if (! ISSLASH (namebuf[name_length - 1]))
struct deferred_unlink
{
struct deferred_unlink *next; /* Next unlink in the queue */
- int dir_idx; /* Directory index in wd */
+ idx_t dir_idx; /* Directory index in wd */
char *file_name; /* Name of the file to unlink, relative
to dir_idx */
bool is_dir; /* True if file_name is a directory */
p->next = anchor->next;
anchor->next = p;
}
- else
+ else
{
p->next = dunlink_head;
dunlink_head = p;
flush_deferred_unlinks (bool force)
{
struct deferred_unlink *p, *prev = NULL;
- int saved_chdir = chdir_current;
-
+ idx_t saved_chdir = chdir_current;
+
for (p = dunlink_head; p; )
{
struct deferred_unlink *next = p->next;
p = next;
}
dunlink_head = dunlink_tail = NULL;
- }
-
+ }
+
chdir_do (saved_chdir);
}
finish_deferred_unlinks (void)
{
flush_deferred_unlinks (true);
-
+
while (dunlink_avail)
{
struct deferred_unlink *next = dunlink_avail->next;