OSDN Git Service

7be04cfa6fe89fb43e77e15cd578065a655b2425
[linuxjm/LDP_man-pages.git] / original / 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 2013-06-21 "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 .sp
31 .BI "ssize_t pread(int " fd ", void *" buf ", size_t " count \
32 ", off_t " offset );
33 .sp
34 .BI "ssize_t pwrite(int " fd ", const void *" buf ", size_t " count \
35 ", off_t " offset );
36 .sp
37 .in -4n
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
40 .in
41 .PD 0
42 .ad l
43 .sp
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, the number of bytes read or written is returned (zero
81 indicates that nothing was written, in the case of
82 .BR pwrite (),
83 or
84 end of file, in the case of
85 .BR pread ()),
86 or \-1 on error, in which case
87 .I errno
88 is set to indicate the error.
89 .SH ERRORS
90 .BR pread ()
91 can fail and set
92 .I errno
93 to any error specified for
94 .BR read (2)
95 or
96 .BR lseek (2).
97 .BR pwrite ()
98 can fail and set
99 .I errno
100 to any error specified for
101 .BR write (2)
102 or
103 .BR lseek (2).
104 .SH VERSIONS
105 The
106 .BR pread ()
107 and
108 .BR pwrite ()
109 system calls were added to Linux in
110 version 2.1.60; the entries in the i386 system call table were added
111 in 2.1.69.
112 C library support (including emulation using
113 .BR lseek (2)
114 on older kernels without the system calls) was added in glibc 2.1.
115 .SH CONFORMING TO
116 POSIX.1-2001.
117 .SH NOTES
118 The
119 .BR pread ()
120 and
121 .BR pwrite ()
122 system calls are especially useful in multithreaded applications.
123 They allow multiple threads to perform I/O on the same file descriptor
124 without being affected by changes to the file offset by other threads.
125
126 On Linux, the underlying system calls were renamed
127 in kernel 2.6:
128 .BR pread ()
129 became
130 .BR pread64 (),
131 and
132 .BR pwrite ()
133 became
134 .BR pwrite64 ().
135 The system call numbers remained the same.
136 The glibc
137 .BR pread ()
138 and
139 .BR pwrite ()
140 wrapper functions transparently deal with the change.
141
142 On some 32-bit architectures,
143 the calling signature for these system calls differ,
144 for the reasons described in
145 .BR syscall (2).
146 .SH BUGS
147 POSIX requires that opening a file with the
148 .BR O_APPEND
149 flag should have no affect on the location at which
150 .BR pwrite ()
151 writes data.
152 However, on Linux, if a file is opened with
153 .\" FIXME https://bugzilla.kernel.org/show_bug.cgi?id=43178
154 .BR O_APPEND ,
155 .BR pwrite ()
156 appends data to the end of the file, regardless of the value of
157 .IR offset .
158 .SH SEE ALSO
159 .BR lseek (2),
160 .BR read (2),
161 .BR readv (2),
162 .BR write (2)
163 .SH COLOPHON
164 This page is part of release 3.67 of the Linux
165 .I man-pages
166 project.
167 A description of the project,
168 information about reporting bugs,
169 and the latest version of this page,
170 can be found at
171 \%http://www.kernel.org/doc/man\-pages/.