From 34795cedb7db68babf7eae672ba47fd486555be8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 Aug 2010 13:25:58 -0700 Subject: [PATCH] tar: don't export names that aren't used elsewhere * src/common.h (file_dumpable_p, gid_to_chars, major_to_chars): (minor_to_chars, mode_to_chars, uid_to_chars, uintmax_to_chars): (string_to_chars, dumpdir_creat0, dumpdir_create, dumpdir_free): (dumpdir_locate, dumpdir_next, dumpdir_first, gid_from_header): (major_from_header, minor_from_header, mode_from_header): (time_from_header, uid_from_header, quote_copy_string, request_stdin): (xheader_init, transform_header_name): Remove declarations; these are no longer exported from their modules. (GID_TO_CHARS, MAJOR_TO_CHARS, MINOR_TO_CHARS, MODE_TO_CHARS): (UID_TO_CHARS, UINTMAX_TO_CHARS, UNAME_TO_CHARS, GNAME_TO_CHARS): Move to src/create.c, since no other module uses these. (GID_FROM_HEADER, MAJOR_FROM_HEADER, MINOR_FROM_HEADER): (MODE_FROM_HEADER, TIME_FROM_HEADER, UID_FROM_HEADER): Move to src/extract.c, since no other module uses these. (dumpdir_t, dumpdir_iter_t): Remove; no longer used. * src/create.c (gid_to_chars, major_to_chars, minor_to_chars): (mode_to_chars, uid_to_chars, uintmax_to_chars, string_to_chars): (file_dumpable_p): Now static. * src/incremen.c (dumpdir_create0, dumpdir_create, dumpdir_free): (dumpdir_locate, dumpdir_next, dumpdir_first): Now static. (scan_directory, write_directory_file_entry): Use struct dumpdir_iter * rather than dumpdir_iter_t. * src/list.c (gid_from_header, major_from_header, minor_from_header): (mode_from_header, time_from_header, uid_from_header): (transform_member_name): Now static. * src/misc.c (quote_copy_string): #if 0 out, as it's not used anywhere. * src/system.c (wait_for_grandchild): Now static. * src/tar.c (request_stdin): Now static. * src/xheader.c (xheader_init): Now static. --- src/common.h | 44 +------------------------------------------- src/create.c | 24 ++++++++++++++++-------- src/incremen.c | 16 ++++++++-------- src/list.c | 28 +++++++++++++++++++++------- src/misc.c | 6 +++++- src/system.c | 4 ++-- src/tar.c | 2 +- src/xheader.c | 3 ++- 8 files changed, 56 insertions(+), 71 deletions(-) diff --git a/src/common.h b/src/common.h index 595e2ee..24227f4 100644 --- a/src/common.h +++ b/src/common.h @@ -449,7 +449,6 @@ void add_exclusion_tag (const char *name, enum exclusion_tag_type type, bool (*)(const char*)); bool cachedir_file_p (const char *name); -bool file_dumpable_p (struct tar_stat_info *st); void create_archive (void); void pad_archive (off_t size_left); void dump_file (const char *st, bool top_level, dev_t parent_device); @@ -467,28 +466,13 @@ void exclusion_tag_warning (const char *dirname, const char *tagname, enum exclusion_tag_type check_exclusion_tags (const char *dirname, const char **tag_file_name); -#define GID_TO_CHARS(val, where) gid_to_chars (val, where, sizeof (where)) -#define MAJOR_TO_CHARS(val, where) major_to_chars (val, where, sizeof (where)) -#define MINOR_TO_CHARS(val, where) minor_to_chars (val, where, sizeof (where)) -#define MODE_TO_CHARS(val, where) mode_to_chars (val, where, sizeof (where)) #define OFF_TO_CHARS(val, where) off_to_chars (val, where, sizeof (where)) #define SIZE_TO_CHARS(val, where) size_to_chars (val, where, sizeof (where)) #define TIME_TO_CHARS(val, where) time_to_chars (val, where, sizeof (where)) -#define UID_TO_CHARS(val, where) uid_to_chars (val, where, sizeof (where)) -#define UINTMAX_TO_CHARS(val, where) uintmax_to_chars (val, where, sizeof (where)) -#define UNAME_TO_CHARS(name,buf) string_to_chars (name, buf, sizeof(buf)) -#define GNAME_TO_CHARS(name,buf) string_to_chars (name, buf, sizeof(buf)) - -bool gid_to_chars (gid_t gid, char *buf, size_t size); -bool major_to_chars (major_t m, char *buf, size_t size); -bool minor_to_chars (minor_t m, char *buf, size_t size); -bool mode_to_chars (mode_t m, char *buf, size_t size); + bool off_to_chars (off_t off, char *buf, size_t size); bool size_to_chars (size_t v, char *buf, size_t size); bool time_to_chars (time_t t, char *buf, size_t size); -bool uid_to_chars (uid_t uid, char *buf, size_t size); -bool uintmax_to_chars (uintmax_t v, char *buf, size_t size); -void string_to_chars (char const *s, char *buf, size_t size); /* Module diffarch.c. */ @@ -510,15 +494,6 @@ bool rename_directory (char *src, char *dst); void delete_archive_members (void); /* Module incremen.c. */ -typedef struct dumpdir *dumpdir_t; -typedef struct dumpdir_iter *dumpdir_iter_t; - -dumpdir_t dumpdir_create0 (const char *contents, const char *cmask); -dumpdir_t dumpdir_create (const char *contents); -void dumpdir_free (dumpdir_t); -char *dumpdir_locate (dumpdir_t dump, const char *name); -char *dumpdir_next (dumpdir_iter_t itr); -char *dumpdir_first (dumpdir_t dump, int all, dumpdir_iter_t *pitr); struct directory *scan_directory (char *dir, dev_t device, bool cmdline); void name_fill_directory (struct name *name, dev_t device, bool cmdline); @@ -571,25 +546,12 @@ void decode_header (union block *header, struct tar_stat_info *stat_info, enum archive_format *format_pointer, int do_user_group); char const *tartime (struct timespec t, bool full_time); -#define GID_FROM_HEADER(where) gid_from_header (where, sizeof (where)) -#define MAJOR_FROM_HEADER(where) major_from_header (where, sizeof (where)) -#define MINOR_FROM_HEADER(where) minor_from_header (where, sizeof (where)) -#define MODE_FROM_HEADER(where, hbits) \ - mode_from_header (where, sizeof (where), hbits) #define OFF_FROM_HEADER(where) off_from_header (where, sizeof (where)) #define SIZE_FROM_HEADER(where) size_from_header (where, sizeof (where)) -#define TIME_FROM_HEADER(where) time_from_header (where, sizeof (where)) -#define UID_FROM_HEADER(where) uid_from_header (where, sizeof (where)) #define UINTMAX_FROM_HEADER(where) uintmax_from_header (where, sizeof (where)) -gid_t gid_from_header (const char *buf, size_t size); -major_t major_from_header (const char *buf, size_t size); -minor_t minor_from_header (const char *buf, size_t size); -mode_t mode_from_header (const char *buf, size_t size, unsigned *hbits); off_t off_from_header (const char *buf, size_t size); size_t size_from_header (const char *buf, size_t size); -time_t time_from_header (const char *buf, size_t size); -uid_t uid_from_header (const char *buf, size_t size); uintmax_t uintmax_from_header (const char *buf, size_t size); void list_archive (void); @@ -608,7 +570,6 @@ void skip_member (void); /* Module misc.c. */ void assign_string (char **dest, const char *src); -char *quote_copy_string (const char *str); int unquote_string (char *str); char *zap_slashes (char *name); char *normalize_filename (const char *name); @@ -720,7 +681,6 @@ bool contains_dot_dot (char const *name); void usage (int); int confirm (const char *message_action, const char *name); -void request_stdin (const char *option); void tar_stat_init (struct tar_stat_info *st); void tar_stat_destroy (struct tar_stat_info *st); @@ -738,7 +698,6 @@ void update_archive (void); /* Module xheader.c. */ -void xheader_init (struct xheader *xhdr); void xheader_decode (struct tar_stat_info *stat); void xheader_decode_global (struct xheader *xhdr); void xheader_store (char const *keyword, struct tar_stat_info *st, @@ -804,7 +763,6 @@ bool utf8_convert (bool to_utf, char const *input, char **output); void set_transform_expr (const char *expr); bool transform_name (char **pinput, int type); -bool transform_member_name (char **pinput, int type); bool transform_name_fp (char **pinput, int type, char *(*fun)(char *, void *), void *); diff --git a/src/create.c b/src/create.c index 6777f9c..fbd7165 100644 --- a/src/create.c +++ b/src/create.c @@ -214,6 +214,14 @@ to_base256 (int negative, uintmax_t value, char *where, size_t size) while (i); } +#define GID_TO_CHARS(val, where) gid_to_chars (val, where, sizeof (where)) +#define MAJOR_TO_CHARS(val, where) major_to_chars (val, where, sizeof (where)) +#define MINOR_TO_CHARS(val, where) minor_to_chars (val, where, sizeof (where)) +#define MODE_TO_CHARS(val, where) mode_to_chars (val, where, sizeof (where)) +#define UID_TO_CHARS(val, where) uid_to_chars (val, where, sizeof (where)) +#define UINTMAX_TO_CHARS(val, where) uintmax_to_chars (val, where, sizeof (where)) +#define UNAME_TO_CHARS(name,buf) string_to_chars (name, buf, sizeof(buf)) +#define GNAME_TO_CHARS(name,buf) string_to_chars (name, buf, sizeof(buf)) static bool to_chars (int negative, uintmax_t value, size_t valsize, @@ -368,25 +376,25 @@ gid_substitute (int *negative) return r; } -bool +static bool gid_to_chars (gid_t v, char *p, size_t s) { return to_chars (v < 0, (uintmax_t) v, sizeof v, gid_substitute, p, s, "gid_t"); } -bool +static bool major_to_chars (major_t v, char *p, size_t s) { return to_chars (v < 0, (uintmax_t) v, sizeof v, 0, p, s, "major_t"); } -bool +static bool minor_to_chars (minor_t v, char *p, size_t s) { return to_chars (v < 0, (uintmax_t) v, sizeof v, 0, p, s, "minor_t"); } -bool +static bool mode_to_chars (mode_t v, char *p, size_t s) { /* In the common case where the internal and external mode bits are the same, @@ -460,19 +468,19 @@ uid_substitute (int *negative) return r; } -bool +static bool uid_to_chars (uid_t v, char *p, size_t s) { return to_chars (v < 0, (uintmax_t) v, sizeof v, uid_substitute, p, s, "uid_t"); } -bool +static bool uintmax_to_chars (uintmax_t v, char *p, size_t s) { return to_chars (0, v, sizeof v, 0, p, s, "uintmax_t"); } -void +static void string_to_chars (char const *str, char *p, size_t s) { tar_copy_str (p, str, s); @@ -487,7 +495,7 @@ string_to_chars (char const *str, char *p, size_t s) a) it is empty *and* world-readable, or b) current archive is /dev/null */ -bool +static bool file_dumpable_p (struct tar_stat_info *st) { if (dev_null_output) diff --git a/src/incremen.c b/src/incremen.c index 0d1c115..5f00944 100644 --- a/src/incremen.c +++ b/src/incremen.c @@ -77,7 +77,7 @@ struct directory char *name; /* file name of directory */ }; -struct dumpdir * +static struct dumpdir * dumpdir_create0 (const char *contents, const char *cmask) { struct dumpdir *dump; @@ -108,13 +108,13 @@ dumpdir_create0 (const char *contents, const char *cmask) return dump; } -struct dumpdir * +static struct dumpdir * dumpdir_create (const char *contents) { return dumpdir_create0 (contents, "YND"); } -void +static void dumpdir_free (struct dumpdir *dump) { free (dump->elv); @@ -131,7 +131,7 @@ compare_dirnames (const void *first, const void *second) /* Locate NAME in the dumpdir array DUMP. Return pointer to the slot in DUMP->contents, or NULL if not found */ -char * +static char * dumpdir_locate (struct dumpdir *dump, const char *name) { char **ptr; @@ -150,7 +150,7 @@ struct dumpdir_iter size_t next; /* Index of the next element */ }; -char * +static char * dumpdir_next (struct dumpdir_iter *itr) { size_t cur = itr->next; @@ -172,7 +172,7 @@ dumpdir_next (struct dumpdir_iter *itr) return ret; } -char * +static char * dumpdir_first (struct dumpdir *dump, int all, struct dumpdir_iter **pitr) { struct dumpdir_iter *itr = xmalloc (sizeof (*itr)); @@ -723,7 +723,7 @@ scan_directory (char *dir, dev_t device, bool cmdline) if (dirp && directory->children != NO_CHILDREN) { char *entry; /* directory entry being scanned */ - dumpdir_iter_t itr; + struct dumpdir_iter *itr; makedumpdir (directory, dirp); @@ -1386,7 +1386,7 @@ write_directory_file_entry (void *entry, void *data) if (directory->dump) { const char *p; - dumpdir_iter_t itr; + struct dumpdir_iter *itr; for (p = dumpdir_first (directory->dump, 0, &itr); p; diff --git a/src/list.c b/src/list.c index 9184bea..f0d3d5a 100644 --- a/src/list.c +++ b/src/list.c @@ -35,6 +35,20 @@ size_t recent_long_name_blocks; /* number of blocks in recent_long_name */ size_t recent_long_link_blocks; /* likewise, for long link */ union block *recent_global_header; /* Recent global header block */ +#define GID_FROM_HEADER(where) gid_from_header (where, sizeof (where)) +#define MAJOR_FROM_HEADER(where) major_from_header (where, sizeof (where)) +#define MINOR_FROM_HEADER(where) minor_from_header (where, sizeof (where)) +#define MODE_FROM_HEADER(where, hbits) \ + mode_from_header (where, sizeof (where), hbits) +#define TIME_FROM_HEADER(where) time_from_header (where, sizeof (where)) +#define UID_FROM_HEADER(where) uid_from_header (where, sizeof (where)) + +static gid_t gid_from_header (const char *buf, size_t size); +static major_t major_from_header (const char *buf, size_t size); +static minor_t minor_from_header (const char *buf, size_t size); +static mode_t mode_from_header (const char *buf, size_t size, unsigned *hbits); +static time_t time_from_header (const char *buf, size_t size); +static uid_t uid_from_header (const char *buf, size_t size); static uintmax_t from_header (const char *, size_t, const char *, uintmax_t, uintmax_t, bool, bool); @@ -516,7 +530,7 @@ decode_xform (char *file_name, void *data) return file_name; } -bool +static bool transform_member_name (char **pinput, int type) { return transform_name_fp (pinput, type, decode_xform, &type); @@ -874,7 +888,7 @@ from_header (char const *where0, size_t digs, char const *type, return -1; } -gid_t +static gid_t gid_from_header (const char *p, size_t s) { return from_header (p, s, "gid_t", @@ -883,7 +897,7 @@ gid_from_header (const char *p, size_t s) false, false); } -major_t +static major_t major_from_header (const char *p, size_t s) { return from_header (p, s, "major_t", @@ -891,7 +905,7 @@ major_from_header (const char *p, size_t s) (uintmax_t) TYPE_MAXIMUM (major_t), false, false); } -minor_t +static minor_t minor_from_header (const char *p, size_t s) { return from_header (p, s, "minor_t", @@ -901,7 +915,7 @@ minor_from_header (const char *p, size_t s) /* Convert P to the file mode, as understood by tar. Store unrecognized mode bits (from 10th up) in HBITS. */ -mode_t +static mode_t mode_from_header (const char *p, size_t s, unsigned *hbits) { unsigned u = from_header (p, s, "mode_t", @@ -939,7 +953,7 @@ size_from_header (const char *p, size_t s) (uintmax_t) TYPE_MAXIMUM (size_t), false, false); } -time_t +static time_t time_from_header (const char *p, size_t s) { return from_header (p, s, "time_t", @@ -947,7 +961,7 @@ time_from_header (const char *p, size_t s) (uintmax_t) TYPE_MAXIMUM (time_t), false, false); } -uid_t +static uid_t uid_from_header (const char *p, size_t s) { return from_header (p, s, "uid_t", diff --git a/src/misc.c b/src/misc.c index ecf3fd8..4bae75e 100644 --- a/src/misc.c +++ b/src/misc.c @@ -50,6 +50,9 @@ assign_string (char **string, const char *value) *string = value ? xstrdup (value) : 0; } +#if 0 +/* This function is currently unused; perhaps it should be removed? */ + /* Allocate a copy of the string quoted as in C, and returns that. If the string does not have to be quoted, it returns a null pointer. The allocated copy should normally be freed with free() after the @@ -62,7 +65,7 @@ assign_string (char **string, const char *value) when reading directory files. This means that we can't use quotearg, as quotearg is locale-dependent and is meant for human consumption. */ -char * +static char * quote_copy_string (const char *string) { const char *source = string; @@ -103,6 +106,7 @@ quote_copy_string (const char *string) } return 0; } +#endif /* Takes a quoted C string (like those produced by quote_copy_string) and turns it back into the un-quoted original. This is done in diff --git a/src/system.c b/src/system.c index 345cc07..f8c3ec1 100644 --- a/src/system.c +++ b/src/system.c @@ -283,10 +283,10 @@ xdup2 (int from, int into) } } -void wait_for_grandchild (pid_t pid) __attribute__ ((__noreturn__)); +static void wait_for_grandchild (pid_t pid) __attribute__ ((__noreturn__)); /* Propagate any failure of the grandchild back to the parent. */ -void +static void wait_for_grandchild (pid_t pid) { int wait_status; diff --git a/src/tar.c b/src/tar.c index 4bfcdce..782ed3b 100644 --- a/src/tar.c +++ b/src/tar.c @@ -74,7 +74,7 @@ static const char *stdin_used_by; /* Doesn't return if stdin already requested. */ -void +static void request_stdin (const char *option) { if (stdin_used_by) diff --git a/src/xheader.c b/src/xheader.c index 311e775..42656bf 100644 --- a/src/xheader.c +++ b/src/xheader.c @@ -26,6 +26,7 @@ #include "common.h" +static void xheader_init (struct xheader *xhdr); static bool xheader_protected_pattern_p (char const *pattern); static bool xheader_protected_keyword_p (char const *keyword); static void xheader_set_single_keyword (char *) __attribute__ ((noreturn)); @@ -661,7 +662,7 @@ xheader_decode_global (struct xheader *xhdr) } } -void +static void xheader_init (struct xheader *xhdr) { if (!xhdr->stk) -- 2.45.2