summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/fs.c30
-rw-r--r--include/unistd.h2
2 files changed, 32 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;
diff --git a/include/unistd.h b/include/unistd.h
index 06ce355809..f7fe737d00 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -20,6 +20,8 @@ int rmdir (const char *pathname);
int symlink(const char *pathname, const char *newpath);
int readlink(const char *path, char *buf, size_t bufsiz);
int chdir(const char *pathname);
+char *pushd(const char *dir);
+int popd(char *dir);
const char *getcwd(void);
int ftruncate(int fd, loff_t length);