remove LFS64 symbol aliases; replace with dynamic linker remapping
[musl] / src / stat / fstatat.c
index 7de7546..0450637 100644 (file)
@@ -6,7 +6,6 @@
 #include <stdint.h>
 #include <sys/sysmacros.h>
 #include "syscall.h"
-#include "kstat.h"
 
 struct statx {
        uint32_t stx_mask;
@@ -57,26 +56,38 @@ static int fstatat_statx(int fd, const char *restrict path, struct stat *restric
                .st_mtim.tv_nsec = stx.stx_mtime.tv_nsec,
                .st_ctim.tv_sec = stx.stx_ctime.tv_sec,
                .st_ctim.tv_nsec = stx.stx_ctime.tv_nsec,
+#if _REDIR_TIME64
+               .__st_atim32.tv_sec = stx.stx_atime.tv_sec,
+               .__st_atim32.tv_nsec = stx.stx_atime.tv_nsec,
+               .__st_mtim32.tv_sec = stx.stx_mtime.tv_sec,
+               .__st_mtim32.tv_nsec = stx.stx_mtime.tv_nsec,
+               .__st_ctim32.tv_sec = stx.stx_ctime.tv_sec,
+               .__st_ctim32.tv_nsec = stx.stx_ctime.tv_nsec,
+#endif
        };
        return 0;
 }
 
+#ifdef SYS_fstatat
+
+#include "kstat.h"
+
 static int fstatat_kstat(int fd, const char *restrict path, struct stat *restrict st, int flag)
 {
        int ret;
        struct kstat kst;
 
        if (flag==AT_EMPTY_PATH && fd>=0 && !*path) {
-               ret = __syscall(SYS_fstat, fd, st);
+               ret = __syscall(SYS_fstat, fd, &kst);
                if (ret==-EBADF && __syscall(SYS_fcntl, fd, F_GETFD)>=0) {
-                       ret = __syscall(SYS_fstatat, fd, path, st, flag);
+                       ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
                        if (ret==-EINVAL) {
                                char buf[15+3*sizeof(int)];
                                __procfdname(buf, fd);
 #ifdef SYS_stat
-                               ret = __syscall(SYS_stat, buf, st);
+                               ret = __syscall(SYS_stat, buf, &kst);
 #else
-                               ret = __syscall(SYS_fstatat, AT_FDCWD, buf, st, 0);
+                               ret = __syscall(SYS_fstatat, AT_FDCWD, buf, &kst, 0);
 #endif
                        }
                }
@@ -110,20 +121,33 @@ static int fstatat_kstat(int fd, const char *restrict path, struct stat *restric
                .st_mtim.tv_nsec = kst.st_mtime_nsec,
                .st_ctim.tv_sec = kst.st_ctime_sec,
                .st_ctim.tv_nsec = kst.st_ctime_nsec,
+#if _REDIR_TIME64
+               .__st_atim32.tv_sec = kst.st_atime_sec,
+               .__st_atim32.tv_nsec = kst.st_atime_nsec,
+               .__st_mtim32.tv_sec = kst.st_mtime_sec,
+               .__st_mtim32.tv_nsec = kst.st_mtime_nsec,
+               .__st_ctim32.tv_sec = kst.st_ctime_sec,
+               .__st_ctim32.tv_nsec = kst.st_ctime_nsec,
+#endif
        };
 
        return 0;
 }
+#endif
 
-int fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
+int __fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
 {
        int ret;
+#ifdef SYS_fstatat
        if (sizeof((struct kstat){0}.st_atime_sec) < sizeof(time_t)) {
                ret = fstatat_statx(fd, path, st, flag);
                if (ret!=-ENOSYS) return __syscall_ret(ret);
        }
        ret = fstatat_kstat(fd, path, st, flag);
+#else
+       ret = fstatat_statx(fd, path, st, flag);
+#endif
        return __syscall_ret(ret);
 }
 
-weak_alias(fstatat, fstatat64);
+weak_alias(__fstatat, fstatat);