diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c index 1222d2ee75c6..9f438d67dc69 100644 --- a/pkgs/build-support/libredirect/libredirect.c +++ b/pkgs/build-support/libredirect/libredirect.c @@ -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); diff --git a/pkgs/build-support/libredirect/test.c b/pkgs/build-support/libredirect/test.c index 144e6d3d66dd..650bdd849037 100644 --- a/pkgs/build-support/libredirect/test.c +++ b/pkgs/build-support/libredirect/test.c @@ -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!