aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-04-08 22:12:08 -0500
committerRob Landley <rob@landley.net>2018-04-08 22:12:08 -0500
commit221439164eb6683a5af35540b24b5620e5d8ab19 (patch)
tree5460bd0d03042863cb6b3ddf12a9473c84da8689 /lib
parentcd3f81ebe5c82f1fd5f610b0f2e0fa07ac27903e (diff)
downloadtoybox-221439164eb6683a5af35540b24b5620e5d8ab19.tar.gz
Add mkpath() for common case of mkpathat(), and #define magic constants.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c6
-rw-r--r--lib/lib.h4
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index ea678011..27d14be7 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -204,6 +204,12 @@ int mkpathat(int atfd, char *dir, mode_t lastmode, int flags)
return 0;
}
+// The common case
+int mkpath(char *dir)
+{
+ return mkpathat(AT_FDCWD, dir, 0, MKPATHAT_MAKE);
+}
+
// Split a path into linked list of components, tracking head and tail of list.
// Filters out // entries with no contents.
struct string_list **splitpath(char *path, struct string_list **list)
diff --git a/lib/lib.h b/lib/lib.h
index 676c47b3..ccf342cc 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -191,7 +191,11 @@ void perror_exit_raw(char *msg);
ssize_t readall(int fd, void *buf, size_t len);
ssize_t writeall(int fd, void *buf, size_t len);
off_t lskip(int fd, off_t offset);
+#define MKPATHAT_MKLAST 1
+#define MKPATHAT_MAKE 2
+#define MKPATHAT_VERBOSE 4
int mkpathat(int atfd, char *dir, mode_t lastmode, int flags);
+int mkpath(char *dir);
struct string_list **splitpath(char *path, struct string_list **list);
char *readfileat(int dirfd, char *name, char *buf, off_t *len);
char *readfile(char *name, char *buf, off_t len);