aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-11-03 16:59:56 +0200
committerSergey Poznyakoff <gray@gnu.org>2019-11-03 17:07:39 +0200
commit3177d660a4c62a6acb538b0f7c54ba423698889a (patch)
treeca4dee3715063ecc96140db2a5c3ed3895c7ce51 /src/util.c
parent38290e9dde947f2d46e06e594d7d81644f423cd7 (diff)
downloadcpio-3177d660a4c62a6acb538b0f7c54ba423698889a.tar.gz
cpio-3177d660a4c62a6acb538b0f7c54ba423698889a.tar.bz2
Provide functions for struct cpio_file_stat management.
* src/copyin.c (long_format): Mark unchangeable argument as const. (read_name_from_file): Use cpio_realloc_c_name. (process_copy_in): Use CPIO_FILE_STAT_INITIALIZER. Call cpio_file_stat_free before return. * src/copyout.c (process_copy_out): Likewise. * src/copypass.c (link_to_name): Mark unchangeable argument as const. * src/cpiohdr.h (cpio_file_stat) <c_name_buflen>: New member, <c_tar_linkname>: Mark as const. (CPIO_FILE_STAT_INITIALIZER): New define. (cpio_file_stat_init,cpio_file_stat_free) (cpio_realloc_c_name): New protos. * src/extern.h: Fix prototypes. * src/makepath.c (make_path): Mark unchangeable argument as const. * src/util.c (create_all_directories): Mark unchangeable argument as const. (cpio_realloc_c_name): New function. (cpio_set_c_name): Use cpio_realloc_c_name. (cpio_file_stat_init,cpio_file_stat_free): New functions.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/util.c b/src/util.c
index 0e40134..4421b20 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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);
+}

Return to:

Send suggestions and report system problems to the System administrator.