Update.
[glibc.git] / sysdeps / unix / sysv / linux / mips / pwrite.c
blob3c0eba57578e1cd62a07f5bb751f3b1ce8adb471
1 /* Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <assert.h>
21 #include <errno.h>
22 #include <unistd.h>
23 #include <endian.h>
25 #include <sysdep-cancel.h>
26 #include <sys/syscall.h>
27 #include <bp-checks.h>
29 #include <kernel-features.h>
31 #ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
32 # ifdef __NR_pwrite
33 # error "__NR_pwrite and __NR_pwrite64 both defined???"
34 # endif
35 # define __NR_pwrite __NR_pwrite64
36 #endif
38 #if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
40 # if __ASSUME_PWRITE_SYSCALL == 0
41 static ssize_t __emulate_pwrite (int fd, const void *buf, size_t count,
42 off_t offset) internal_function;
43 # endif
45 ssize_t
46 __libc_pwrite (fd, buf, count, offset)
47 int fd;
48 const void *buf;
49 size_t count;
50 off_t offset;
52 ssize_t result;
54 #if (defined _ABI64 && _MIPS_SIM != _ABI64)
55 assert (sizeof (offset) == 4);
56 #endif
58 if (SINGLE_THREAD_P)
60 /* First try the syscall. */
61 #if (defined _ABIN32 && _MIPS_SIM == _ABIN32) || (defined _ABI64 && _MIPS_SIM == _ABI64)
62 result = INLINE_SYSCALL (pwrite, 4, fd, CHECK_N (buf, count), count,
63 offset);
64 #else
65 result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
66 __LONG_LONG_PAIR (offset >> 31, offset));
67 #endif
68 # if __ASSUME_PWRITE_SYSCALL == 0
69 if (result == -1 && errno == ENOSYS)
70 /* No system call available. Use the emulation. */
71 result = __emulate_pwrite (fd, buf, count, offset);
72 # endif
73 return result;
76 int oldtype = LIBC_CANCEL_ASYNC ();
78 /* First try the syscall. */
79 #if (defined _ABIN32 && _MIPS_SIM == _ABIN32) || (defined _ABI64 && _MIPS_SIM == _ABI64)
80 result = INLINE_SYSCALL (pwrite, 4, fd, CHECK_N (buf, count), count, offset);
81 #else
82 result = INLINE_SYSCALL (pwrite, 6, fd, CHECK_N (buf, count), count, 0,
83 __LONG_LONG_PAIR (offset >> 31, offset));
84 #endif
85 # if __ASSUME_PWRITE_SYSCALL == 0
86 if (result == -1 && errno == ENOSYS)
87 /* No system call available. Use the emulation. */
88 result = __emulate_pwrite (fd, buf, count, offset);
89 # endif
91 LIBC_CANCEL_RESET (oldtype);
93 return result;
96 strong_alias (__libc_pwrite, __pwrite)
97 weak_alias (__libc_pwrite, pwrite)
99 # define __libc_pwrite(fd, buf, count, offset) \
100 static internal_function __emulate_pwrite (fd, buf, count, offset)
101 #endif
103 #if __ASSUME_PWRITE_SYSCALL == 0
104 # include <sysdeps/posix/pwrite.c>
105 #endif