]>
Commit | Line | Data |
---|---|---|
24c4c341 AJ |
1 | /* Copyright (C) 1997, 1998, 2000, 2002, 2003, 2004 |
2 | Free Software Foundation, Inc. | |
245061db AJ |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
3214b89b AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
245061db AJ |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3214b89b | 14 | Lesser General Public License for more details. |
245061db | 15 | |
3214b89b | 16 | You should have received a copy of the GNU Lesser General Public |
ab84e3ff PE |
17 | License along with the GNU C Library. If not, see |
18 | <http://www.gnu.org/licenses/>. */ | |
245061db AJ |
19 | |
20 | #include <errno.h> | |
f0b94226 | 21 | #ifndef NO_SGIDEFS_H |
b8ddf7a1 | 22 | #include <sgidefs.h> |
f0b94226 | 23 | #endif |
245061db | 24 | #include <unistd.h> |
6f5d6cb6 | 25 | #include <endian.h> |
245061db | 26 | |
8c5a1c78 | 27 | #include <sysdep-cancel.h> |
245061db | 28 | #include <sys/syscall.h> |
e3d6c581 | 29 | #include <bp-checks.h> |
245061db AJ |
30 | |
31 | #include <kernel-features.h> | |
32 | ||
8c5a1c78 UD |
33 | #ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */ |
34 | # ifdef __NR_pread | |
35 | # error "__NR_pread and __NR_pread64 both defined???" | |
36 | # endif | |
37 | # define __NR_pread __NR_pread64 | |
38 | #endif | |
39 | ||
245061db AJ |
40 | #if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0 |
41 | ||
42 | # if __ASSUME_PREAD_SYSCALL == 0 | |
43 | static ssize_t __emulate_pread64 (int fd, void *buf, size_t count, | |
44 | off64_t offset) internal_function; | |
45 | # endif | |
46 | ||
245061db AJ |
47 | ssize_t |
48 | __libc_pread64 (fd, buf, count, offset) | |
49 | int fd; | |
50 | void *buf; | |
51 | size_t count; | |
52 | off64_t offset; | |
53 | { | |
54 | ssize_t result; | |
55 | ||
8c5a1c78 UD |
56 | |
57 | if (SINGLE_THREAD_P) | |
58 | { | |
59 | /* First try the syscall. */ | |
b8ddf7a1 | 60 | #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64 |
8525f64d | 61 | result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count, |
fe638fda AO |
62 | offset); |
63 | #else | |
8c5a1c78 UD |
64 | result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0, |
65 | __LONG_LONG_PAIR ((off_t) (offset >> 32), | |
66 | (off_t) (offset & 0xffffffff))); | |
fe638fda | 67 | #endif |
8c5a1c78 UD |
68 | # if __ASSUME_PREAD_SYSCALL == 0 |
69 | if (result == -1 && errno == ENOSYS) | |
70 | /* No system call available. Use the emulation. */ | |
71 | result = __emulate_pread64 (fd, buf, count, offset); | |
72 | # endif | |
73 | return result; | |
74 | } | |
75 | ||
76 | int oldtype = LIBC_CANCEL_ASYNC (); | |
77 | ||
245061db | 78 | /* First try the syscall. */ |
b8ddf7a1 | 79 | #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64 |
8525f64d | 80 | result = INLINE_SYSCALL (pread, 4, fd, CHECK_N (buf, count), count, offset); |
fe638fda | 81 | #else |
e3d6c581 | 82 | result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0, |
6f5d6cb6 GM |
83 | __LONG_LONG_PAIR ((off_t) (offset >> 32), |
84 | (off_t) (offset & 0xffffffff))); | |
fe638fda | 85 | #endif |
245061db AJ |
86 | # if __ASSUME_PREAD_SYSCALL == 0 |
87 | if (result == -1 && errno == ENOSYS) | |
88 | /* No system call available. Use the emulation. */ | |
89 | result = __emulate_pread64 (fd, buf, count, offset); | |
90 | # endif | |
8c5a1c78 UD |
91 | |
92 | LIBC_CANCEL_RESET (oldtype); | |
93 | ||
245061db AJ |
94 | return result; |
95 | } | |
96 | ||
97 | weak_alias (__libc_pread64, __pread64) | |
98 | weak_alias (__libc_pread64, pread64) | |
99 | ||
100 | # define __libc_pread64(fd, buf, count, offset) \ | |
101 | static internal_function __emulate_pread64 (fd, buf, count, offset) | |
102 | #endif | |
103 | ||
104 | #if __ASSUME_PREAD_SYSCALL == 0 | |
105 | # include <sysdeps/posix/pread64.c> | |
106 | #endif |