diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/conf-files.c | 2 | ||||
-rw-r--r-- | src/shared/conf-files.h | 2 | ||||
-rw-r--r-- | src/shared/util.c | 19 | ||||
-rw-r--r-- | src/shared/util.h | 1 |
4 files changed, 22 insertions, 2 deletions
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c index 296e605761..6d99739353 100644 --- a/src/shared/conf-files.c +++ b/src/shared/conf-files.c @@ -134,7 +134,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const return 0; } -int conf_files_list_strv(char ***strv, const char *suffix, const char *root, const char **dirs) { +int conf_files_list_strv(char ***strv, const char *suffix, const char *root, const char* const* dirs) { _cleanup_strv_free_ char **copy = NULL; assert(strv); diff --git a/src/shared/conf-files.h b/src/shared/conf-files.h index 28588e6f03..3bd3d2f3d4 100644 --- a/src/shared/conf-files.h +++ b/src/shared/conf-files.h @@ -26,7 +26,7 @@ #include "macro.h" int conf_files_list(char ***strv, const char *suffix, const char *root, const char *dir, ...); -int conf_files_list_strv(char ***strv, const char *suffix, const char *root, const char **dirs); +int conf_files_list_strv(char ***strv, const char *suffix, const char *root, const char* const* dirs); int conf_files_list_nulstr(char ***strv, const char *suffix, const char *root, const char *dirs); #endif diff --git a/src/shared/util.c b/src/shared/util.c index 8fa01fa8a4..2241b79859 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -59,6 +59,7 @@ #include <limits.h> #include <langinfo.h> #include <locale.h> +#include <libgen.h> #include "macro.h" #include "util.h" @@ -2356,6 +2357,24 @@ int dir_is_empty(const char *path) { } } +char* dirname_malloc(const char *path) { + char *d, *dir, *dir2; + + d = strdup(path); + if (!d) + return NULL; + dir = dirname(d); + assert(dir); + + if (dir != d) { + dir2 = strdup(dir); + free(d); + return dir2; + } + + return dir; +} + unsigned long long random_ull(void) { _cleanup_close_ int fd; uint64_t ull; diff --git a/src/shared/util.h b/src/shared/util.h index 52c33238b1..aefde5f85a 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -329,6 +329,7 @@ ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll); bool is_device_path(const char *path); int dir_is_empty(const char *path); +char* dirname_malloc(const char *path); void rename_process(const char name[8]); |