]> git.ipfire.org Git - thirdparty/util-linux.git/blame - include/path.h
include/xalloc: reindent function bodies to unify indentation
[thirdparty/util-linux.git] / include / path.h
CommitLineData
e21e6d26
KZ
1#ifndef UTIL_LINUX_PATH_H
2#define UTIL_LINUX_PATH_H
3
8148217b 4#include <stdio.h>
37a5c7ee 5#include <stdint.h>
1ed21c80
KZ
6#include <sys/types.h>
7#include <dirent.h>
8
2cb147e0
KZ
9#include "c.h"
10
1ed21c80
KZ
11struct path_cxt {
12 int dir_fd;
13 char *dir_path;
14
15 int refcount;
16
17 char *prefix;
18 char path_buffer[PATH_MAX];
19
20 void *dialect;
21 void (*free_dialect)(struct path_cxt *);
22 int (*redirect_on_enoent)(struct path_cxt *, const char *, int *);
23};
24
83bbeb77 25struct path_cxt *ul_new_path(const char *dir, ...);
1ed21c80
KZ
26void ul_unref_path(struct path_cxt *pc);
27void ul_ref_path(struct path_cxt *pc);
28
bcf445fd
KZ
29void ul_path_init_debug(void);
30
1ed21c80
KZ
31int ul_path_set_prefix(struct path_cxt *pc, const char *prefix);
32const char *ul_path_get_prefix(struct path_cxt *pc);
33
34int ul_path_set_dir(struct path_cxt *pc, const char *dir);
35const char *ul_path_get_dir(struct path_cxt *pc);
36
37int ul_path_set_dialect(struct path_cxt *pc, void *data, void free_data(struct path_cxt *));
38void *ul_path_get_dialect(struct path_cxt *pc);
39
40int ul_path_set_enoent_redirect(struct path_cxt *pc, int (*func)(struct path_cxt *, const char *, int *));
41int ul_path_get_dirfd(struct path_cxt *pc);
c9ea91d4
KZ
42void ul_path_close_dirfd(struct path_cxt *pc);
43int ul_path_isopen_dirfd(struct path_cxt *pc);
1ed21c80 44
e74e5401
KZ
45char *ul_path_get_abspath(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
46 __attribute__ ((__format__ (__printf__, 4, 5)));
47
1ed21c80
KZ
48int ul_path_access(struct path_cxt *pc, int mode, const char *path);
49int ul_path_accessf(struct path_cxt *pc, int mode, const char *path, ...)
50 __attribute__ ((__format__ (__printf__, 3, 4)));
51
52int ul_path_open(struct path_cxt *pc, int flags, const char *path);
53int ul_path_openf(struct path_cxt *pc, int flags, const char *path, ...)
54 __attribute__ ((__format__ (__printf__, 3, 4)));
55int ul_path_vopenf(struct path_cxt *pc, int flags, const char *path, va_list ap);
56
57FILE *ul_path_fopen(struct path_cxt *pc, const char *mode, const char *path);
58FILE *ul_path_fopenf(struct path_cxt *pc, const char *mode, const char *path, ...)
59 __attribute__ ((__format__ (__printf__, 3, 4)));
60FILE *ul_path_vfopenf(struct path_cxt *pc, const char *mode, const char *path, va_list ap);
61
62DIR *ul_path_opendir(struct path_cxt *pc, const char *path);
63DIR *ul_path_vopendirf(struct path_cxt *pc, const char *path, va_list ap);
64DIR *ul_path_opendirf(struct path_cxt *pc, const char *path, ...)
65 __attribute__ ((__format__ (__printf__, 2, 3)));
66
67ssize_t ul_path_readlink(struct path_cxt *pc, char *buf, size_t bufsiz, const char *path);
68ssize_t ul_path_readlinkf(struct path_cxt *pc, char *buf, size_t bufsiz, const char *path, ...)
69 __attribute__ ((__format__ (__printf__, 4, 5)));
70
71int ul_path_read(struct path_cxt *pc, char *buf, size_t len, const char *path);
72int ul_path_vreadf(struct path_cxt *pc, char *buf, size_t len, const char *path, va_list ap);
73int ul_path_readf(struct path_cxt *pc, char *buf, size_t len, const char *path, ...)
74 __attribute__ ((__format__ (__printf__, 4, 5)));
75
76int ul_path_read_string(struct path_cxt *pc, char **str, const char *path);
77int ul_path_readf_string(struct path_cxt *pc, char **str, const char *path, ...)
78 __attribute__ ((__format__ (__printf__, 3, 4)));
79
7eb8e47b
KZ
80int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path);
81int ul_path_readf_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char *path, ...)
82 __attribute__ ((__format__ (__printf__, 4, 5)));
83
1ed21c80
KZ
84int ul_path_scanf(struct path_cxt *pc, const char *path, const char *fmt, ...);
85int ul_path_scanff(struct path_cxt *pc, const char *path, va_list ap, const char *fmt, ...)
86 __attribute__ ((__format__ (__scanf__, 4, 5)));
87
88int ul_path_read_majmin(struct path_cxt *pc, dev_t *res, const char *path);
89int ul_path_readf_majmin(struct path_cxt *pc, dev_t *res, const char *path, ...)
90 __attribute__ ((__format__ (__printf__, 3, 4)));
91
92int ul_path_read_u32(struct path_cxt *pc, uint32_t *res, const char *path);
93int ul_path_readf_u32(struct path_cxt *pc, uint32_t *res, const char *path, ...)
94 __attribute__ ((__format__ (__printf__, 3, 4)));
95
96int ul_path_read_s32(struct path_cxt *pc, int32_t *res, const char *path);
97int ul_path_readf_s32(struct path_cxt *pc, int32_t *res, const char *path, ...)
98 __attribute__ ((__format__ (__printf__, 3, 4)));
99
100int ul_path_read_u64(struct path_cxt *pc, uint64_t *res, const char *path);
101int ul_path_readf_u64(struct path_cxt *pc, uint64_t *res, const char *path, ...)
102 __attribute__ ((__format__ (__printf__, 3, 4)));
103
104int ul_path_read_s64(struct path_cxt *pc, int64_t *res, const char *path);
105int ul_path_readf_s64(struct path_cxt *pc, int64_t *res, const char *path, ...)
106 __attribute__ ((__format__ (__printf__, 3, 4)));
107
108int ul_path_write_string(struct path_cxt *pc, const char *str, const char *path);
109int ul_path_writef_string(struct path_cxt *pc, const char *str, const char *path, ...)
110 __attribute__ ((__format__ (__printf__, 3, 4)));
111
c455cdb3 112int ul_path_write_s64(struct path_cxt *pc, int64_t num, const char *path);
1ed21c80
KZ
113int ul_path_write_u64(struct path_cxt *pc, uint64_t num, const char *path);
114int ul_path_writef_u64(struct path_cxt *pc, uint64_t num, const char *path, ...)
115 __attribute__ ((__format__ (__printf__, 3, 4)));
116
117int ul_path_count_dirents(struct path_cxt *pc, const char *path);
118int ul_path_countf_dirents(struct path_cxt *pc, const char *path, ...)
119 __attribute__ ((__format__ (__printf__, 2, 3)));
120
9023b201 121FILE *ul_prefix_fopen(const char *prefix, const char *path, const char *mode);
8148217b 122
e21e6d26
KZ
123
124#ifdef HAVE_CPU_SET_T
125# include "cpuset.h"
1ed21c80
KZ
126int ul_path_readf_cpuset(struct path_cxt *pc, cpu_set_t **set, int maxcpus, const char *path, ...)
127 __attribute__ ((__format__ (__printf__, 4, 5)));
e21e6d26 128
1ed21c80
KZ
129int ul_path_readf_cpulist(struct path_cxt *pc, cpu_set_t **set, int maxcpus, const char *path, ...)
130 __attribute__ ((__format__ (__printf__, 4, 5)));
e21e6d26 131#endif /* HAVE_CPU_SET_T */
e21e6d26 132#endif /* UTIL_LINUX_PATH_H */