summaryrefslogtreecommitdiff
path: root/mkfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-18 08:53:27 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-11-18 09:15:47 +0100
commitbca4dfec757a0c3c62551427268c65de06107db4 (patch)
tree9272e4c42ddd94aebbb075115832875876959bd5 /mkfs
parent84210b0ba9f2d2208981fb71967bdcf6001f44b2 (diff)
Remove pushd/popd usage from gensquashfs packing code
We don't do any directory operations aftwerwards, so we can just chdir into the input directory. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/mkfs.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index b000652..2e89813 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -9,22 +9,33 @@
static int set_working_dir(options_t *opt)
{
const char *ptr;
+ char *path;
- if (opt->packdir != NULL)
- return pushd(opt->packdir);
+ if (opt->packdir != NULL) {
+ if (chdir(opt->packdir)) {
+ perror(opt->packdir);
+ return -1;
+ }
+ return 0;
+ }
ptr = strrchr(opt->infile, '/');
- if (ptr != NULL)
- return pushdn(opt->infile, ptr - opt->infile);
+ if (ptr == NULL)
+ return 0;
- return 0;
-}
+ path = strndup(opt->infile, ptr - opt->infile);
+ if (path == NULL) {
+ perror("constructing input directory path");
+ return -1;
+ }
-static int restore_working_dir(options_t *opt)
-{
- if (opt->packdir != NULL || strrchr(opt->infile, '/') != NULL)
- return popd();
+ if (chdir(path)) {
+ perror(path);
+ free(path);
+ return -1;
+ }
+ free(path);
return 0;
}
@@ -84,7 +95,7 @@ static int pack_files(sqfs_data_writer_t *data, fstree_t *fs,
stats->bytes_read += filesize;
}
- return restore_working_dir(opt);
+ return 0;
}
static int relabel_tree_dfs(const char *filename, sqfs_xattr_writer_t *xwr,