[PATCH v6 4/7] libbb: xfchdir(): new function
Bartosz Golaszewski
bartekgola at gmail.com
Thu Mar 17 14:52:26 UTC 2016
Add a new xfunction that prints an error message and exits if the
underlying fchdir() fails.
Signed-off-by: Bartosz Golaszewski <bartekgola at gmail.com>
---
include/libbb.h | 1 +
libbb/xfuncs_printf.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/include/libbb.h b/include/libbb.h
index 0713917..3477525 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -503,6 +503,7 @@ void xsetuid(uid_t uid) FAST_FUNC;
void xsetegid(gid_t egid) FAST_FUNC;
void xseteuid(uid_t euid) FAST_FUNC;
void xchdir(const char *path) FAST_FUNC;
+void xfchdir(int fd) FAST_FUNC;
void xchroot(const char *path) FAST_FUNC;
void xsetenv(const char *key, const char *value) FAST_FUNC;
void bb_unsetenv(const char *key) FAST_FUNC;
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index 7348890..1aa3874 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -390,6 +390,12 @@ void FAST_FUNC xchdir(const char *path)
bb_perror_msg_and_die("can't change directory to '%s'", path);
}
+void FAST_FUNC xfchdir(int fd)
+{
+ if (fchdir(fd))
+ bb_perror_msg_and_die("can't change directory by descriptor");
+}
+
void FAST_FUNC xchroot(const char *path)
{
if (chroot(path))
--
2.1.4
More information about the busybox
mailing list