commit:     296dea574aff001ae7baa86be0ec902609558867
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 22 08:56:26 2015 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Feb 22 08:56:26 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=296dea57

mkdir: add a mkdir_p_at helper

---
 libq/xmkdir.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libq/xmkdir.c b/libq/xmkdir.c
index 600e6d0..cc428aa 100644
--- a/libq/xmkdir.c
+++ b/libq/xmkdir.c
@@ -1,11 +1,11 @@
 /* Emulate `mkdir -p -m MODE PATH` */
-static int mkdir_p(const char *path, mode_t mode)
+static int mkdir_p_at(int dfd, const char *path, mode_t mode)
 {
        char *_p, *p, *s;
 
        /* Assume that most of the time, only the last element
         * is missing.  So if we can mkdir it right away, bail. */
-       if (mkdir(path, mode) == 0 || errno == EEXIST)
+       if (mkdirat(dfd, path, mode) == 0 || errno == EEXIST)
                return 0;
 
        /* Build up the whole tree */
@@ -19,13 +19,13 @@ static int mkdir_p(const char *path, mode_t mode)
                /* Find the next path element */
                s = strchr(p, '/');
                if (!s) {
-                       mkdir(_p, mode);
+                       mkdirat(dfd, _p, mode);
                        break;
                }
 
                /* Make it */
                *s = '\0';
-               mkdir(_p, mode);
+               mkdirat(dfd, _p, mode);
                *s = '/';
 
                p = s;
@@ -35,6 +35,10 @@ static int mkdir_p(const char *path, mode_t mode)
 
        return 0;
 }
+static int mkdir_p(const char *path, mode_t mode)
+{
+       return mkdir_p_at(AT_FDCWD, path, mode);
+}
 
 /* Emulate `rm -rf PATH` */
 _q_static int rm_rf_at(int dfd, const char *path)

Reply via email to