276 lines
5.5 KiB
HTML
276 lines
5.5 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of PREAD</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>PREAD</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
pread, pwrite - read from or write to a file descriptor at a given offset
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>ssize_t pread(int </B><I>fd</I><B>, void *</B><I>buf</I><B>, size_t </B><I>count</I><B>, off_t </B><I>offset</I><B>);</B>
|
|
|
|
<P>
|
|
|
|
<B>ssize_t pwrite(int </B><I>fd</I><B>, const void *</B><I>buf</I><B>, size_t </B><I>count</I><B>, off_t </B><I>offset</I><B>);</B>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
|
|
|
|
<B>pread</B>(),
|
|
|
|
<B>pwrite</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_XOPEN_SOURCE >= 500
|
|
<BR>
|
|
|
|
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
|
|
</DL>
|
|
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>pread</B>()
|
|
|
|
reads up to
|
|
<I>count</I>
|
|
|
|
bytes from file descriptor
|
|
<I>fd</I>
|
|
|
|
at offset
|
|
<I>offset</I>
|
|
|
|
(from the start of the file) into the buffer starting at
|
|
<I>buf</I>.
|
|
|
|
The file offset is not changed.
|
|
<P>
|
|
|
|
<B>pwrite</B>()
|
|
|
|
writes up to
|
|
<I>count</I>
|
|
|
|
bytes from the buffer starting at
|
|
<I>buf</I>
|
|
|
|
to the file descriptor
|
|
<I>fd</I>
|
|
|
|
at offset
|
|
<I>offset</I>.
|
|
|
|
The file offset is not changed.
|
|
<P>
|
|
|
|
The file referenced by
|
|
<I>fd</I>
|
|
|
|
must be capable of seeking.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>pread</B>()
|
|
|
|
returns the number of bytes read
|
|
(a return of zero indicates end of file)
|
|
and
|
|
<B>pwrite</B>()
|
|
|
|
returns the number of bytes written.
|
|
<P>
|
|
|
|
Note that it is not an error for a successful call to transfer fewer bytes
|
|
than requested (see
|
|
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?2+write">write</A></B>(2)).
|
|
|
|
<P>
|
|
|
|
On error, -1 is returned and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the cause of the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<B>pread</B>()
|
|
|
|
can fail and set
|
|
<I>errno</I>
|
|
|
|
to any error specified for
|
|
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2)
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?2+lseek">lseek</A></B>(2).
|
|
|
|
<B>pwrite</B>()
|
|
|
|
can fail and set
|
|
<I>errno</I>
|
|
|
|
to any error specified for
|
|
<B><A HREF="/cgi-bin/man/man2html?2+write">write</A></B>(2)
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?2+lseek">lseek</A></B>(2).
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
The
|
|
<B>pread</B>()
|
|
|
|
and
|
|
<B>pwrite</B>()
|
|
|
|
system calls were added to Linux in
|
|
version 2.1.60; the entries in the i386 system call table were added
|
|
in 2.1.69.
|
|
C library support (including emulation using
|
|
<B><A HREF="/cgi-bin/man/man2html?2+lseek">lseek</A></B>(2)
|
|
|
|
on older kernels without the system calls) was added in glibc 2.1.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The
|
|
<B>pread</B>()
|
|
|
|
and
|
|
<B>pwrite</B>()
|
|
|
|
system calls are especially useful in multithreaded applications.
|
|
They allow multiple threads to perform I/O on the same file descriptor
|
|
without being affected by changes to the file offset by other threads.
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>C library/kernel differences</H3>
|
|
|
|
On Linux, the underlying system calls were renamed
|
|
in kernel 2.6:
|
|
<B>pread</B>()
|
|
|
|
became
|
|
<B>pread64</B>(),
|
|
|
|
and
|
|
<B>pwrite</B>()
|
|
|
|
became
|
|
<B>pwrite64</B>().
|
|
|
|
The system call numbers remained the same.
|
|
The glibc
|
|
<B>pread</B>()
|
|
|
|
and
|
|
<B>pwrite</B>()
|
|
|
|
wrapper functions transparently deal with the change.
|
|
<P>
|
|
|
|
On some 32-bit architectures,
|
|
the calling signature for these system calls differ,
|
|
for the reasons described in
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
POSIX requires that opening a file with the
|
|
<B>O_APPEND</B>
|
|
|
|
flag should have no effect on the location at which
|
|
<B>pwrite</B>()
|
|
|
|
writes data.
|
|
However, on Linux, if a file is opened with
|
|
|
|
<B>O_APPEND</B>,
|
|
|
|
<B>pwrite</B>()
|
|
|
|
appends data to the end of the file, regardless of the value of
|
|
<I>offset</I>.
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+lseek">lseek</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+readv">readv</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+write">write</A></B>(2)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="8"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="10"><A HREF="#lbAJ">C library/kernel differences</A><DD>
|
|
</DL>
|
|
<DT id="11"><A HREF="#lbAK">BUGS</A><DD>
|
|
<DT id="12"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="13"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:33 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|