[PATCH v2 31/46] stat64: Use fstatat64 if arch does not have the stat64 syscall

Markos Chandras markos.chandras at gmail.com
Mon Nov 26 14:24:13 UTC 2012


From: Markos Chandras <markos.chandras at imgtec.com>

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
 include/sys/stat.h                    |  1 +
 libc/sysdeps/linux/common/fstatat64.c |  1 +
 libc/sysdeps/linux/common/stat64.c    | 16 ++++++++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/sys/stat.h b/include/sys/stat.h
index e04fd44..4b16c71 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -257,6 +257,7 @@ extern int __REDIRECT_NTH (fstatat, (int __fd, __const char *__restrict __file,
 extern int fstatat64 (int __fd, __const char *__restrict __file,
 		      struct stat64 *__restrict __buf, int __flag)
      __THROW __nonnull ((2, 3));
+libc_hidden_proto(fstatat64)
 # endif
 #endif
 
diff --git a/libc/sysdeps/linux/common/fstatat64.c b/libc/sysdeps/linux/common/fstatat64.c
index 203ec4c..5926711 100644
--- a/libc/sysdeps/linux/common/fstatat64.c
+++ b/libc/sysdeps/linux/common/fstatat64.c
@@ -29,6 +29,7 @@ int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
 
 	return ret;
 }
+libc_hidden_def(fstatat64)
 #else
 /* should add emulation with fstat64() and /proc/self/fd/ ... */
 #endif
diff --git a/libc/sysdeps/linux/common/stat64.c b/libc/sysdeps/linux/common/stat64.c
index a76f182..52a83ec 100644
--- a/libc/sysdeps/linux/common/stat64.c
+++ b/libc/sysdeps/linux/common/stat64.c
@@ -9,11 +9,21 @@
 
 #include <sys/syscall.h>
 #include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
 
-#if defined __UCLIBC_HAS_LFS__ && defined __NR_stat64
+#if defined __UCLIBC_HAS_LFS__
 
+#if defined(__NR_fstatat64) && !defined(__NR_stat64)
+int stat64(const char *file_name, struct stat64 *buf)
+{
+	return fstatat64(AT_FDCWD, file_name, buf, 0);
+}
+libc_hidden_def(stat64)
+
+/* For systems which have both, prefer the old one */
+#elif defined(__NR_stat64)
 # define __NR___syscall_stat64 __NR_stat64
-# include <unistd.h>
 # include "xstatconv.h"
 
 static __inline__ _syscall2(int, __syscall_stat64,
@@ -32,3 +42,5 @@ int stat64(const char *file_name, struct stat64 *buf)
 }
 libc_hidden_def(stat64)
 #endif
+
+#endif /* __UCLIBC_HAS_LFS__ */
-- 
1.8.0




More information about the uClibc mailing list