path-util: Reduce transitive includes

This commit is contained in:
Daan De Meyer
2025-05-07 22:04:46 +09:00
committed by Yu Watanabe
parent fda652117e
commit d9ccf6b349
48 changed files with 90 additions and 31 deletions
+2
View File
@@ -3,11 +3,13 @@
#include <linux/btrfs.h>
#include <sys/ioctl.h>
#include "alloc-util.h"
#include "btrfs.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "path-util.h"
#include "string-util.h"
int btrfs_validate_subvolume_name(const char *name) {
+1
View File
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
#include "capsule-util.h"
#include "path-util.h"
#include "user-util.h"
+1
View File
@@ -12,6 +12,7 @@
#include "log.h"
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
#include "user-util.h"
bool unsafe_transition(const struct stat *a, const struct stat *b) {
+1
View File
@@ -3,6 +3,7 @@
#include <string.h>
#include <sys/stat.h>
#include "alloc-util.h"
#include "chase.h"
#include "devnum-util.h"
#include "parse-util.h"
+1
View File
@@ -29,6 +29,7 @@
#include "socket-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
#include "sync-util.h"
#include "terminal-util.h"
#include "tmpfile-util.h"
+31
View File
@@ -22,6 +22,13 @@
#include "strv.h"
#include "time-util.h"
bool is_path(const char *p) {
if (!p) /* A NULL pointer is definitely not a path */
return false;
return strchr(p, '/');
}
int path_split_and_make_absolute(const char *p, char ***ret) {
_cleanup_strv_free_ char **l = NULL;
int r;
@@ -345,6 +352,10 @@ char** path_strv_resolve_uniq(char **l, const char *root) {
return strv_uniq(l);
}
char* skip_leading_slash(const char *p) {
return skip_leading_chars(p, "/");
}
char* path_simplify_full(char *path, PathSimplifyFlags flags) {
bool add_slash = false, keep_trailing_slash, absolute, beginning = true;
char *f = path;
@@ -406,6 +417,22 @@ char* path_simplify_full(char *path, PathSimplifyFlags flags) {
return path;
}
int path_simplify_alloc(const char *path, char **ret) {
assert(ret);
if (!path) {
*ret = NULL;
return 0;
}
char *t = strdup(path);
if (!t)
return -ENOMEM;
*ret = path_simplify(t);
return 0;
}
char* path_startswith_full(const char *path, const char *prefix, bool accept_dot_dot) {
assert(path);
assert(prefix);
@@ -1361,6 +1388,10 @@ bool empty_or_root(const char *path) {
return path_equal(path, "/");
}
const char* empty_to_root(const char *path) {
return isempty(path) ? "/" : path;
}
bool path_strv_contains(char * const *l, const char *path) {
assert(path);
+4 -31
View File
@@ -1,14 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <alloca.h>
#include <stdbool.h>
#include <stddef.h>
#include "macro.h"
#include "stat-util.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
#define PATH_SPLIT_BIN(x) x "sbin:" x "bin"
@@ -32,12 +28,7 @@ static inline const char* default_user_PATH(void) {
#endif
}
static inline bool is_path(const char *p) {
if (!p) /* A NULL pointer is definitely not a path */
return false;
return strchr(p, '/');
}
bool is_path(const char *p) _pure_;
static inline bool path_is_absolute(const char *p) {
if (!p) /* A NULL pointer is definitely not an absolute path */
@@ -76,9 +67,7 @@ char* path_extend_internal(char **x, ...);
#define path_extend(x, ...) path_extend_internal(x, __VA_ARGS__, POINTER_MAX)
#define path_join(...) path_extend_internal(NULL, __VA_ARGS__, POINTER_MAX)
static inline char* skip_leading_slash(const char *p) {
return skip_leading_chars(p, "/");
}
char* skip_leading_slash(const char *p) _pure_;
typedef enum PathSimplifyFlags {
PATH_SIMPLIFY_KEEP_TRAILING_SLASH = 1 << 0,
@@ -89,21 +78,7 @@ static inline char* path_simplify(char *path) {
return path_simplify_full(path, 0);
}
static inline int path_simplify_alloc(const char *path, char **ret) {
assert(ret);
if (!path) {
*ret = NULL;
return 0;
}
char *t = strdup(path);
if (!t)
return -ENOMEM;
*ret = path_simplify(t);
return 0;
}
int path_simplify_alloc(const char *path, char **ret);
/* Note: the search terminates on the first NULL item. */
#define PATH_IN_SET(p, ...) path_strv_contains(STRV_MAKE(__VA_ARGS__), p)
@@ -195,9 +170,7 @@ static inline const char* skip_dev_prefix(const char *p) {
}
bool empty_or_root(const char *path);
static inline const char* empty_to_root(const char *path) {
return isempty(path) ? "/" : path;
}
const char* empty_to_root(const char *path) _pure_;
bool path_strv_contains(char * const *l, const char *path);
bool prefixed_path_strv_contains(char * const *l, const char *path);
+2
View File
@@ -3,11 +3,13 @@
#include <fcntl.h>
#include <sys/stat.h>
#include "alloc-util.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fs-util.h"
#include "log.h"
#include "path-util.h"
#include "string-util.h"
#include "sync-util.h"
int fsync_directory_of_file(int fd) {
+1
View File
@@ -6,6 +6,7 @@
#include <unistd.h>
#include "af-list.h"
#include "alloc-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "log.h"
+1
View File
@@ -9,6 +9,7 @@
#include "alloc-util.h"
#include "glob-util.h"
#include "hash-funcs.h"
#include "hexdecoct.h"
#include "log.h"
#include "memory-util.h"
+1
View File
@@ -13,6 +13,7 @@
#include "dirent-util.h"
#include "env-util.h"
#include "errno-util.h"
#include "extract-word.h"
#include "fd-util.h"
#include "fileio.h"
#include "log.h"