]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/pread.2
sched_setattr.2: tfix
[thirdparty/man-pages.git] / man2 / pread.2
1 .\" Copyright (C) 1999 Joseph Samuel Myers.
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH PREAD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 pread, pwrite \- read from or write to a file descriptor at a given offset
28 .SH SYNOPSIS
29 .B #include <unistd.h>
30 .PP
31 .BI "ssize_t pread(int " fd ", void *" buf ", size_t " count \
32 ", off_t " offset );
33 .PP
34 .BI "ssize_t pwrite(int " fd ", const void *" buf ", size_t " count \
35 ", off_t " offset );
36 .PP
37 .in -4n
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
40 .in
41 .PP
42 .PD 0
43 .ad l
44 .BR pread (),
45 .BR pwrite ():
46 .RS 4
47 _XOPEN_SOURCE\ >=\ 500
48 .br
49 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
50 .RE
51 .ad
52 .PD
53 .SH DESCRIPTION
54 .BR pread ()
55 reads up to
56 .I count
57 bytes from file descriptor
58 .I fd
59 at offset
60 .I offset
61 (from the start of the file) into the buffer starting at
62 .IR buf .
63 The file offset is not changed.
64 .PP
65 .BR pwrite ()
66 writes up to
67 .I count
68 bytes from the buffer starting at
69 .I buf
70 to the file descriptor
71 .I fd
72 at offset
73 .IR offset .
74 The file offset is not changed.
75 .PP
76 The file referenced by
77 .I fd
78 must be capable of seeking.
79 .SH RETURN VALUE
80 On success,
81 .BR pread ()
82 returns the number of bytes read
83 (a return of zero indicates end of file)
84 and
85 .BR pwrite ()
86 returns the number of bytes written.
87 .PP
88 Note that it is not an error for a successful call to transfer fewer bytes
89 than requested (see
90 .BR read (2)
91 and
92 .BR write (2)).
93 .PP
94 On error, \-1 is returned and
95 .I errno
96 is set to indicate the cause of the error.
97 .SH ERRORS
98 .BR pread ()
99 can fail and set
100 .I errno
101 to any error specified for
102 .BR read (2)
103 or
104 .BR lseek (2).
105 .BR pwrite ()
106 can fail and set
107 .I errno
108 to any error specified for
109 .BR write (2)
110 or
111 .BR lseek (2).
112 .SH VERSIONS
113 The
114 .BR pread ()
115 and
116 .BR pwrite ()
117 system calls were added to Linux in
118 version 2.1.60; the entries in the i386 system call table were added
119 in 2.1.69.
120 C library support (including emulation using
121 .BR lseek (2)
122 on older kernels without the system calls) was added in glibc 2.1.
123 .SH CONFORMING TO
124 POSIX.1-2001, POSIX.1-2008.
125 .SH NOTES
126 The
127 .BR pread ()
128 and
129 .BR pwrite ()
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.
133 .\"
134 .SS C library/kernel differences
135 On Linux, the underlying system calls were renamed
136 in kernel 2.6:
137 .BR pread ()
138 became
139 .BR pread64 (),
140 and
141 .BR pwrite ()
142 became
143 .BR pwrite64 ().
144 The system call numbers remained the same.
145 The glibc
146 .BR pread ()
147 and
148 .BR pwrite ()
149 wrapper functions transparently deal with the change.
150 .PP
151 On some 32-bit architectures,
152 the calling signature for these system calls differ,
153 for the reasons described in
154 .BR syscall (2).
155 .SH BUGS
156 POSIX requires that opening a file with the
157 .BR O_APPEND
158 flag should have no effect on the location at which
159 .BR pwrite ()
160 writes data.
161 However, on Linux, if a file is opened with
162 .\" FIXME . https://bugzilla.kernel.org/show_bug.cgi?id=43178
163 .BR O_APPEND ,
164 .BR pwrite ()
165 appends data to the end of the file, regardless of the value of
166 .IR offset .
167 .SH SEE ALSO
168 .BR lseek (2),
169 .BR read (2),
170 .BR readv (2),
171 .BR write (2)