summaryrefslogtreecommitdiff
path: root/cpio
diff options
context:
space:
mode:
authorMartin Matuska <martin@matuska.org>2020-03-02 00:48:47 +0100
committerMartin Matuska <martin@matuska.org>2020-03-02 00:48:47 +0100
commitba0478d30ef0932316e62480e5c338ae14168157 (patch)
treef95c878c1fde20aefa0e480bc1bd8ba4f6e98ee7 /cpio
parentde0d217aa3ff615f26f1895b298ff6e64e89ceb2 (diff)
downloadlibarchive-ba0478d30ef0932316e62480e5c338ae14168157.tar.gz
cpio/cpio.c: avoid calling strlen() for destdir twice
Diffstat (limited to 'cpio')
-rw-r--r--cpio/cpio.c15
-rw-r--r--cpio/cpio.h1
2 files changed, 8 insertions, 8 deletions
diff --git a/cpio/cpio.c b/cpio/cpio.c
index da5c3986..c9ffe76b 100644
--- a/cpio/cpio.c
+++ b/cpio/cpio.c
@@ -737,7 +737,7 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
*/
destpath = srcpath;
if (cpio->destdir) {
- len = strlen(cpio->destdir) + strlen(srcpath) + 8;
+ len = cpio->destdir_len + strlen(srcpath) + 8;
if (len >= cpio->pass_destpath_alloc) {
while (len >= cpio->pass_destpath_alloc) {
cpio->pass_destpath_alloc += 512;
@@ -1228,15 +1228,14 @@ mode_pass(struct cpio *cpio, const char *destdir)
struct lafe_line_reader *lr;
const char *p;
int r;
- size_t destdir_len;
/* Ensure target dir has a trailing '/' to simplify path surgery. */
- destdir_len = strlen(destdir);
- cpio->destdir = malloc(destdir_len + 8);
- memcpy(cpio->destdir, destdir, destdir_len);
- if (destdir_len == 0 || destdir[destdir_len - 1] != '/')
- cpio->destdir[destdir_len++] = '/';
- cpio->destdir[destdir_len++] = '\0';
+ cpio->destdir_len = strlen(destdir);
+ cpio->destdir = malloc(cpio->destdir_len + 8);
+ memcpy(cpio->destdir, destdir, cpio->destdir_len);
+ if (cpio->destdir_len == 0 || destdir[cpio->destdir_len - 1] != '/')
+ cpio->destdir[cpio->destdir_len++] = '/';
+ cpio->destdir[cpio->destdir_len + 1] = '\0';
cpio->archive = archive_write_disk_new();
if (cpio->archive == NULL)
diff --git a/cpio/cpio.h b/cpio/cpio.h
index abf3628b..8e7cc5fd 100644
--- a/cpio/cpio.h
+++ b/cpio/cpio.h
@@ -64,6 +64,7 @@ struct cpio {
int option_numeric_uid_gid; /* -n */
int option_rename; /* -r */
char *destdir;
+ size_t destdir_len;
size_t pass_destpath_alloc;
char *pass_destpath;
int uid_override;