Merge pull request #212678 from impl/libredirect-wrappers

libredirect: add more wrappers
This commit is contained in:
Robert Scott 2023-01-31 22:35:19 +00:00 committed by GitHub
commit 117178971a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 0 deletions

View File

@ -201,6 +201,37 @@ WRAPPER(int, __xstat64)(int ver, const char * path, struct stat64 * st)
WRAPPER_DEF(__xstat64)
#endif
#ifdef __linux__
WRAPPER(int, statx)(int dirfd, const char * restrict pathname, int flags,
unsigned int mask, struct statx * restrict statxbuf)
{
int (*statx_real) (int, const char * restrict, int,
unsigned int, struct statx * restrict) = LOOKUP_REAL(statx);
char buf[PATH_MAX];
return statx_real(dirfd, rewrite(pathname, buf), flags, mask, statxbuf);
}
WRAPPER_DEF(statx)
#endif
WRAPPER(int, fstatat)(int dirfd, const char * pathname, struct stat * statbuf, int flags)
{
int (*fstatat_real) (int, const char *, struct stat *, int) = LOOKUP_REAL(fstatat);
char buf[PATH_MAX];
return fstatat_real(dirfd, rewrite(pathname, buf), statbuf, flags);
}
WRAPPER_DEF(fstatat);
// In musl libc, fstatat64 is simply a macro for fstatat
#if !defined(__APPLE__) && !defined(fstatat64)
WRAPPER(int, fstatat64)(int dirfd, const char * pathname, struct stat64 * statbuf, int flags)
{
int (*fstatat64_real) (int, const char *, struct stat64 *, int) = LOOKUP_REAL(fstatat64);
char buf[PATH_MAX];
return fstatat64_real(dirfd, rewrite(pathname, buf), statbuf, flags);
}
WRAPPER_DEF(fstatat64);
#endif
WRAPPER(int, stat)(const char * path, struct stat * st)
{
int (*__stat_real) (const char *, struct stat *) = LOOKUP_REAL(stat);
@ -209,6 +240,17 @@ WRAPPER(int, stat)(const char * path, struct stat * st)
}
WRAPPER_DEF(stat)
// In musl libc, stat64 is simply a macro for stat
#if !defined(__APPLE__) && !defined(stat64)
WRAPPER(int, stat64)(const char * path, struct stat64 * st)
{
int (*stat64_real) (const char *, struct stat64 *) = LOOKUP_REAL(stat64);
char buf[PATH_MAX];
return stat64_real(rewrite(path, buf), st);
}
WRAPPER_DEF(stat64)
#endif
WRAPPER(int, access)(const char * path, int mode)
{
int (*access_real) (const char *, int mode) = LOOKUP_REAL(access);
@ -346,6 +388,14 @@ WRAPPER(int, system)(const char *command)
}
WRAPPER_DEF(system)
WRAPPER(int, chdir)(const char *path)
{
int (*chdir_real) (const char *) = LOOKUP_REAL(chdir);
char buf[PATH_MAX];
return chdir_real(rewrite(path, buf));
}
WRAPPER_DEF(chdir);
WRAPPER(int, mkdir)(const char *path, mode_t mode)
{
int (*mkdir_real) (const char *path, mode_t mode) = LOOKUP_REAL(mkdir);

View File

@ -63,6 +63,12 @@ int main(int argc, char *argv[])
FILE *testfp;
int testfd;
struct stat testsb;
#ifndef __APPLE__
struct stat64 testsb64;
#endif
#ifdef __linux__
struct statx testsbx;
#endif
char buf[PATH_MAX];
testfp = fopen(TESTPATH, "r");
@ -76,6 +82,20 @@ int main(int argc, char *argv[])
assert(access(TESTPATH, X_OK) == 0);
assert(stat(TESTPATH, &testsb) != -1);
#ifndef __APPLE__
assert(stat64(TESTPATH, &testsb64) != -1);
#endif
assert(fstatat(123, TESTPATH, &testsb, 0) != -1);
#ifndef __APPLE__
assert(fstatat64(123, TESTPATH, &testsb64, 0) != -1);
#endif
#ifdef __linux__
assert(statx(123, TESTPATH, 0, STATX_ALL, &testsbx) != -1);
#endif
assert(getcwd(buf, PATH_MAX) != NULL);
assert(chdir(TESTDIR) == 0);
assert(chdir(buf) == 0);
assert(mkdir(TESTDIR "/dir-mkdir", 0777) == 0);
assert(unlink(TESTDIR "/dir-mkdir") == -1); // it's a directory!