1 .\" Copyright (C) 1999 Joseph Samuel Myers.
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH PREAD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
27 pread, pwrite \- read from or write to a file descriptor at a given offset
29 .B #include <unistd.h>
31 .BI "ssize_t pread(int " fd ", void *" buf ", size_t " count \
34 .BI "ssize_t pwrite(int " fd ", const void *" buf ", size_t " count \
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
47 _XOPEN_SOURCE\ >=\ 500
49 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
57 bytes from file descriptor
61 (from the start of the file) into the buffer starting at
63 The file offset is not changed.
68 bytes from the buffer starting at
70 to the file descriptor
74 The file offset is not changed.
76 The file referenced by
78 must be capable of seeking.
82 returns the number of bytes read
83 (a return of zero indicates end of file)
86 returns the number of bytes written.
88 Note that it is not an error for a successful call to transfer fewer bytes
94 On error, \-1 is returned and
96 is set to indicate the cause of the error.
101 to any error specified for
108 to any error specified for
117 system calls were added to Linux in
118 version 2.1.60; the entries in the i386 system call table were added
120 C library support (including emulation using
122 on older kernels without the system calls) was added in glibc 2.1.
124 POSIX.1-2001, POSIX.1-2008.
130 system calls are especially useful in multithreaded applications.
131 They allow multiple threads to perform I/O on the same file descriptor
132 without being affected by changes to the file offset by other threads.
134 .SS C library/kernel differences
135 On Linux, the underlying system calls were renamed
144 The system call numbers remained the same.
149 wrapper functions transparently deal with the change.
151 On some 32-bit architectures,
152 the calling signature for these system calls differ,
153 for the reasons described in
156 POSIX requires that opening a file with the
158 flag should have no effect on the location at which
161 However, on Linux, if a file is opened with
162 .\" FIXME . https://bugzilla.kernel.org/show_bug.cgi?id=43178
165 appends data to the end of the file, regardless of the value of