]>
Commit | Line | Data |
---|---|---|
3c7f1f59 | 1 | /* Linux lseek implementation, 32 bits off_t. |
688903eb | 2 | Copyright (C) 2016-2018 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 PE |
16 | License along with the GNU C Library. If not, see |
17 | <http://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 | ||
31 | static 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 | |
41 | off_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 | } |
54 | libc_hidden_def (__lseek) | |
55 | weak_alias (__lseek, lseek) | |
56 | strong_alias (__lseek, __libc_lseek) | |
3c7f1f59 | 57 | #endif /* __OFF_T_MATCHES_OFF64_T */ |