2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (C) 1999 Joseph Samuel Myers.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
2007-04-12 22:42:49 +00:00
|
|
|
.\"
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
2012-04-29 19:47:27 +00:00
|
|
|
.TH PREAD 2 2012-04-30 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
pread, pwrite \- read from or write to a file descriptor at a given offset
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <unistd.h>
|
|
|
|
.sp
|
2008-07-06 14:54:26 +00:00
|
|
|
.BI "ssize_t pread(int " fd ", void *" buf ", size_t " count \
|
|
|
|
", off_t " offset );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
2008-07-06 14:54:26 +00:00
|
|
|
.BI "ssize_t pwrite(int " fd ", const void *" buf ", size_t " count \
|
|
|
|
", off_t " offset );
|
2010-09-18 03:35:39 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
.in
|
|
|
|
.PD 0
|
|
|
|
.ad l
|
|
|
|
.sp
|
|
|
|
.BR pread (),
|
|
|
|
.BR pwrite ():
|
|
|
|
.RS 4
|
brk.2, chroot.2, faccessat.2, fchmodat.2, fchownat.2, fstatat.2, futimesat.2, getdtablesize.2, getpagesize.2, getsid.2, linkat.2, mkdirat.2, mknodat.2, openat.2, pread.2, readlinkat.2, renameat.2, setpgid.2, sigaltstack.2, symlinkat.2, sync.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, unlinkat.2, utimensat.2, vfork.2, acosh.3, asinh.3, atanh.3, dirfd.3, dprintf.3, ecvt.3, expm1.3, fexecve.3, fmemopen.3, gcvt.3, getcwd.3, gethostid.3, getpass.3, getsubopt.3, getw.3, mbsnrtowcs.3, mkfifoat.3, mkstemp.3, mktemp.3, opendir.3, posix_memalign.3, rint.3, siginterrupt.3, stpcpy.3, stpncpy.3, strdup.3, strerror.3, strnlen.3, strsignal.3, strtol.3, strtoul.3, ualarm.3, usleep.3, wcpcpy.3, wcpncpy.3, wcscasecmp.3, wcsdup.3, wcsncasecmp.3, wcsnlen.3, wcsnrtombs.3: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 06:02:38 +00:00
|
|
|
_XOPEN_SOURCE\ >=\ 500
|
chdir.2, chmod.2, chown.2, gethostname.2, getsid.2, pread.2, setpgid.2, sigaltstack.2, stat.2, truncate.2, wait.2, dirfd.3, getsubopt.3, mkdtemp.3, mkstemp.3, siginterrupt.3, strdup.3: Simplify feature test macro requirements
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-26 15:16:57 +00:00
|
|
|
.br
|
|
|
|
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
|
2010-09-18 03:35:39 +00:00
|
|
|
.RE
|
|
|
|
.ad
|
|
|
|
.PD
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR pread ()
|
2004-11-03 13:51:07 +00:00
|
|
|
reads up to
|
|
|
|
.I count
|
|
|
|
bytes from file descriptor
|
|
|
|
.I fd
|
|
|
|
at offset
|
|
|
|
.I offset
|
|
|
|
(from the start of the file) into the buffer starting at
|
|
|
|
.IR buf .
|
|
|
|
The file offset is not changed.
|
|
|
|
.PP
|
2005-10-19 07:07:02 +00:00
|
|
|
.BR pwrite ()
|
2004-11-03 13:51:07 +00:00
|
|
|
writes up to
|
|
|
|
.I count
|
|
|
|
bytes from the buffer starting at
|
|
|
|
.I buf
|
|
|
|
to the file descriptor
|
|
|
|
.I fd
|
|
|
|
at offset
|
|
|
|
.IR offset .
|
|
|
|
The file offset is not changed.
|
|
|
|
.PP
|
|
|
|
The file referenced by
|
|
|
|
.I fd
|
|
|
|
must be capable of seeking.
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
On success, the number of bytes read or written is returned (zero
|
2007-05-12 09:06:04 +00:00
|
|
|
indicates that nothing was written, in the case of
|
|
|
|
.BR pwrite (),
|
|
|
|
or
|
2007-05-12 13:19:09 +00:00
|
|
|
end of file, in the case of
|
2010-06-12 12:35:03 +00:00
|
|
|
.BR pread ()),
|
2007-05-12 13:19:09 +00:00
|
|
|
or \-1 on error, in which case
|
2004-11-03 13:51:07 +00:00
|
|
|
.I errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.SH ERRORS
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR pread ()
|
2004-11-03 13:51:07 +00:00
|
|
|
can fail and set
|
|
|
|
.I errno
|
2007-05-12 09:06:04 +00:00
|
|
|
to any error specified for
|
|
|
|
.BR read (2)
|
|
|
|
or
|
|
|
|
.BR lseek (2).
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR pwrite ()
|
2004-11-03 13:51:07 +00:00
|
|
|
can fail and set
|
|
|
|
.I errno
|
2007-05-12 09:06:04 +00:00
|
|
|
to any error specified for
|
|
|
|
.BR write (2)
|
|
|
|
or
|
|
|
|
.BR lseek (2).
|
2007-05-18 11:59:14 +00:00
|
|
|
.SH VERSIONS
|
2007-05-12 09:06:04 +00:00
|
|
|
The
|
|
|
|
.BR pread ()
|
|
|
|
and
|
|
|
|
.BR pwrite ()
|
|
|
|
system calls were added to Linux in
|
2004-11-03 13:51:07 +00:00
|
|
|
version 2.1.60; the entries in the i386 system call table were added
|
2007-04-24 16:44:51 +00:00
|
|
|
in 2.1.69.
|
2008-12-05 20:01:19 +00:00
|
|
|
C library support (including emulation using
|
2008-12-03 19:25:03 +00:00
|
|
|
.BR lseek (2)
|
|
|
|
on older kernels without the system calls) was added in glibc 2.1.
|
2007-05-18 16:06:42 +00:00
|
|
|
.SH "CONFORMING TO"
|
|
|
|
POSIX.1-2001.
|
2010-11-21 05:39:03 +00:00
|
|
|
.SH NOTES
|
|
|
|
On Linux, the underlying system calls were renamed
|
|
|
|
in kernel 2.6:
|
|
|
|
.BR pread ()
|
|
|
|
became
|
|
|
|
.BR pread64 (),
|
|
|
|
and
|
|
|
|
.BR pwrite ()
|
|
|
|
became
|
2010-12-03 05:54:08 +00:00
|
|
|
.BR pwrite64 ().
|
2010-11-21 05:39:03 +00:00
|
|
|
The system call numbers remained the same.
|
|
|
|
The glibc
|
|
|
|
.BR pread ()
|
|
|
|
and
|
|
|
|
.BR pwrite ()
|
|
|
|
wrapper functions transparently deal with the change.
|
2012-04-29 19:47:27 +00:00
|
|
|
.SH BUGS
|
|
|
|
POSIX requires that opening a file with the
|
|
|
|
.BR O_APPEND
|
|
|
|
flag should have no affect on the location at which
|
|
|
|
.BR pwrite ()
|
|
|
|
writes data.
|
|
|
|
However, on Linux, if a file is opened with
|
|
|
|
.\" FIXME https://bugzilla.kernel.org/show_bug.cgi?id=43178
|
|
|
|
.BR O_APPEND ,
|
|
|
|
.BR pwrite ()
|
|
|
|
appends data to the end of the file, regardless of the value of
|
|
|
|
.IR offset .
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR lseek (2),
|
|
|
|
.BR read (2),
|
2010-11-16 05:50:28 +00:00
|
|
|
.BR readv (2),
|
getresuid.2, intro.2, mremap.2, open.2, poll.2, posix_fadvise.2, pread.2, remap_file_pages.2, setresuid.2, signal.2, splice.2, sync_file_range.2, tee.2, vmsplice.2, INFINITY.3, asprintf.3, assert_perror.3, basename.3, bsd_signal.3, canonicalize_file_name.3, clog10.3, crypt.3, dl_iterate_phdr.3, dlopen.3, dprintf.3, encrypt.3, exp10.3, fcloseall.3, fenv.3, ffs.3, fmemopen.3, fopencookie.3, ftw.3, getdate.3, getline.3, getloadavg.3, getopt.3, getsubopt.3, getutent.3, grantpt.3, hsearch.3, intro.3, lseek64.3, memmem.3, mempcpy.3, mq_receive.3, mq_send.3, posix_fallocate.3, pow10.3, program_invocation_name.3, ptsname.3, putgrent.3, readdir.3, sigset.3, sincos.3, stpcpy.3, stpncpy.3, strchr.3, strfry.3, strnlen.3, strptime.3, strsignal.3, strstr.3, strverscmp.3, swab.3, sysv_signal.3, tsearch.3, unlocked_stdio.3, unlockpt.3, wcpcpy.3, wcpncpy.3, wcsdup.3, wcwidth.3: SEE ALSO: Remove redundant reference to feature_test_macros(7)
Reported-by: Florian Lehmann <flo.lehmann@googlemail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-31 05:05:22 +00:00
|
|
|
.BR write (2)
|