aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/lseek64.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2016-08-25 17:42:44 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2016-11-08 16:04:33 -0200
commit3c7f1f59cd1611e0727f9b5ffc32dae78cb05000 (patch)
treee70424eba74bebc6cbc1466f995d8474c57ce89d /sysdeps/unix/sysv/linux/lseek64.c
parente0c6851980806f2a51b37e3e37fc9a48420a4a83 (diff)
downloadglibc-3c7f1f59cd1611e0727f9b5ffc32dae78cb05000.tar
glibc-3c7f1f59cd1611e0727f9b5ffc32dae78cb05000.tar.gz
glibc-3c7f1f59cd1611e0727f9b5ffc32dae78cb05000.tar.bz2
glibc-3c7f1f59cd1611e0727f9b5ffc32dae78cb05000.zip
Consolidate lseek/lseek64/llseek implementations
This patch consolidates all Linux lseek/lseek64/llseek implementation in on on sysdeps/unix/sysv/linux/lseek{64}.c. It also removes the llseek file and instead consolidate the LFS lseek implementation on lseek64.c as for other LFS symbols implementations. The general idea is: - lseek: ABIs that not define __OFF_T_MATCHES_OFF64_T will preferable use __NR__llseek if kernel supports it, otherwise they will use __NR_lseek. ABIs that defines __OFF_T_MATCHES_OFF64_T won't produce any symbol. - lseek64: ABIs with __OFF_T_MATCHES_OFF64_T will preferable use __NR_lseek (since it will use 64-bit arguments without low/high splitting) and __NR__llseek if __NR_lseek is not defined (for some ILP32 ports). - llseek: files will be removed and symbols will be aliased ot lseek64. ABI without __OFF_T_MATCHES_OFF64_T and without __NR_llseek (basically MIPS64n32 so far) are covered by building lseek with off_t as expected and lseek64 using __NR_lseek (as expected for off64_t being passed using 64-bit registers). For this consolidation I mantained the x32 assembly specific implementation because to correctly fix this it would required both the x32 fix for {INLINE,INTERNAL}_SYSCALL [1] and a wrapper to correctly subscribe it to return 64 bits instead of default 32 bits (as for times). It could a future cleanup. It is based on my previous {INTERNAL,INLINE}_SYSCALL_CALL macro [2], although it is mainly for simplification. Tested on x86_64, i686, aarch64, armhf, and powerpc64le. * nptl/Makefile (libpthread-routines): Remove ptw-llseek and add ptw-lseek64. * sysdeps/unix/sysv/linux/Makefile (sysdeps_routines): Remove llseek. * sysdeps/unix/sysv/linux/alpha/Makefile (sysdeps_routines): Likewise. * sysdeps/unix/sysv/linux/generic/wordsize-32/llseek.c: Remove file. * sysdeps/unix/sysv/linux/generic/wordsize-32/lseek.c: Remove file. * sysdeps/unix/sysv/linux/mips/mips64/llseek.c: Likewise. * sysdeps/unix/sysv/linux/llseek.c: Remove file. * sysdeps/unix/sysv/linux/lseek.c: New file. * sysdeps/unix/sysv/linux/lseek64.c: Add default Linux implementation. * sysdeps/unix/sysv/linux/mips/mips64/syscalls.list: Remove lseek and __libc_lseek64 from auto-generation. * sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/lseek64.S: New file. [1] https://sourceware.org/ml/libc-alpha/2016-08/msg00443.html [2] https://sourceware.org/ml/libc-alpha/2016-08/msg00646.html
Diffstat (limited to 'sysdeps/unix/sysv/linux/lseek64.c')
-rw-r--r--sysdeps/unix/sysv/linux/lseek64.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/sysdeps/unix/sysv/linux/lseek64.c b/sysdeps/unix/sysv/linux/lseek64.c
index d81e98fb51..c4a0851d8c 100644
--- a/sysdeps/unix/sysv/linux/lseek64.c
+++ b/sysdeps/unix/sysv/linux/lseek64.c
@@ -1 +1,54 @@
-/* We don't need a definition since the llseek function is what we need. */
+/* Linux lseek implementation, 64 bits off_t.
+ Copyright (C) 2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ 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/>. */
+
+#include <unistd.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sysdep.h>
+#include <errno.h>
+
+off64_t
+__lseek64 (int fd, off64_t offset, int whence)
+{
+#ifdef __NR__llseek
+ loff_t res;
+ int rc = INLINE_SYSCALL_CALL (_llseek, fd,
+ (long) (((uint64_t) (offset)) >> 32),
+ (long) offset, &res, whence);
+ return rc ?: res;
+#else
+ return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);
+#endif
+}
+
+#ifdef __OFF_T_MATCHES_OFF64_T
+weak_alias (__lseek64, lseek)
+weak_alias (__lseek64, __lseek)
+strong_alias (__lseek64, __libc_lseek)
+libc_hidden_def (__lseek)
+#endif
+
+strong_alias (__lseek64, __libc_lseek64)
+weak_alias (__lseek64, lseek64)
+
+/* llseek doesn't have a prototype. Since the second parameter is a
+ 64bit type, this results in wrong behaviour if no prototype is
+ provided. */
+weak_alias (__lseek64, llseek)
+link_warning (llseek, "\
+the `llseek' function may be dangerous; use `lseek64' instead.")