]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/fileutils: add mkdir_p() from libmount
authorKarel Zak <kzak@redhat.com>
Mon, 9 Jun 2014 08:59:18 +0000 (10:59 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 9 Jun 2014 08:59:18 +0000 (10:59 +0200)
disk-utils/fsck.c
include/fileutils.h
lib/fileutils.c
libmount/src/context.c
libmount/src/utils.c

index caeb6381c25f4824ae57588a9c8dec8907f37894..7c7043ac16c8807b8f36e246f1a8edded6cdd549 100644 (file)
@@ -19,7 +19,7 @@
  * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
  *              2001, 2002, 2003, 2004, 2005 by  Theodore Ts'o.
  *
- * Copyright (C) 2009, 2012 Karel Zak <kzak@redhat.com>
+ * Copyright (C) 2009-2014 Karel Zak <kzak@redhat.com>
  *
  * This file may be redistributed under the terms of the GNU Public
  * License.
index d0d4505cdbf0db7e858c8dd91e9302810150c5cb..99a71edbcd45fcfc7db5eacf2732bfe8f575a9f6 100644 (file)
@@ -20,4 +20,6 @@ static inline FILE *xfmkstemp(char **tmpname, char *dir)
 
 extern int get_fd_tabsize(void);
 
+extern int mkdir_p(const char *path, mode_t mode);
+
 #endif /* UTIL_LINUX_FILEUTILS */
index 92b474cef4a159dbb6013bf61045a4817c676c47..3d45531792e158e915e1d46a1b537c8b262c583f 100644 (file)
@@ -81,3 +81,39 @@ int main(void)
        return EXIT_FAILURE;
 }
 #endif
+
+
+int mkdir_p(const char *path, mode_t mode)
+{
+       char *p, *dir;
+       int rc = 0;
+
+       if (!path || !*path)
+               return -EINVAL;
+
+       dir = p = strdup(path);
+       if (!dir)
+               return -ENOMEM;
+
+       if (*p == '/')
+               p++;
+
+       while (p && *p) {
+               char *e = strchr(p, '/');
+               if (e)
+                       *e = '\0';
+               if (*p) {
+                       rc = mkdir(dir, mode);
+                       if (rc && errno != EEXIST)
+                               break;
+                       rc = 0;
+               }
+               if (!e)
+                       break;
+               *e = '/';
+               p = e + 1;
+       }
+
+       free(dir);
+       return rc;
+}
index b7278a42dde2828498b07a5e131d21578e541973..1a04c1a29ee8a6c63923389e4bfe02c4dbafd844 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include "mountP.h"
+#include "fileutils.h"
 
 #include <sys/wait.h>
 
index d82920905e9c6f517ce4f872414d227bda4b4a92..7700d805a5e662b805b6ec1867a8f2f79a9d8a3f 100644 (file)
@@ -23,6 +23,7 @@
 #include "canonicalize.h"
 #include "env.h"
 #include "match.h"
+#include "fileutils.h"
 #include "statfs_magic.h"
 
 int append_string(char **a, const char *b)
@@ -1110,43 +1111,6 @@ char *mnt_get_kernel_cmdline_option(const char *name)
        return res;
 }
 
-int mkdir_p(const char *path, mode_t mode)
-{
-       char *p, *dir;
-       int rc = 0;
-
-       if (!path || !*path)
-               return -EINVAL;
-
-       dir = p = strdup(path);
-       if (!dir)
-               return -ENOMEM;
-
-       if (*p == '/')
-               p++;
-
-       while (p && *p) {
-               char *e = strchr(p, '/');
-               if (e)
-                       *e = '\0';
-               if (*p) {
-                       rc = mkdir(dir, mode);
-                       if (rc && errno != EEXIST)
-                               break;
-                       rc = 0;
-               }
-               if (!e)
-                       break;
-               *e = '/';
-               p = e + 1;
-       }
-
-       DBG(UTILS, ul_debug("%s mkdir %s", path, rc ? "FAILED" : "SUCCESS"));
-
-       free(dir);
-       return rc;
-}
-
 #ifdef TEST_PROGRAM
 int test_match_fstype(struct libmnt_test *ts, int argc, char *argv[])
 {