1PREAD(2)                   Linux Programmer's Manual                  PREAD(2)
2
3
4

NAME

6       pread, pwrite - read from or write to a file descriptor at a given off‐
7       set
8

SYNOPSIS

10       #include <unistd.h>
11
12       ssize_t pread(int fd, void *buf, size_t count, off_t offset);
13
14       ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
15
16   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18       pread(), pwrite():
19           _XOPEN_SOURCE >= 500
20           || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
21

DESCRIPTION

23       pread() reads up to count bytes from file descriptor fd at offset  off‐
24       set  (from the start of the file) into the buffer starting at buf.  The
25       file offset is not changed.
26
27       pwrite() writes up to count bytes from the buffer starting  at  buf  to
28       the  file  descriptor  fd  at  offset  offset.   The file offset is not
29       changed.
30
31       The file referenced by fd must be capable of seeking.
32

RETURN VALUE

34       On success, the number of bytes read or written is returned (zero indi‐
35       cates  that  nothing  was  written,  in the case of pwrite(), or end of
36       file, in the case of pread()), or -1 on error, in which case  errno  is
37       set to indicate the error.
38

ERRORS

40       pread()  can  fail  and set errno to any error specified for read(2) or
41       lseek(2).  pwrite() can fail and set errno to any error  specified  for
42       write(2) or lseek(2).
43

VERSIONS

45       The  pread()  and  pwrite() system calls were added to Linux in version
46       2.1.60; the entries in the i386 system call table were added in 2.1.69.
47       C  library support (including emulation using lseek(2) on older kernels
48       without the system calls) was added in glibc 2.1.
49

CONFORMING TO

51       POSIX.1-2001.
52

NOTES

54       The pread() and pwrite() system calls are especially useful  in  multi‐
55       threaded  applications.   They allow multiple threads to perform I/O on
56       the same file descriptor without being affected by changes to the  file
57       offset by other threads.
58
59       On  Linux,  the  underlying  system  calls  were renamed in kernel 2.6:
60       pread() became pread64(), and pwrite() became pwrite64().   The  system
61       call numbers remained the same.  The glibc pread() and pwrite() wrapper
62       functions transparently deal with the change.
63
64       On some 32-bit architectures, the calling signature  for  these  system
65       calls differ, for the reasons described in syscall(2).
66

BUGS

68       POSIX  requires  that opening a file with the O_APPEND flag should have
69       no affect on the location at which pwrite() writes data.   However,  on
70       Linux,  if a file is opened with O_APPEND, pwrite() appends data to the
71       end of the file, regardless of the value of offset.
72

SEE ALSO

74       lseek(2), read(2), readv(2), write(2)
75

COLOPHON

77       This page is part of release 3.53 of the Linux  man-pages  project.   A
78       description  of  the project, and information about reporting bugs, can
79       be found at http://www.kernel.org/doc/man-pages/.
80
81
82
83Linux                             2013-06-21                          PREAD(2)
Impressum