From: Ray Strode Date: Sun, 10 Jun 2007 23:12:41 +0000 (-0400) Subject: add untested recursive mkdir function (ply_create_directory) X-Git-Tag: 0.1.0~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37eb87df07b30a8a2fd295a21b073483214ba48d;p=thirdparty%2Fplymouth.git add untested recursive mkdir function (ply_create_directory) --- diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 4f5821fc..be40d6cd 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 6a59deb7..eda9fef2 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 */