2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / sh / pread.c
blob0186e40c9c64f131d3b888c6f970dd4996a8cdba
1 /* Copyright (C) 1997, 1998, 2000, 2002, 2003, 2004, 2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
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.
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
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <assert.h>
22 #include <errno.h>
23 #include <unistd.h>
24 #include <endian.h>
26 #include <sysdep-cancel.h>
27 #include <sys/syscall.h>
28 #include <bp-checks.h>
30 #include <kernel-features.h>
32 #ifdef __NR_pread64 /* Newer kernels renamed but it's the same. */
33 # ifdef __NR_pread
34 # error "__NR_pread and __NR_pread64 both defined???"
35 # endif
36 # define __NR_pread __NR_pread64
37 #endif
39 #if defined __NR_pread || __ASSUME_PREAD_SYSCALL > 0
41 # if __ASSUME_PREAD_SYSCALL == 0
42 static ssize_t __emulate_pread (int fd, void *buf, size_t count,
43 off_t offset) internal_function;
44 # endif
46 ssize_t
47 __libc_pread (fd, buf, count, offset)
48 int fd;
49 void *buf;
50 size_t count;
51 off_t offset;
53 ssize_t result;
55 if (SINGLE_THREAD_P)
57 /* First try the syscall. */
58 result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
59 __LONG_LONG_PAIR (offset >> 31, offset));
60 # if __ASSUME_PREAD_SYSCALL == 0
61 if (result == -1 && errno == ENOSYS)
62 /* No system call available. Use the emulation. */
63 result = __emulate_pread (fd, buf, count, offset);
64 # endif
65 return result;
68 int oldtype = LIBC_CANCEL_ASYNC ();
70 /* First try the syscall. */
71 result = INLINE_SYSCALL (pread, 6, fd, CHECK_N (buf, count), count, 0,
72 __LONG_LONG_PAIR (offset >> 31, offset));
73 # if __ASSUME_PREAD_SYSCALL == 0
74 if (result == -1 && errno == ENOSYS)
75 /* No system call available. Use the emulation. */
76 result = __emulate_pread (fd, buf, count, offset);
77 # endif
79 LIBC_CANCEL_RESET (oldtype);
81 return result;
84 strong_alias (__libc_pread, __pread)
85 weak_alias (__libc_pread, pread)
87 # define __libc_pread(fd, buf, count, offset) \
88 static internal_function __emulate_pread (fd, buf, count, offset)
89 #endif
91 #if __ASSUME_PREAD_SYSCALL == 0
92 # include <sysdeps/posix/pread.c>
93 #endif