1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#pragma once
/**
* @file
*
* NUL-safe wrappers for C functions.
*/
#include "file-descriptor.hh"
#include "file-system.hh"
#include <grp.h>
#include <sys/statvfs.h>
namespace nix {
class CString
{
friend CString requireCString(const std::string & s);
const std::string * s;
explicit CString(const std::string & s) : s(&s) {}
public:
operator const char *() const
{
return s->c_str();
}
const char * asCStr() const
{
return *this;
}
};
CString requireCString(const std::string & s);
}
namespace nix::sys {
AutoCloseFD open(const std::string & path, int flags);
AutoCloseFD open(const std::string & path, int flags, mode_t mode);
AutoCloseFD openat(int dir, const std::string & path, int flags);
AutoCloseFD openat(int dir, const std::string & path, int flags, mode_t mode);
AutoCloseDir opendir(const std::string & path);
[[nodiscard]]
int mkdir(const std::string & path, mode_t mode);
[[nodiscard]]
int lstat(const std::string & path, struct ::stat * st);
[[nodiscard]]
int stat(const std::string & path, struct ::stat * st);
[[nodiscard]]
int unlink(const std::string & path);
[[nodiscard]]
int access(const std::string & path, int mode);
[[nodiscard]]
int chmod(const std::string & path, mode_t mode);
[[nodiscard]]
int chown(const std::string & path, uid_t uid, gid_t gid);
[[nodiscard]]
int fchownat(int dir, const std::string & path, uid_t uid, gid_t gid, int flags);
[[nodiscard]]
int lchown(const std::string & path, uid_t uid, gid_t gid);
[[nodiscard]]
int rename(const std::string & oldPath, const std::string & newPath);
[[nodiscard]]
int utimes(const std::string & path, const struct ::timeval times[2]);
[[nodiscard]]
int lutimes(const std::string & path, const struct ::timeval times[2]);
[[nodiscard]]
int link(const std::string & oldPath, const std::string & newPath);
[[nodiscard]]
int symlink(const std::string & target, const std::string & linkpath);
[[nodiscard]]
int unlinkat(int dir, const std::string & path, int flags);
[[nodiscard]]
int remove(const std::string & path);
[[nodiscard]]
int rmdir(const std::string & path);
[[nodiscard]]
int fstatat(int dir, const std::string & path, struct ::stat * st, int flags);
[[nodiscard]]
int fchmodat(int dir, const std::string & path, mode_t mode, int flags);
[[nodiscard]]
int statvfs(const std::string & path, struct ::statvfs * st);
#if __linux__
[[nodiscard]]
int mount(
const std::string & source,
const std::string & target,
const std::string & filesystemtype,
unsigned long mountflags,
const void * data
);
#endif
[[nodiscard]]
ssize_t llistxattr(const std::string & path, char * list, size_t size);
[[nodiscard]]
ssize_t lremovexattr(const std::string & path, const std::string & name);
[[nodiscard]]
ssize_t getxattr(const std::string & path, const std::string & name, void * value, size_t size);
[[nodiscard]]
int chdir(const std::string & path);
[[nodiscard]]
int chroot(const std::string & path);
AutoCloseFD mkstemp(std::string & path);
[[nodiscard]]
ssize_t readlink(const std::string & path, char * buf, size_t bufsiz);
int execv(const std::string & path, const std::list<std::string> & argv);
int execvp(const std::string & path, const std::list<std::string> & argv);
int execve(
const std::string & path,
const std::list<std::string> & argv,
const std::list<std::string> & envp
);
char * getenv(const std::string & name);
[[nodiscard]]
int setenv(const std::string & name, const std::string & value, int overwrite);
[[nodiscard]]
int unsetenv(const std::string & name);
struct group * getgrnam(const std::string & name);
struct Passwd
{
std::string pw_name;
std::string pw_passwd;
uid_t pw_uid;
gid_t pw_gid;
std::string pw_gecos;
std::string pw_dir;
std::string pw_shell;
};
std::optional<Passwd> getpwnam(const std::string & name);
}
|