1 .\" Copyright (C) 1999 Joseph Samuel Myers.
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"*******************************************************************
27 .\" This file was generated with po4a. Translate the source file.
29 .\"*******************************************************************
31 .\" Japanese Version Copyright (c) 1999 HANATAKA Shinya
32 .\" all rights reserved.
33 .\" Translated Fri Jun 25 23:32:20 JST 1999
34 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
35 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
36 .\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
37 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
38 .\" Updated 2013-07-24, Akihiro MOTOKI <amotoki@gmail.com>
40 .TH PREAD 2 2017\-09\-15 Linux "Linux Programmer's Manual"
42 pread, pwrite \- 指定したオフセットでファイルディスクリプターを読み書きする
44 \fB#include <unistd.h>\fP
46 \fBssize_t pread(int \fP\fIfd\fP\fB, void *\fP\fIbuf\fP\fB, size_t \fP\fIcount\fP\fB, off_t
47 \fP\fIoffset\fP\fB);\fP
49 \fBssize_t pwrite(int \fP\fIfd\fP\fB, const void *\fP\fIbuf\fP\fB, size_t \fP\fIcount\fP\fB,
50 off_t \fP\fIoffset\fP\fB);\fP
53 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
58 \fBpread\fP(), \fBpwrite\fP():
60 _XOPEN_SOURCE\ >=\ 500
62 || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
67 \fBpread\fP() は、ファイルディスクリプター \fIfd\fP の (ファイルの先頭からの) オフセット \fIoffset\fP から最大
68 \fIcount\fP バイトをバッファー \fIbuf\fP へ読み込む。ファイルオフセットは変化しない。
70 \fBpwrite\fP() は、バッファー \fIbuf\fP から最大 \fIcount\fP バイトをファイルディスクリプター \fIfd\fP のオフセット
71 \fIoffset\fP に書き込む。ファイルオフセットは変化しない。
73 \fIfd\fP で参照されるファイルはシーク (seek) 可能でなければならない。
75 On success, \fBpread\fP() returns the number of bytes read (a return of zero
76 indicates end of file) and \fBpwrite\fP() returns the number of bytes
79 Note that it is not an error for a successful call to transfer fewer bytes
80 than requested (see \fBread\fP(2) and \fBwrite\fP(2)).
82 On error, \-1 is returned and \fIerrno\fP is set to indicate the cause of the
85 \fBpread\fP() では、 \fBread\fP(2) および \fBlseek\fP(2) で規定された全てのエラーが発生する可能性があり、
86 \fIerrno\fP にはエラーを示す値が設定される。 \fBpwrite\fP() では、 \fBwrite\fP(2) および \fBlseek\fP(2)
87 で規定された全てのエラーが発生する可能性があり、 \fIerrno\fP にはエラーを示す値が設定される。
89 システムコール \fBpread\fP() と \fBpwrite\fP() は Linux にバージョン 2.1.60 で追加された。 i386
90 のシステムコールのエントリーは 2.1.69 で追加された。 (システムコールを持たない古いカーネルでの \fBlseek\fP(2)
91 を使ったエミュレーションを含めると) C ライブラリにおけるサポートは glibc 2.1 で追加された。
93 POSIX.1\-2001, POSIX.1\-2008.
96 システムコール \fBpread\fP() と \fBpwrite\fP() は、特にマルチスレッドアプリケーションで役に立つ。 これらを使うと、
97 他のスレッドによるファイルオフセットの変更の影響を受けることなく、 複数のスレッドが同じファイルディスクリプターに対して入出力を行うことができる。
99 Linux では、裏で呼び出されるシステムコールの名前がカーネル 2.6 で変更された。
100 \fBpread\fP() は \fBpread64\fP() になり、 \fBpwrite\fP() は \fBpwrite64\fP() になった。
102 glibc の \fBpread\fP() と \fBpwrite\fP() のラッパー関数はこれらの変更を吸収している。
104 いくつかの 32 ビットアーキテクチャーでは、これらのシステムコールの呼び出し時のシグネチャーが違っています。理由は \fBsyscall\fP(2)
107 .\" FIXME . https://bugzilla.kernel.org/show_bug.cgi?id=43178
108 POSIX では、\fBO_APPEND\fP フラグを指定してファイルをオープンした場合、
109 \fBpwrite\fP() がデータを書き込む位置に影響を及ぼさないことが
110 求められている。しかし、 Linux では、ファイルを \fBO_APPEND\fP 付きで
111 オープンした場合、 \fIoffset\fP の値に関わらず、
112 \fBpwrite\fP() はファイルの末尾にデータを追記する。
114 \fBlseek\fP(2), \fBread\fP(2), \fBreadv\fP(2), \fBwrite\fP(2)
116 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
117 \%https://www.kernel.org/doc/man\-pages/ に書かれている。