]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/pwrite.c
Replace FSF snail mail address with URLs.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / pwrite.c
CommitLineData
6ddd37a4 1/* Copyright (C) 1997-2000,2002,2003,2004,2006 Free Software Foundation, Inc.
af6f3906
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
af6f3906
UD
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
41bdb6e2 13 Lesser General Public License for more details.
af6f3906 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
af6f3906 18
cd682e15 19#include <assert.h>
d71b808a 20#include <errno.h>
741845cb 21#include <endian.h>
af6f3906 22#include <unistd.h>
0dee6738 23
6ee8d334 24#include <sysdep-cancel.h>
36ecfe56 25#include <sys/syscall.h>
4bbb61e4 26#include <bp-checks.h>
36ecfe56 27
6ddd37a4 28#include <kernel-features.h>
958f238f 29
4b172769
RM
30#ifdef __NR_pwrite64 /* Newer kernels renamed but it's the same. */
31# ifdef __NR_pwrite
32# error "__NR_pwrite and __NR_pwrite64 both defined???"
33# endif
0f0d786f 34# define __NR_pwrite __NR_pwrite64
4b172769
RM
35#endif
36
958f238f 37#if defined __NR_pwrite || __ASSUME_PWRITE_SYSCALL > 0
af6f3906 38
958f238f 39# if __ASSUME_PWRITE_SYSCALL == 0
d71b808a
UD
40static ssize_t __emulate_pwrite (int fd, const void *buf, size_t count,
41 off_t offset) internal_function;
958f238f 42# endif
d71b808a
UD
43
44
6ee8d334 45static ssize_t
ce6e047f
UD
46#ifdef NO_CANCELLATION
47inline __attribute ((always_inline))
48#endif
6ee8d334 49do_pwrite (int fd, const void *buf, size_t count, off_t offset)
af6f3906 50{
d71b808a
UD
51 ssize_t result;
52
53 /* First try the syscall. */
cd682e15 54 assert (sizeof (offset) == 4);
4bbb61e4 55 result = INLINE_SYSCALL (pwrite, 5, fd, CHECK_N (buf, count), count,
cd682e15 56 __LONG_LONG_PAIR (offset >> 31, offset));
958f238f 57# if __ASSUME_PWRITE_SYSCALL == 0
d71b808a
UD
58 if (result == -1 && errno == ENOSYS)
59 /* No system call available. Use the emulation. */
60 result = __emulate_pwrite (fd, buf, count, offset);
958f238f 61# endif
d71b808a
UD
62
63 return result;
af6f3906
UD
64}
65
6ee8d334
UD
66
67ssize_t
68__libc_pwrite (fd, buf, count, offset)
69 int fd;
70 const void *buf;
71 size_t count;
72 off_t offset;
73{
74 if (SINGLE_THREAD_P)
75 return do_pwrite (fd, buf, count, offset);
76
77 int oldtype = LIBC_CANCEL_ASYNC ();
78
79 ssize_t result = do_pwrite (fd, buf, count, offset);
80
81 LIBC_CANCEL_RESET (oldtype);
82
83 return result;
84}
85
778c59c8
UD
86strong_alias (__libc_pwrite, __pwrite)
87weak_alias (__libc_pwrite, pwrite)
d71b808a 88
778c59c8 89# define __libc_pwrite(fd, buf, count, offset) \
d71b808a 90 static internal_function __emulate_pwrite (fd, buf, count, offset)
36ecfe56 91#endif
958f238f
UD
92
93#if __ASSUME_PWRITE_SYSCALL == 0
94# include <sysdeps/posix/pwrite.c>
95#endif