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       ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       pread(), pwrite():
18           _XOPEN_SOURCE >= 500
19               || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
20

DESCRIPTION

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

RETURN VALUE

33       On success, pread() returns the number of bytes read (a return of  zero
34       indicates  end  of file) and pwrite() returns the number of bytes writ‐
35       ten.
36
37       Note that it is not an error for a successful call  to  transfer  fewer
38       bytes than requested (see read(2) and write(2)).
39
40       On error, -1 is returned and errno is set to indicate the error.
41

ERRORS

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

VERSIONS

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

CONFORMING TO

54       POSIX.1-2001, POSIX.1-2008.
55

NOTES

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

BUGS

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

SEE ALSO

78       lseek(2), read(2), readv(2), write(2)
79

COLOPHON

81       This page is part of release 5.13 of the Linux  man-pages  project.   A
82       description  of  the project, information about reporting bugs, and the
83       latest    version    of    this    page,    can     be     found     at
84       https://www.kernel.org/doc/man-pages/.
85
86
87
88Linux                             2021-03-22                          PREAD(2)
Impressum