[PATCH v3 26/48] truncate: Use truncate64 if arch does not have the truncate syscall

Markos Chandras markos.chandras at gmail.com
Wed Jan 23 11:41:50 UTC 2013


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

Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
---
 include/unistd.h                       |  1 +
 libc/sysdeps/linux/common/truncate.c   | 22 ++++++++++++++++++++++
 libc/sysdeps/linux/common/truncate64.c |  4 +++-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/include/unistd.h b/include/unistd.h
index ff39c63..0336fc4 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1102,6 +1102,7 @@ extern int __REDIRECT_NTH (truncate,
 # ifdef __USE_LARGEFILE64
 extern int truncate64 (const char *__file, __off64_t __length)
      __THROW __nonnull ((1)) __wur;
+libc_hidden_proto(truncate64)
 # endif
 
 #endif /* Use BSD || X/Open Unix.  */
diff --git a/libc/sysdeps/linux/common/truncate.c b/libc/sysdeps/linux/common/truncate.c
index fe7bda9..190348c 100644
--- a/libc/sysdeps/linux/common/truncate.c
+++ b/libc/sysdeps/linux/common/truncate.c
@@ -8,7 +8,29 @@
  */
 
 #include <sys/syscall.h>
+#include <endian.h>
+#include <stdint.h>
 #include <unistd.h>
 
+#if defined(__NR_truncate64) && !defined(__NR_truncate)
+int truncate(const char *path, __off_t length)
+{
+#if defined __UCLIBC_HAS_LFS
+	return truncate64(path, length);
+#elif __WORDSIZE == 32
+	uint32_t high = length & (1<<31) ? 0xffffffff : 0;
+# if defined(__UCLIBC_TRUNCATE64_HAS_4_ARGS__)
+	return INLINE_SYSCALL(truncate64, 4, path, 0,
+			      __LONG_LONG_PAIR(high, length));
+# else
+	return INLINE_SYSCALL(truncate64, 3, path,
+			      __LONG_LONG_PAIR(high, length));
+# endif
+#endif
+}
+libc_hidden_def(truncate);
+
+#else
 _syscall2(int, truncate, const char *, path, __off_t, length)
 libc_hidden_def(truncate)
+#endif
diff --git a/libc/sysdeps/linux/common/truncate64.c b/libc/sysdeps/linux/common/truncate64.c
index 6dfdc4c..1f5f862 100644
--- a/libc/sysdeps/linux/common/truncate64.c
+++ b/libc/sysdeps/linux/common/truncate64.c
@@ -52,4 +52,6 @@ int truncate64(const char * path, __off64_t length)
 
 	return -1;
 }
-#endif
+
+#endif /* __NR_truncate64 */
+libc_hidden_def(truncate64)
-- 
1.8.1.1




More information about the uClibc mailing list