This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] generic/wordsize-32: don't duplicate truncate syscalls if not needed


If off_t is 64-bit, current implementation of truncate() and ftruncate()
is wrong, and proper implementation is identical to corresponding 64-bit
versions of syscalls. This patch creates aliases for it.

2016-09-19: Yury Norov  <ynorov@caviumnetworks.com>

	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c:
	  don't declare ftruncate() and symbols if off_t is 64-bit.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c:
	  declare ftruncate() and symbols if off_t is 64-bit.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
	  don't declare truncate() and symbols if off_t is 64-bit.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
	  declare truncate() and symbols if off_t is 64-bit.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c   | 2 ++
 sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c | 9 +++++++++
 sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c    | 2 ++
 sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c  | 9 +++++++++
 4 files changed, 22 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
index e1b500d..35ae787 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate.c
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifndef __OFF_T_MATCHES_OFF64_T
 /* Truncate the file FD refers to to LENGTH bytes.  */
 int
 __ftruncate (int fd, off_t length)
@@ -29,3 +30,4 @@ __ftruncate (int fd, off_t length)
                          __LONG_LONG_PAIR (length >> 31, length));
 }
 weak_alias (__ftruncate, ftruncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
index 946f05a..0ff3e70 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/ftruncate64.c
@@ -15,6 +15,8 @@
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
+#define __ftruncate __ftruncate_disable
+#define ftruncate ftruncate_disable
 
 #include <errno.h>
 #include <sys/types.h>
@@ -30,3 +32,10 @@ __ftruncate64 (int fd, off64_t length)
                          __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
 }
 weak_alias (__ftruncate64, ftruncate64)
+
+#undef __ftruncate
+#undef ftruncate
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (__ftruncate64, __ftruncate)
+weak_alias (__ftruncate64, ftruncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
index 2579951..b3e54e4 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate.c
@@ -20,6 +20,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#ifndef __OFF_T_MATCHES_OFF64_T
 /* Truncate PATH to LENGTH bytes.  */
 int
 __truncate (const char *path, off_t length)
@@ -29,3 +30,4 @@ __truncate (const char *path, off_t length)
                          __LONG_LONG_PAIR (length >> 31, length));
 }
 weak_alias (__truncate, truncate)
+#endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
index f2927ea..e4343cd 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/truncate64.c
@@ -15,6 +15,8 @@
    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library.  If not, see
    <http://www.gnu.org/licenses/>.  */
+#define __truncate __truncate_disabled
+#define truncate truncate_disabled
 
 #include <errno.h>
 #include <sys/types.h>
@@ -29,3 +31,10 @@ truncate64 (const char *path, off64_t length)
   return INLINE_SYSCALL (truncate64, __ALIGNMENT_COUNT (3, 4), path,
                          __ALIGNMENT_ARG __LONG_LONG_PAIR (high, low));
 }
+
+#undef __truncate
+#undef truncate
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (truncate64, __truncate)
+weak_alias (truncate64, truncate)
+#endif
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]