2.9
[glibc/nacl-glibc.git] / sysdeps / unix / sysv / linux / sh / pwrite.c
blobf0e2bc7e0f512dcfb395aa637c3f4b4af8bad647
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_pwrite64 /* Newer kernels renamed but it's the same. */
33 # ifdef __NR_pwrite
34 # error "__NR_pwrite and __NR_pwrite64 both defined???"
35 # endif
36 # define __NR_pwrite __NR_pwrite64
37 #endif
39 #if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
41 # if __ASSUME_PWRITE_SYSCALL == 0
42 static ssize_t __emulate_pwrite (int fd, const void *buf, size_t count,
43 off_t offset) internal_function;
44 # endif
46 ssize_t
47 __libc_pwrite (fd, buf, count, offset)
48 int fd;
49 const 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 (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
59 __LONG_LONG_PAIR (offset >> 31, offset));
60 # if __ASSUME_PWRITE_SYSCALL == 0
61 if (result == -1 && errno == ENOSYS)
62 /* No system call available. Use the emulation. */
63 result = __emulate_pwrite (fd, buf, count, offset);
64 # endif
65 return result;
68 int oldtype = LIBC_CANCEL_ASYNC ();
70 /* First try the syscall. */
71 result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
72 __LONG_LONG_PAIR (offset >> 31, offset));
73 # if __ASSUME_PWRITE_SYSCALL == 0
74 if (result == -1 && errno == ENOSYS)
75 /* No system call available. Use the emulation. */
76 result = __emulate_pwrite (fd, buf, count, offset);
77 # endif
79 LIBC_CANCEL_RESET (oldtype);
81 return result;
84 strong_alias (__libc_pwrite, __pwrite)
85 weak_alias (__libc_pwrite, pwrite)
87 # define __libc_pwrite(fd, buf, count, offset) \
88 static internal_function __emulate_pwrite (fd, buf, count, offset)
89 #endif
91 #if __ASSUME_PWRITE_SYSCALL == 0
92 # include <sysdeps/posix/pwrite.c>
93 #endif