diff options
-rw-r--r-- | src/copyin.c | 25 | ||||
-rw-r--r-- | src/copyout.c | 4 | ||||
-rw-r--r-- | src/copypass.c | 2 | ||||
-rw-r--r-- | src/cpiohdr.h | 8 | ||||
-rw-r--r-- | src/extern.h | 8 | ||||
-rw-r--r-- | src/makepath.c | 2 | ||||
-rw-r--r-- | src/util.c | 27 |
7 files changed, 46 insertions, 30 deletions
diff --git a/src/copyin.c b/src/copyin.c index a01873d..63541eb 100644 --- a/src/copyin.c +++ b/src/copyin.c @@ -725,7 +725,7 @@ static time_t current_time; this file is a symbolic link to. */ void -long_format (struct cpio_file_stat *file_hdr, char *link_name) +long_format (struct cpio_file_stat *file_hdr, char const *link_name) { char mbuf[11]; char tbuf[40]; @@ -993,17 +993,9 @@ read_in_header (struct cpio_file_stat *file_hdr, int in_des) static void read_name_from_file (struct cpio_file_stat *file_hdr, int fd, uintmax_t len) { - static char *tmp_filename; - static size_t buflen; - - if (buflen < len) - { - buflen = len; - tmp_filename = xrealloc (tmp_filename, buflen); - } - - tape_buffered_read (tmp_filename, fd, len); - cpio_set_c_name (file_hdr, tmp_filename); + cpio_realloc_c_name (file_hdr, len); + tape_buffered_read (file_hdr->c_name, fd, len); + file_hdr->c_namesize = len; } /* Fill in FILE_HDR by reading an old-format ASCII format cpio header from @@ -1206,7 +1198,8 @@ process_copy_in () FILE *tty_out = NULL; /* Interactive file for rename option. */ FILE *rename_in = NULL; /* Batch file for rename option. */ struct stat file_stat; /* Output file stat record. */ - struct cpio_file_stat file_hdr; /* Output header information. */ + struct cpio_file_stat file_hdr = CPIO_FILE_STAT_INITIALIZER; + /* Output header information. */ int in_file_des; /* Input file descriptor. */ char skip_file; /* Flag for use with patterns. */ int i; /* Loop index variable. */ @@ -1219,9 +1212,7 @@ process_copy_in () { read_pattern_file (); } - file_hdr.c_name = NULL; - file_hdr.c_namesize = 0; - + if (rename_batch_file) { rename_in = fopen (rename_batch_file, "r"); @@ -1421,6 +1412,8 @@ process_copy_in () fputc ('\n', stderr); apply_delayed_set_stat (); + + cpio_file_stat_free (&file_hdr); if (append_flag) return; diff --git a/src/copyout.c b/src/copyout.c index 71abc4d..d00816e 100644 --- a/src/copyout.c +++ b/src/copyout.c @@ -587,7 +587,8 @@ process_copy_out () { dynamic_string input_name; /* Name of file read from stdin. */ struct stat file_stat; /* Stat record for file. */ - struct cpio_file_stat file_hdr; /* Output header information. */ + struct cpio_file_stat file_hdr = CPIO_FILE_STAT_INITIALIZER; + /* Output header information. */ int in_file_des; /* Source file descriptor. */ int out_file_des; /* Output file descriptor. */ char *orig_file_name = NULL; @@ -862,6 +863,7 @@ process_copy_out () ngettext ("%lu block\n", "%lu blocks\n", (unsigned long) blocks), (unsigned long) blocks); } + cpio_file_stat_free (&file_hdr); } diff --git a/src/copypass.c b/src/copypass.c index 26b453b..dc13b5b 100644 --- a/src/copypass.c +++ b/src/copypass.c @@ -372,7 +372,7 @@ link_to_maj_min_ino (char *file_name, int st_dev_maj, int st_dev_min, is created, -1 otherwise. */ int -link_to_name (char *link_name, char *link_target) +link_to_name (char const *link_name, char const *link_target) { int res = link (link_target, link_name); if (res < 0 && create_dir_flag) diff --git a/src/cpiohdr.h b/src/cpiohdr.h index 588135b..ff5f375 100644 --- a/src/cpiohdr.h +++ b/src/cpiohdr.h @@ -126,9 +126,15 @@ struct cpio_file_stat /* Internal representation of a CPIO header */ size_t c_namesize; uint32_t c_chksum; char *c_name; - char *c_tar_linkname; + size_t c_name_buflen; + char const *c_tar_linkname; }; +#define CPIO_FILE_STAT_INITIALIZER \ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 0, NULL } +void cpio_file_stat_init (struct cpio_file_stat *file_hdr); +void cpio_file_stat_free (struct cpio_file_stat *file_hdr); void cpio_set_c_name(struct cpio_file_stat *file_hdr, char *name); +void cpio_realloc_c_name (struct cpio_file_stat *file_hdr, size_t len); #endif /* cpiohdr.h */ diff --git a/src/extern.h b/src/extern.h index 6fa2089..8611c05 100644 --- a/src/extern.h +++ b/src/extern.h @@ -111,7 +111,7 @@ void read_in_binary (struct cpio_file_stat *file_hdr, struct old_cpio_header *short_hdr, int in_des); void swab_array (char *arg, int count); void process_copy_in (void); -void long_format (struct cpio_file_stat *file_hdr, char *link_name); +void long_format (struct cpio_file_stat *file_hdr, char const *link_name); /* copyout.c */ int write_out_header (struct cpio_file_stat *file_hdr, int out_des); @@ -121,7 +121,7 @@ void process_copy_out (void); void process_copy_pass (void); int link_to_maj_min_ino (char *file_name, int st_dev_maj, int st_dev_min, ino_t st_ino); -int link_to_name (char *link_name, char *link_target); +int link_to_name (char const *link_name, char const *link_target); /* dirname.c */ char *dirname (char *path); @@ -140,7 +140,7 @@ void process_args (int argc, char *argv[]); void initialize_buffers (void); /* makepath.c */ -int make_path (char *argpath, uid_t owner, gid_t group, +int make_path (char const *argpath, uid_t owner, gid_t group, const char *verbose_fmt_string); /* tar.c */ @@ -168,7 +168,7 @@ void copy_files_disk_to_tape (int in_des, int out_des, off_t num_bytes, char *fi void copy_files_disk_to_disk (int in_des, int out_des, off_t num_bytes, char *filename); void warn_if_file_changed (char *file_name, off_t old_file_size, time_t old_file_mtime); -void create_all_directories (char *name); +void create_all_directories (char const *name); void prepare_append (int out_file_des); char *find_inode_file (ino_t node_num, unsigned long major_num, unsigned long minor_num); diff --git a/src/makepath.c b/src/makepath.c index 0e2184c..f937166 100644 --- a/src/makepath.c +++ b/src/makepath.c @@ -49,7 +49,7 @@ ownership and permissions when done, otherwise 1. */ int -make_path (char *argpath, +make_path (char const *argpath, uid_t owner, gid_t group, const char *verbose_fmt_string) @@ -598,7 +598,7 @@ warn_if_file_changed (char *file_name, off_t old_file_size, Do not destroy any nondirectories while creating directories. */ void -create_all_directories (char *name) +create_all_directories (char const *name) { char *dir; @@ -1251,17 +1251,20 @@ set_file_times (int fd, utime_error (name); } +/* Reallocate file_hdr->c_name to accomodate len bytes (including final \0) */ +void +cpio_realloc_c_name (struct cpio_file_stat *file_hdr, size_t len) +{ + while (file_hdr->c_name_buflen < len) + file_hdr->c_name = x2realloc (file_hdr->c_name, &file_hdr->c_name_buflen); +} void cpio_set_c_name (struct cpio_file_stat *file_hdr, char *name) { - static char *buf = NULL; - static size_t buflen = 0; size_t len = strlen (name) + 1; - while (buflen < len) - buf = x2realloc (buf, &buflen); - file_hdr->c_name = buf; + cpio_realloc_c_name (file_hdr, len); file_hdr->c_namesize = len; memmove (file_hdr->c_name, name, len); } @@ -1528,3 +1531,15 @@ arf_stores_inode_p (enum archive_format arf) return 1; } +void +cpio_file_stat_init (struct cpio_file_stat *file_hdr) +{ + memset (file_hdr, 0, sizeof (*file_hdr)); +} + +void +cpio_file_stat_free (struct cpio_file_stat *file_hdr) +{ + free (file_hdr->c_name); + cpio_file_stat_init (file_hdr); +} |