]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
add untested recursive mkdir function (ply_create_directory)
authorRay Strode <rstrode@redhat.com>
Sun, 10 Jun 2007 23:12:41 +0000 (19:12 -0400)
committerRay Strode <rstrode@redhat.com>
Sun, 10 Jun 2007 23:12:41 +0000 (19:12 -0400)
src/libply/ply-utils.c
src/libply/ply-utils.h

index 4f5821fcf0a02fd2a1e0ac76b87a7d198359bf27..be40d6cda8508bf01ec1243a3749af83754829c2 100644 (file)
@@ -626,4 +626,45 @@ ply_close_module (ply_module_handle_t *handle)
 {
   dlclose (handle);
 }
+
+bool
+ply_create_directory (const char *directory)
+{
+  assert (directory != NULL);
+  assert (directory[0] != '\0');
+
+  if (ply_directory_exists (directory))
+    return true;
+
+  if (ply_file_exists (directory))
+    {
+      errno = EEXIST;
+      return false;
+    }
+
+  if (mkdir (directory, 0755) < 0)
+    {
+      char *parent_directory;
+      char *last_path_component;
+      bool parent_is_created;
+
+      parent_is_created = false;
+      if (errno == ENOENT)
+        {
+          parent_directory = strdup (directory);
+          last_path_component = strrchr (parent_directory, '/');
+          *last_path_component = '\0';
+          parent_is_created = ply_create_directory (parent_directory);
+
+          ply_save_errno ();
+          free (parent_directory);
+          ply_restore_errno ();
+        }
+
+      return parent_is_created;
+    }
+
+
+  return true;
+}
 /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
index 6a59deb7f48bef708b7951088260700dd857c3f8..eda9fef28610d42835485401e761c8b1e4856ddb 100644 (file)
@@ -77,6 +77,8 @@ ply_module_function_t ply_module_look_up_function (ply_module_handle_t *handle,
                                                    const char  *function_name);
 void ply_close_module (ply_module_handle_t *handle);
 
+bool ply_create_directory (const char *directory);
+
 #endif
 
 #endif /* PLY_UTILS_H */