]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/path.h
taskset: Accept 0 pid for current process
[thirdparty/util-linux.git] / include / path.h
CommitLineData
faeb1b64
KZ
1/*
2 * No copyright is claimed. This code is in the public domain; do with
3 * it what you wish.
4 */
e21e6d26
KZ
5#ifndef UTIL_LINUX_PATH_H
6#define UTIL_LINUX_PATH_H
7
8148217b 8#include <stdio.h>
37a5c7ee 9#include <stdint.h>
b2a1a691 10#include <sys/stat.h>
1ed21c80
KZ
11#include <sys/types.h>
12#include <dirent.h>
13
2cb147e0
KZ
14#include "c.h"
15
1ed21c80
KZ
16struct path_cxt {
17 int dir_fd;
18 char *dir_path;
19
20 int refcount;
21
22 char *prefix;
23 char path_buffer[PATH_MAX];
24
25 void *dialect;
26 void (*free_dialect)(struct path_cxt *);
27 int (*redirect_on_enoent)(struct path_cxt *, const char *, int *);
28};
29
f5771a08
KZ
30struct path_cxt *ul_new_path(const char *dir, ...)
31 __attribute__ ((__format__ (__printf__, 1, 2)));
1ed21c80
KZ
32void ul_unref_path(struct path_cxt *pc);
33void ul_ref_path(struct path_cxt *pc);
34
bcf445fd
KZ
35void ul_path_init_debug(void);
36
1ed21c80
KZ
37int ul_path_set_prefix(struct path_cxt *pc, const char *prefix);
38const char *ul_path_get_prefix(struct path_cxt *pc);
39
40int ul_path_set_dir(struct path_cxt *pc, const char *dir);
41const char *ul_path_get_dir(struct path_cxt *pc);
42
43int ul_path_set_dialect(struct path_cxt *pc, void *data, void free_data(struct path_cxt *));
44void *ul_path_get_dialect(struct path_cxt *pc);
45
46int ul_path_set_enoent_redirect(struct path_cxt *pc, int (*func)(struct path_cxt *, const char *, int *));
47int ul_path_get_dirfd(struct path_cxt *pc);
c9ea91d4
KZ
48void ul_path_close_dirfd(struct path_cxt *pc);
49int ul_path_isopen_dirfd(struct path_cxt *pc);
655d736d 50int ul_path_is_accessible(struct path_cxt *pc);
1ed21c80 51
e74e5401
KZ
52char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
53 __attribute__ ((__format__ (__printf__, 4, 5)));
54
db9ad223 55int ul_path_stat(struct path_cxt *pc, struct stat *sb, int flags, const char *path);
6f962f51
KZ
56int ul_path_vstatf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, va_list ap);
57int ul_path_statf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, ...);
58
1ed21c80
KZ
59int ul_path_access(struct path_cxt *pc, int mode, const char *path);
60int ul_path_accessf(struct path_cxt *pc, int mode, const char *path, ...)
61 __attribute__ ((__format__ (__printf__, 3, 4)));
62
63int ul_path_open(struct path_cxt *pc, int flags, const char *path);
64int ul_path_openf(struct path_cxt *pc, int flags, const char *path, ...)
65 __attribute__ ((__format__ (__printf__, 3, 4)));
f5771a08
KZ
66int ul_path_vopenf(struct path_cxt *pc, int flags, const char *path, va_list ap)
67 __attribute__ ((__format__ (__printf__, 3, 0)));
1ed21c80
KZ
68
69FILE *ul_path_fopen(struct path_cxt *pc, const char *mode, const char *path);
70FILE *ul_path_fopenf(struct path_cxt *pc, const char *mode, const char *path, ...)
71 __attribute__ ((__format__ (__printf__, 3, 4)));
f5771a08
KZ
72FILE *ul_path_vfopenf(struct path_cxt *pc, const char *mode, const char *path, va_list ap)
73 __attribute__ ((__format__ (__printf__, 3, 0)));
1ed21c80
KZ
74
75DIR *ul_path_opendir(struct path_cxt *pc, const char *path);
f5771a08
KZ
76DIR *ul_path_vopendirf(struct path_cxt *pc, const char *path, va_list ap)
77 __attribute__ ((__format__ (__printf__, 2, 0)));
1ed21c80
KZ
78DIR *ul_path_opendirf(struct path_cxt *pc, const char *path, ...)
79 __attribute__ ((__format__ (__printf__, 2, 3)));
80
81ssize_t ul_path_readlink(struct path_cxt *pc, char *buf, size_t bufsiz, const char *path);
82ssize_t ul_path_readlinkf(struct path_cxt *pc, char *buf, size_t bufsiz, const char *path, ...)
83 __attribute__ ((__format__ (__printf__, 4, 5)));
84
85int ul_path_read(struct path_cxt *pc, char *buf, size_t len, const char *path);
f5771a08
KZ
86int ul_path_vreadf(struct path_cxt *pc, char *buf, size_t len, const char *path, va_list ap)
87 __attribute__ ((__format__ (__printf__, 4, 0)));
1ed21c80
KZ
88int ul_path_readf(struct path_cxt *pc, char *buf, size_t len, const char *path, ...)
89 __attribute__ ((__format__ (__printf__, 4, 5)));
90
91int ul_path_read_string(struct path_cxt *pc, char **str, const char *path);
92int ul_path_readf_string(struct path_cxt *pc, char **str, const char *path, ...)
93 __attribute__ ((__format__ (__printf__, 3, 4)));
94
7eb8e47b
KZ
95int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path);
96int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
97 __attribute__ ((__format__ (__printf__, 4, 5)));
1a45153e
TW
98int ul_path_vreadf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, va_list ap)
99 __attribute__ ((__format__ (__printf__, 4, 0)));
7eb8e47b 100
f5771a08
KZ
101int ul_path_scanf(struct path_cxt *pc, const char *path, const char *fmt, ...)
102 __attribute__ ((__format__ (__scanf__, 3, 4)));
1ed21c80 103int ul_path_scanff(struct path_cxt *pc, const char *path, va_list ap, const char *fmt, ...)
f5771a08 104 __attribute__ ((__format__ (__printf__, 2, 0)))
1ed21c80
KZ
105 __attribute__ ((__format__ (__scanf__, 4, 5)));
106
107int ul_path_read_majmin(struct path_cxt *pc, dev_t *res, const char *path);
108int ul_path_readf_majmin(struct path_cxt *pc, dev_t *res, const char *path, ...)
109 __attribute__ ((__format__ (__printf__, 3, 4)));
110
111int ul_path_read_u32(struct path_cxt *pc, uint32_t *res, const char *path);
112int ul_path_readf_u32(struct path_cxt *pc, uint32_t *res, const char *path, ...)
113 __attribute__ ((__format__ (__printf__, 3, 4)));
114
115int ul_path_read_s32(struct path_cxt *pc, int32_t *res, const char *path);
116int ul_path_readf_s32(struct path_cxt *pc, int32_t *res, const char *path, ...)
117 __attribute__ ((__format__ (__printf__, 3, 4)));
118
119int ul_path_read_u64(struct path_cxt *pc, uint64_t *res, const char *path);
120int ul_path_readf_u64(struct path_cxt *pc, uint64_t *res, const char *path, ...)
121 __attribute__ ((__format__ (__printf__, 3, 4)));
122
123int ul_path_read_s64(struct path_cxt *pc, int64_t *res, const char *path);
124int ul_path_readf_s64(struct path_cxt *pc, int64_t *res, const char *path, ...)
125 __attribute__ ((__format__ (__printf__, 3, 4)));
126
127int ul_path_write_string(struct path_cxt *pc, const char *str, const char *path);
128int ul_path_writef_string(struct path_cxt *pc, const char *str, const char *path, ...)
129 __attribute__ ((__format__ (__printf__, 3, 4)));
130
c455cdb3 131int ul_path_write_s64(struct path_cxt *pc, int64_t num, const char *path);
1ed21c80
KZ
132int ul_path_write_u64(struct path_cxt *pc, uint64_t num, const char *path);
133int ul_path_writef_u64(struct path_cxt *pc, uint64_t num, const char *path, ...)
134 __attribute__ ((__format__ (__printf__, 3, 4)));
135
136int ul_path_count_dirents(struct path_cxt *pc, const char *path);
137int ul_path_countf_dirents(struct path_cxt *pc, const char *path, ...)
138 __attribute__ ((__format__ (__printf__, 2, 3)));
139
ae838009
KZ
140int ul_path_next_dirent(struct path_cxt *pc, DIR **sub, const char *dirname, struct dirent **d);
141
e21e6d26
KZ
142
143#ifdef HAVE_CPU_SET_T
144# include "cpuset.h"
1ed21c80
KZ
145int ul_path_readf_cpuset(struct path_cxt *pc, cpu_set_t **set, int maxcpus, const char *path, ...)
146 __attribute__ ((__format__ (__printf__, 4, 5)));
e21e6d26 147
1ed21c80
KZ
148int ul_path_readf_cpulist(struct path_cxt *pc, cpu_set_t **set, int maxcpus, const char *path, ...)
149 __attribute__ ((__format__ (__printf__, 4, 5)));
e21e6d26 150#endif /* HAVE_CPU_SET_T */
e21e6d26 151#endif /* UTIL_LINUX_PATH_H */