|
Packit |
7cfc04 |
.\" Copyright (C) 1999 Joseph Samuel Myers.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(VERBATIM)
|
|
Packit |
7cfc04 |
.\" Permission is granted to make and distribute verbatim copies of this
|
|
Packit |
7cfc04 |
.\" manual provided the copyright notice and this permission notice are
|
|
Packit |
7cfc04 |
.\" preserved on all copies.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Permission is granted to copy and distribute modified versions of this
|
|
Packit |
7cfc04 |
.\" manual under the conditions for verbatim copying, provided that the
|
|
Packit |
7cfc04 |
.\" entire resulting derived work is distributed under the terms of a
|
|
Packit |
7cfc04 |
.\" permission notice identical to this one.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
Packit |
7cfc04 |
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
Packit |
7cfc04 |
.\" responsibility for errors or omissions, or for damages resulting from
|
|
Packit |
7cfc04 |
.\" the use of the information contained herein. The author(s) may not
|
|
Packit |
7cfc04 |
.\" have taken the same level of care in the production of this manual,
|
|
Packit |
7cfc04 |
.\" which is licensed free of charge, as they might when working
|
|
Packit |
7cfc04 |
.\" professionally.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
Packit |
7cfc04 |
.\" the source, must acknowledge the copyright and authors of this work.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.TH PREAD 2 2017-09-15 "Linux" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
pread, pwrite \- read from or write to a file descriptor at a given offset
|
|
Packit |
7cfc04 |
.SH SYNOPSIS
|
|
Packit |
7cfc04 |
.B #include <unistd.h>
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI "ssize_t pread(int " fd ", void *" buf ", size_t " count \
|
|
Packit |
7cfc04 |
", off_t " offset );
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BI "ssize_t pwrite(int " fd ", const void *" buf ", size_t " count \
|
|
Packit |
7cfc04 |
", off_t " offset );
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in -4n
|
|
Packit |
7cfc04 |
Feature Test Macro Requirements for glibc (see
|
|
Packit |
7cfc04 |
.BR feature_test_macros (7)):
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.PD 0
|
|
Packit |
7cfc04 |
.ad l
|
|
Packit |
7cfc04 |
.BR pread (),
|
|
Packit |
7cfc04 |
.BR pwrite ():
|
|
Packit |
7cfc04 |
.RS 4
|
|
Packit |
7cfc04 |
_XOPEN_SOURCE\ >=\ 500
|
|
Packit |
7cfc04 |
.br
|
|
Packit |
7cfc04 |
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
|
|
Packit |
7cfc04 |
.RE
|
|
Packit |
7cfc04 |
.ad
|
|
Packit |
7cfc04 |
.PD
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
.BR pread ()
|
|
Packit |
7cfc04 |
reads up to
|
|
Packit |
7cfc04 |
.I count
|
|
Packit |
7cfc04 |
bytes from file descriptor
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
at offset
|
|
Packit |
7cfc04 |
.I offset
|
|
Packit |
7cfc04 |
(from the start of the file) into the buffer starting at
|
|
Packit |
7cfc04 |
.IR buf .
|
|
Packit |
7cfc04 |
The file offset is not changed.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
writes up to
|
|
Packit |
7cfc04 |
.I count
|
|
Packit |
7cfc04 |
bytes from the buffer starting at
|
|
Packit |
7cfc04 |
.I buf
|
|
Packit |
7cfc04 |
to the file descriptor
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
at offset
|
|
Packit |
7cfc04 |
.IR offset .
|
|
Packit |
7cfc04 |
The file offset is not changed.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The file referenced by
|
|
Packit |
7cfc04 |
.I fd
|
|
Packit |
7cfc04 |
must be capable of seeking.
|
|
Packit |
7cfc04 |
.SH RETURN VALUE
|
|
Packit |
7cfc04 |
On success,
|
|
Packit |
7cfc04 |
.BR pread ()
|
|
Packit |
7cfc04 |
returns the number of bytes read
|
|
Packit |
7cfc04 |
(a return of zero indicates end of file)
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
returns the number of bytes written.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Note that is not an error for a successful call to transfer fewer bytes
|
|
Packit |
7cfc04 |
than requested (see
|
|
Packit |
7cfc04 |
.BR read (2)
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR write (2)).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
On error, \-1 is returned and
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
is set to indicate the cause of the error.
|
|
Packit |
7cfc04 |
.SH ERRORS
|
|
Packit |
7cfc04 |
.BR pread ()
|
|
Packit |
7cfc04 |
can fail and set
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
to any error specified for
|
|
Packit |
7cfc04 |
.BR read (2)
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.BR lseek (2).
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
can fail and set
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
to any error specified for
|
|
Packit |
7cfc04 |
.BR write (2)
|
|
Packit |
7cfc04 |
or
|
|
Packit |
7cfc04 |
.BR lseek (2).
|
|
Packit |
7cfc04 |
.SH VERSIONS
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR pread ()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
system calls were added to Linux in
|
|
Packit |
7cfc04 |
version 2.1.60; the entries in the i386 system call table were added
|
|
Packit |
7cfc04 |
in 2.1.69.
|
|
Packit |
7cfc04 |
C library support (including emulation using
|
|
Packit |
7cfc04 |
.BR lseek (2)
|
|
Packit |
7cfc04 |
on older kernels without the system calls) was added in glibc 2.1.
|
|
Packit |
7cfc04 |
.SH CONFORMING TO
|
|
Packit |
7cfc04 |
POSIX.1-2001, POSIX.1-2008.
|
|
Packit |
7cfc04 |
.SH NOTES
|
|
Packit |
7cfc04 |
The
|
|
Packit |
7cfc04 |
.BR pread ()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
system calls are especially useful in multithreaded applications.
|
|
Packit |
7cfc04 |
They allow multiple threads to perform I/O on the same file descriptor
|
|
Packit |
7cfc04 |
without being affected by changes to the file offset by other threads.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.SS C library/kernel differences
|
|
Packit |
7cfc04 |
On Linux, the underlying system calls were renamed
|
|
Packit |
7cfc04 |
in kernel 2.6:
|
|
Packit |
7cfc04 |
.BR pread ()
|
|
Packit |
7cfc04 |
became
|
|
Packit |
7cfc04 |
.BR pread64 (),
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
became
|
|
Packit |
7cfc04 |
.BR pwrite64 ().
|
|
Packit |
7cfc04 |
The system call numbers remained the same.
|
|
Packit |
7cfc04 |
The glibc
|
|
Packit |
7cfc04 |
.BR pread ()
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
wrapper functions transparently deal with the change.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
On some 32-bit architectures,
|
|
Packit |
7cfc04 |
the calling signature for these system calls differ,
|
|
Packit |
7cfc04 |
for the reasons described in
|
|
Packit |
7cfc04 |
.BR syscall (2).
|
|
Packit |
7cfc04 |
.SH BUGS
|
|
Packit |
7cfc04 |
POSIX requires that opening a file with the
|
|
Packit |
7cfc04 |
.BR O_APPEND
|
|
Packit |
7cfc04 |
flag should have no effect on the location at which
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
writes data.
|
|
Packit |
7cfc04 |
However, on Linux, if a file is opened with
|
|
Packit |
7cfc04 |
.\" FIXME . https://bugzilla.kernel.org/show_bug.cgi?id=43178
|
|
Packit |
7cfc04 |
.BR O_APPEND ,
|
|
Packit |
7cfc04 |
.BR pwrite ()
|
|
Packit |
7cfc04 |
appends data to the end of the file, regardless of the value of
|
|
Packit |
7cfc04 |
.IR offset .
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.BR lseek (2),
|
|
Packit |
7cfc04 |
.BR read (2),
|
|
Packit |
7cfc04 |
.BR readv (2),
|
|
Packit |
7cfc04 |
.BR write (2)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|