summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-01-08 18:15:54 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2022-01-12 11:29:16 +0100
commitec945f352178470d39aa0f7c407fc4ae859b34b0 (patch)
tree3b2606105b25494cb4b0f141afc1c5d474360ea8 /fs
parent818d180da1c709f3d2789925662222019b3cf439 (diff)
downloadbarebox-ec945f352178470d39aa0f7c407fc4ae859b34b0.tar.gz
barebox-ec945f352178470d39aa0f7c407fc4ae859b34b0.tar.xz
fs: implement pushd/popd chdir wrappers
We don't have dirfd's, so running operations relative to the current working directory always involves some allocation/freeing boilerplate. Add pushd/popd helpers to move the boilerplate out of the callsites. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220108171555.588426-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/fs.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 7da3a050c1..60fdb29078 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2846,6 +2846,36 @@ out:
}
EXPORT_SYMBOL(chdir);
+char *pushd(const char *dir)
+{
+ char *oldcwd;
+ int ret;
+
+ oldcwd = strdup(getcwd());
+ if (!oldcwd)
+ return NULL;
+
+ ret = chdir(dir);
+ if (ret) {
+ free(oldcwd);
+ return NULL;
+ }
+
+ return oldcwd;
+}
+
+int popd(char *oldcwd)
+{
+ int ret;
+
+ if (!oldcwd)
+ return 0;
+
+ ret = chdir(oldcwd);
+ free(oldcwd);
+ return ret;
+}
+
static char *get_linux_mmcblkdev(struct fs_device_d *fsdev)
{
struct cdev *cdevm, *cdev;