]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - include/path.h
2 * No copyright is claimed. This code is in the public domain; do with
5 #ifndef UTIL_LINUX_PATH_H
6 #define UTIL_LINUX_PATH_H
11 #include <sys/types.h>
23 char path_buffer
[PATH_MAX
];
26 void (*free_dialect
)(struct path_cxt
*);
27 int (*redirect_on_enoent
)(struct path_cxt
*, const char *, int *);
30 struct path_cxt
*ul_new_path(const char *dir
, ...)
31 __attribute__ ((__format__ (__printf__
, 1, 2)));
32 void ul_unref_path(struct path_cxt
*pc
);
33 void ul_ref_path(struct path_cxt
*pc
);
35 void ul_path_init_debug(void);
37 int ul_path_set_prefix(struct path_cxt
*pc
, const char *prefix
);
38 const char *ul_path_get_prefix(struct path_cxt
*pc
);
40 int ul_path_set_dir(struct path_cxt
*pc
, const char *dir
);
41 const char *ul_path_get_dir(struct path_cxt
*pc
);
43 int ul_path_set_dialect(struct path_cxt
*pc
, void *data
, void free_data(struct path_cxt
*));
44 void *ul_path_get_dialect(struct path_cxt
*pc
);
46 int ul_path_set_enoent_redirect(struct path_cxt
*pc
, int (*func
)(struct path_cxt
*, const char *, int *));
47 int ul_path_get_dirfd(struct path_cxt
*pc
);
48 void ul_path_close_dirfd(struct path_cxt
*pc
);
49 int ul_path_isopen_dirfd(struct path_cxt
*pc
);
50 int ul_path_is_accessible(struct path_cxt
*pc
);
52 char *ul_path_get_abspath(struct path_cxt
*pc
, char *buf
, size_t bufsz
, const char *path
, ...)
53 __attribute__ ((__format__ (__printf__
, 4, 5)));
55 int ul_path_stat(struct path_cxt
*pc
, struct stat
*sb
, int flags
, const char *path
);
56 int ul_path_access(struct path_cxt
*pc
, int mode
, const char *path
);
57 int ul_path_accessf(struct path_cxt
*pc
, int mode
, const char *path
, ...)
58 __attribute__ ((__format__ (__printf__
, 3, 4)));
60 int ul_path_open(struct path_cxt
*pc
, int flags
, const char *path
);
61 int ul_path_openf(struct path_cxt
*pc
, int flags
, const char *path
, ...)
62 __attribute__ ((__format__ (__printf__
, 3, 4)));
63 int ul_path_vopenf(struct path_cxt
*pc
, int flags
, const char *path
, va_list ap
)
64 __attribute__ ((__format__ (__printf__
, 3, 0)));
66 FILE *ul_path_fopen(struct path_cxt
*pc
, const char *mode
, const char *path
);
67 FILE *ul_path_fopenf(struct path_cxt
*pc
, const char *mode
, const char *path
, ...)
68 __attribute__ ((__format__ (__printf__
, 3, 4)));
69 FILE *ul_path_vfopenf(struct path_cxt
*pc
, const char *mode
, const char *path
, va_list ap
)
70 __attribute__ ((__format__ (__printf__
, 3, 0)));
72 DIR *ul_path_opendir(struct path_cxt
*pc
, const char *path
);
73 DIR *ul_path_vopendirf(struct path_cxt
*pc
, const char *path
, va_list ap
)
74 __attribute__ ((__format__ (__printf__
, 2, 0)));
75 DIR *ul_path_opendirf(struct path_cxt
*pc
, const char *path
, ...)
76 __attribute__ ((__format__ (__printf__
, 2, 3)));
78 ssize_t
ul_path_readlink(struct path_cxt
*pc
, char *buf
, size_t bufsiz
, const char *path
);
79 ssize_t
ul_path_readlinkf(struct path_cxt
*pc
, char *buf
, size_t bufsiz
, const char *path
, ...)
80 __attribute__ ((__format__ (__printf__
, 4, 5)));
82 int ul_path_read(struct path_cxt
*pc
, char *buf
, size_t len
, const char *path
);
83 int ul_path_vreadf(struct path_cxt
*pc
, char *buf
, size_t len
, const char *path
, va_list ap
)
84 __attribute__ ((__format__ (__printf__
, 4, 0)));
85 int ul_path_readf(struct path_cxt
*pc
, char *buf
, size_t len
, const char *path
, ...)
86 __attribute__ ((__format__ (__printf__
, 4, 5)));
88 int ul_path_read_string(struct path_cxt
*pc
, char **str
, const char *path
);
89 int ul_path_readf_string(struct path_cxt
*pc
, char **str
, const char *path
, ...)
90 __attribute__ ((__format__ (__printf__
, 3, 4)));
92 int ul_path_read_buffer(struct path_cxt
*pc
, char *buf
, size_t bufsz
, const char *path
);
93 int ul_path_readf_buffer(struct path_cxt
*pc
, char *buf
, size_t bufsz
, const char *path
, ...)
94 __attribute__ ((__format__ (__printf__
, 4, 5)));
96 int ul_path_scanf(struct path_cxt
*pc
, const char *path
, const char *fmt
, ...)
97 __attribute__ ((__format__ (__scanf__
, 3, 4)));
98 int ul_path_scanff(struct path_cxt
*pc
, const char *path
, va_list ap
, const char *fmt
, ...)
99 __attribute__ ((__format__ (__printf__
, 2, 0)))
100 __attribute__ ((__format__ (__scanf__
, 4, 5)));
102 int ul_path_read_majmin(struct path_cxt
*pc
, dev_t
*res
, const char *path
);
103 int ul_path_readf_majmin(struct path_cxt
*pc
, dev_t
*res
, const char *path
, ...)
104 __attribute__ ((__format__ (__printf__
, 3, 4)));
106 int ul_path_read_u32(struct path_cxt
*pc
, uint32_t *res
, const char *path
);
107 int ul_path_readf_u32(struct path_cxt
*pc
, uint32_t *res
, const char *path
, ...)
108 __attribute__ ((__format__ (__printf__
, 3, 4)));
110 int ul_path_read_s32(struct path_cxt
*pc
, int32_t *res
, const char *path
);
111 int ul_path_readf_s32(struct path_cxt
*pc
, int32_t *res
, const char *path
, ...)
112 __attribute__ ((__format__ (__printf__
, 3, 4)));
114 int ul_path_read_u64(struct path_cxt
*pc
, uint64_t *res
, const char *path
);
115 int ul_path_readf_u64(struct path_cxt
*pc
, uint64_t *res
, const char *path
, ...)
116 __attribute__ ((__format__ (__printf__
, 3, 4)));
118 int ul_path_read_s64(struct path_cxt
*pc
, int64_t *res
, const char *path
);
119 int ul_path_readf_s64(struct path_cxt
*pc
, int64_t *res
, const char *path
, ...)
120 __attribute__ ((__format__ (__printf__
, 3, 4)));
122 int ul_path_write_string(struct path_cxt
*pc
, const char *str
, const char *path
);
123 int ul_path_writef_string(struct path_cxt
*pc
, const char *str
, const char *path
, ...)
124 __attribute__ ((__format__ (__printf__
, 3, 4)));
126 int ul_path_write_s64(struct path_cxt
*pc
, int64_t num
, const char *path
);
127 int ul_path_write_u64(struct path_cxt
*pc
, uint64_t num
, const char *path
);
128 int ul_path_writef_u64(struct path_cxt
*pc
, uint64_t num
, const char *path
, ...)
129 __attribute__ ((__format__ (__printf__
, 3, 4)));
131 int ul_path_count_dirents(struct path_cxt
*pc
, const char *path
);
132 int ul_path_countf_dirents(struct path_cxt
*pc
, const char *path
, ...)
133 __attribute__ ((__format__ (__printf__
, 2, 3)));
135 int ul_path_next_dirent(struct path_cxt
*pc
, DIR **sub
, const char *dirname
, struct dirent
**d
);
137 FILE *ul_prefix_fopen(const char *prefix
, const char *path
, const char *mode
);
140 #ifdef HAVE_CPU_SET_T
142 int ul_path_readf_cpuset(struct path_cxt
*pc
, cpu_set_t
**set
, int maxcpus
, const char *path
, ...)
143 __attribute__ ((__format__ (__printf__
, 4, 5)));
145 int ul_path_readf_cpulist(struct path_cxt
*pc
, cpu_set_t
**set
, int maxcpus
, const char *path
, ...)
146 __attribute__ ((__format__ (__printf__
, 4, 5)));
147 #endif /* HAVE_CPU_SET_T */
148 #endif /* UTIL_LINUX_PATH_H */