]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/lseek.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / lseek.c
CommitLineData
3c7f1f59 1/* Linux lseek implementation, 32 bits off_t.
04277e02 2 Copyright (C) 2016-2019 Free Software Foundation, Inc.
a63c7fa1 3 This file is part of the GNU C Library.
a63c7fa1
CM
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
ab84e3ff 16 License along with the GNU C Library. If not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
a63c7fa1 18
a63c7fa1 19#include <unistd.h>
3c7f1f59 20#include <stdint.h>
a63c7fa1 21#include <sys/types.h>
a63c7fa1 22#include <sysdep.h>
3c7f1f59
AZ
23#include <errno.h>
24
25#ifndef __OFF_T_MATCHES_OFF64_T
a63c7fa1 26
3c7f1f59
AZ
27/* Test for overflows of structures where we ask the kernel to fill them
28 in with standard 64-bit syscalls but return them through APIs that
29 only expose the low 32 bits of some fields. */
30
31static inline off_t lseek_overflow (loff_t res)
32{
33 off_t retval = (off_t) res;
34 if (retval == res)
35 return retval;
36
37 __set_errno (EOVERFLOW);
38 return (off_t) -1;
39}
a63c7fa1
CM
40
41off_t
42__lseek (int fd, off_t offset, int whence)
43{
3c7f1f59 44# ifdef __NR__llseek
a63c7fa1 45 loff_t res;
3c7f1f59
AZ
46 int rc = INLINE_SYSCALL_CALL (_llseek, fd,
47 (long) (((uint64_t) (offset)) >> 32),
48 (long) offset, &res, whence);
a63c7fa1 49 return rc ?: lseek_overflow (res);
3c7f1f59
AZ
50# else
51 return INLINE_SYSCALL_CALL (lseek, fd, offset, whence);
52# endif
a63c7fa1
CM
53}
54libc_hidden_def (__lseek)
55weak_alias (__lseek, lseek)
56strong_alias (__lseek, __libc_lseek)
3c7f1f59 57#endif /* __OFF_T_MATCHES_OFF64_T */