.\" Copyright (C) 1999 Joseph Samuel Myers. .\" .\" %%%LICENSE_START(VERBATIM) .\" 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. .\" .\" 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. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1999 HANATAKA Shinya .\" all rights reserved. .\" Translated Fri Jun 25 23:32:20 JST 1999 .\" by HANATAKA Shinya .\" Updated 2012-04-30, Akihiro MOTOKI .\" Updated 2012-05-29, Akihiro MOTOKI .\" Updated 2013-05-01, Akihiro MOTOKI .\" Updated 2013-07-24, Akihiro MOTOKI .\" .TH PREAD 2 2013\-06\-21 Linux "Linux Programmer's Manual" .SH 名前 pread, pwrite \- 指定したオフセットでファイルディスクリプタを読み書きする .SH 書式 \fB#include \fP .sp \fBssize_t pread(int \fP\fIfd\fP\fB, void *\fP\fIbuf\fP\fB, size_t \fP\fIcount\fP\fB, off_t \fP\fIoffset\fP\fB);\fP .sp \fBssize_t pwrite(int \fP\fIfd\fP\fB, const void *\fP\fIbuf\fP\fB, size_t \fP\fIcount\fP\fB, off_t \fP\fIoffset\fP\fB);\fP .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .PD 0 .ad l .sp \fBpread\fP(), \fBpwrite\fP(): .RS 4 _XOPEN_SOURCE\ >=\ 500 .br || /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L .RE .ad .PD .SH 説明 \fBpread\fP() は、ファイルディスクリプタ \fIfd\fP の (ファイルの先頭からの) オフセット \fIoffset\fP から最大 \fIcount\fP バイトをバッファ \fIbuf\fP へ読み込む。ファイルオフセットは変化しない。 .PP \fBpwrite\fP() は、バッファ \fIbuf\fP から最大 \fIcount\fP バイトをファイルディスクリプタ \fIfd\fP のオフセット \fIoffset\fP に書き込む。ファイルオフセットは変化しない。 .PP \fIfd\fP で参照されるファイルはシーク (seek) 可能でなければならない。 .SH 返り値 成功した場合、読み書きを行ったバイト数が返される (ゼロは、 \fBpwrite\fP() の場合には何も書かれなかったことを意味し、 \fBpread\fP() の場合にはファイル の末尾に達したことを意味する)。 エラーの場合は \-1 が返され、 \fIerrno\fP がそのエラーを示すように設定される。 .SH エラー \fBpread\fP() では、 \fBread\fP(2) および \fBlseek\fP(2) で規定された全てのエラーが発生する可能性があり、 \fIerror\fP にはエラーを示す値が設定される。 \fBpwrite\fP() では、 \fBwrite\fP(2) および \fBlseek\fP(2) で規定された全てのエラーが発生する可能性があり、 \fIerror\fP にはエラーを示す値が設定される。 .SH バージョン システムコール \fBpread\fP() と \fBpwrite\fP() は Linux にバージョン 2.1.60 で追加された。 i386 のシステムコールのエントリは 2.1.69 で追加された。 (システムコールを持たない古いカーネルでの \fBlseek\fP(2) を使ったエミュレーションを含めると) C ライブラリにおけるサポートは glibc 2.1 で追加された。 .SH 準拠 POSIX.1\-2001. .SH 注意 システムコール \fBpread\fP() と \fBpwrite\fP() は、特にマルチスレッドアプリケーションで役に立つ。 これらを使うと、 他のスレッドによるファイルオフセットの変更の影響を受けることなく、 複数のスレッドが同じファイルディスクリプタに対して入出力を行うことができる。 Linux では、裏で呼び出されるシステムコールの名前がカーネル 2.6 で変更された。 \fBpread\fP() は \fBpread64\fP() になり、 \fBpwrite\fP() は \fBpwrite64\fP() になった。 システムコールの番号は変更されていない。 glibc の \fBpread\fP() と \fBpwrite\fP() のラッパー関数はこれらの変更を吸収している。 いくつかの 32 ビットアーキテクチャでは、これらのシステムコールの呼び出し時のシグネチャーが違っています。理由は \fBsyscall\fP(2) で説明されている通りです。 .SH バグ .\" FIXME https://bugzilla.kernel.org/show_bug.cgi?id=43178 POSIX では、\fBO_APPEND\fP フラグを指定してファイルをオープンした場合、 \fBpwrite\fP() がデータを書き込む位置に影響を及ぼさないことが 求められている。しかし、 Linux では、ファイルを \fBO_APPEND\fP 付きで オープンした場合、 \fIoffset\fP の値に関わらず、 \fBpwrite\fP() はファイルの末尾にデータを追記する。 .SH 関連項目 \fBlseek\fP(2), \fBread\fP(2), \fBreadv\fP(2), \fBwrite\fP(2) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。