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
|
#include <errno.h>
#include <bits/ensure.h>
#include <sys/stat.h>
#include <mlibc/debug.hpp>
#include <mlibc/posix-sysdeps.hpp>
int chmod(const char *pathname, mode_t mode) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_chmod, -1);
if(int e = mlibc::sys_chmod(pathname, mode); e) {
errno = e;
return -1;
}
return 0;
}
int fchmod(int fd, mode_t mode) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_fchmod, -1);
if(int e = mlibc::sys_fchmod(fd, mode); e) {
errno = e;
return -1;
}
return 0;
}
int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_fchmodat, -1);
if(int e = mlibc::sys_fchmodat(dirfd, pathname, mode, flags); e) {
errno = e;
return -1;
}
return 0;
}
int fstatat(int dirfd, const char *path, struct stat *result, int flags) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_stat, -1);
if(int e = mlibc::sys_stat(mlibc::fsfd_target::fd_path, dirfd, path, flags, result); e) {
errno = e;
return -1;
}
return 0;
}
int futimens(int fd, const struct timespec times[2]) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_utimensat, -1);
if (int e = mlibc::sys_utimensat(fd, nullptr, times, 0); e) {
errno = e;
return -1;
}
return 0;
}
int mkdir(const char *path, mode_t mode) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_mkdir, -1);
if(int e = mlibc::sys_mkdir(path, mode); e) {
errno = e;
return -1;
}
return 0;
}
int mkdirat(int dirfd, const char *path, mode_t mode) {
mlibc::infoLogger() << "\e[31mmlibc: mkdirat() ignores its mode\e[39m" << frg::endlog;
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_mkdirat, -1);
if(int e = mlibc::sys_mkdirat(dirfd, path, mode); e) {
errno = e;
return -1;
}
return 0;
}
int mkfifo(const char *path, mode_t mode) {
return mkfifoat(AT_FDCWD, path, mode);
}
int mkfifoat(int dirfd, const char *path, mode_t mode) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_mkfifoat, -1);
if (int e = mlibc::sys_mkfifoat(dirfd, path, mode); e) {
errno = e;
return -1;
}
return 0;
}
int mknod(const char *path, mode_t mode, dev_t dev) {
return mknodat(AT_FDCWD, path, mode, dev);
}
int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_mknodat, -1);
if (int e = mlibc::sys_mknodat(dirfd, path, mode, dev); e) {
errno = e;
return -1;
}
return 0;
}
mode_t umask(mode_t mode) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_umask, -1);
mode_t old;
if (int e = mlibc::sys_umask(mode, &old); e) {
errno = e;
return -1;
}
return old;
}
int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) {
if(pathname == nullptr) {
errno = EINVAL;
return -1;
}
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_utimensat, -1);
if (int e = mlibc::sys_utimensat(dirfd, pathname, times, flags); e) {
errno = e;
return -1;
}
return 0;
}
int stat(const char *path, struct stat *result) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_stat, -1);
if(int e = mlibc::sys_stat(mlibc::fsfd_target::path, -1, path, 0, result); e) {
errno = e;
return -1;
}
return 0;
}
int lstat(const char *path, struct stat *result) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_stat, -1);
if(int e = mlibc::sys_stat(mlibc::fsfd_target::path,
-1, path, AT_SYMLINK_NOFOLLOW, result); e) {
errno = e;
return -1;
}
return 0;
}
int fstat(int fd, struct stat *result) {
MLIBC_CHECK_OR_ENOSYS(mlibc::sys_stat, -1);
if(int e = mlibc::sys_stat(mlibc::fsfd_target::fd, fd, "", 0, result); e) {
errno = e;
return -1;
}
return 0;
}
|