summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2007-06-10 19:12:41 -0400
committerRay Strode <rstrode@redhat.com>2007-06-10 19:12:41 -0400
commit37eb87df07b30a8a2fd295a21b073483214ba48d (patch)
tree99d0ebe3db196254f37d54ac341605922f6cbf6b /src
parent193cfa0525e0f3bf2902c7ab417beb09cf8bfea1 (diff)
downloadplymouth-37eb87df07b30a8a2fd295a21b073483214ba48d.tar.gz
plymouth-37eb87df07b30a8a2fd295a21b073483214ba48d.tar.xz
plymouth-37eb87df07b30a8a2fd295a21b073483214ba48d.zip
add untested recursive mkdir function (ply_create_directory)
Diffstat (limited to 'src')
-rw-r--r--src/libply/ply-utils.c41
-rw-r--r--src/libply/ply-utils.h2
2 files changed, 43 insertions, 0 deletions
diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c
index 4f5821f..be40d6c 100644
--- a/src/libply/ply-utils.c
+++ b/src/libply/ply-utils.c
@@ -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: */
diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h
index 6a59deb..eda9fef 100644
--- a/src/libply/ply-utils.h
+++ b/src/libply/ply-utils.h
@@ -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 */