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, pread() returns the number of bytes read (a return of  zero
35       indicates  end  of file) and pwrite() returns the number of bytes writ‐
36       ten.
37
38       Note that is not an error for a successful call to transfer fewer bytes
39       than requested (see read(2) and write(2)).
40
41       On  error, -1 is returned and errno is set to indicate the cause of the
42       error.
43

ERRORS

45       pread() can fail and set errno to any error specified  for  read(2)  or
46       lseek(2).   pwrite()  can fail and set errno to any error specified for
47       write(2) or lseek(2).
48

VERSIONS

50       The pread() and pwrite() system calls were added to  Linux  in  version
51       2.1.60; the entries in the i386 system call table were added in 2.1.69.
52       C library support (including emulation using lseek(2) on older  kernels
53       without the system calls) was added in glibc 2.1.
54

CONFORMING TO

56       POSIX.1-2001, POSIX.1-2008.
57

NOTES

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

BUGS

74       POSIX requires that opening a file with the O_APPEND flag  should  have
75       no  effect  on the location at which pwrite() writes data.  However, on
76       Linux, if a file is opened with O_APPEND, pwrite() appends data to  the
77       end of the file, regardless of the value of offset.
78

SEE ALSO

80       lseek(2), read(2), readv(2), write(2)
81

COLOPHON

83       This  page  is  part of release 4.16 of the Linux man-pages project.  A
84       description of the project, information about reporting bugs,  and  the
85       latest     version     of     this    page,    can    be    found    at
86       https://www.kernel.org/doc/man-pages/.
87
88
89
90Linux                             2017-09-15                          PREAD(2)
Impressum