mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-05 11:07:59 +02:00
add untested recursive mkdir function (ply_create_directory)
This commit is contained in:
parent
193cfa0525
commit
37eb87df07
2 changed files with 43 additions and 0 deletions
|
|
@ -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: */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue