OSDN Git Service

9680dc6bf8d31ba5ff91469ac5239f1cff6c6c3b
[linuxjm/LDP_man-pages.git] / release / man2 / write.2
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\" and Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" %%%LICENSE_END
26 .\"
27 .\" Modified Sat Jul 24 13:35:59 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Sun Nov 28 17:19:01 1993 by Rik Faith <faith@cs.unc.edu>
29 .\" Modified Sat Jan 13 12:58:08 1996 by Michael Haardt
30 .\"   <michael@cantor.informatik.rwth-aachen.de>
31 .\" Modified Sun Jul 21 18:59:33 1996 by Andries Brouwer <aeb@cwi.nl>
32 .\" 2001-12-13 added remark by Zack Weinberg
33 .\" 2007-06-18 mtk:
34 .\"     Added details about seekable files and file offset.
35 .\"     Noted that write() may write less than 'count' bytes, and
36 .\"     gave some examples of why this might occur.
37 .\"     Noted what happens if write() is interrupted by a signal.
38 .\"
39 .\"*******************************************************************
40 .\"
41 .\" This file was generated with po4a. Translate the source file.
42 .\"
43 .\"*******************************************************************
44 .\"
45 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
46 .\"         all rights reserved.
47 .\" Translated Tue Mar  4 00:18:20 JST 1997
48 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
49 .\" Updated & Modified Wed Jun 13 20:57:55 JST 2001
50 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>
51 .\" Updated Mon Jun 25 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
52 .\" Updated Fri Dec 21 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
53 .\" Updated 2002-09-24 by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
54 .\" Updated 2005-10-14 by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
55 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
56 .\" Updated 2007-09-01, Akihiro MOTOKI, LDP v2.64
57 .\" Updated 2008-04-13, Akihiro MOTOKI, LDP v3.20
58 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
59 .\" Updated 2013-05-04, Akihiro MOTOKI <amotoki@gmail.com>
60 .\"
61 .TH WRITE 2 2013\-01\-27 Linux "Linux Programmer's Manual"
62 .SH 名前
63 write \- ファイルディスクリプタ (file descriptor) に書き込む
64 .SH 書式
65 \fB#include <unistd.h>\fP
66 .sp
67 \fBssize_t write(int \fP\fIfd\fP\fB, const void *\fP\fIbuf\fP\fB, size_t \fP\fIcount\fP\fB);\fP
68 .SH 説明
69 \fBwrite\fP()  は、 \fIbuf\fP が指すバッファから、ファイルディスクリプタ \fIfd\fP が参照するファイルへ、最大 \fIcount\fP
70 バイトを書き込む。
71
72 書き込まれるバイト数は \fIcount\fP よりも小さくなることがある。 例えば、書き込み対象の物理メディアに十分な領域がない場合、 リソース上限
73 \fBRLIMIT_FSIZE\fP に達した場合 (\fBsetrlimit\fP(2)  参照)、 \fIcount\fP バイト未満の書き込みが行われた後で
74 呼び出しがシグナルハンドラにより割り込まれた場合、 などである。 (\fBpipe\fP(7)  も参照のこと。)
75
76 seek 可能なファイル (つまり \fBlseek\fP(2)  が適用できるファイル、例えば通常のファイル) では、
77 書き込みは現在のファイルオフセットから行われ、 ファイルオフセットは実際に書き込みが行われたバイト数分 加算される。ファイルが \fBO_APPEND\fP
78 で \fBopen\fP(2)  された場合、ファイルオフセットは書き込み前に ファイルの末尾に設定される。
79 ファイルオフセットの調整と書き込み操作はアトミックな処理として 実行される。
80
81 POSIX requires that a \fBread\fP(2)  which can be proved to occur after a
82 \fBwrite\fP()  has returned returns the new data.  Note that not all
83 filesystems are POSIX conforming.
84 .SH 返り値
85 成功した場合、書き込まれたバイト数が返される (ゼロは何も書き込まれなかったことを示す)。 エラーならば \-1 が返され、\fIerrno\fP
86 が適切に設定される。
87
88 \fIcount\fP が 0 で、 \fIfd\fP が通常のファイル (regular file) を参照している場合、 \fBwrite\fP()
89 は後述のエラーのいずれかを検出した場合、失敗を返すことがある。 エラーが検出されなかった場合は、 0 を返し、他に何の影響も与えない。 \fIcount\fP
90 が 0 で、 \fIfd\fP が通常のファイル以外のファイルを参照している場合、 その結果は規定されていない。
91 .SH エラー
92 .TP 
93 \fBEAGAIN\fP
94 ファイルディスクリプタ \fIfd\fP がソケット以外のファイルを参照していて、 非停止 (nonblocking) モード (\fBO_NONBLOCK\fP)
95 に設定されており、書き込みを行うと停止する状況にある。
96 .TP 
97 \fBEAGAIN\fP または \fBEWOULDBLOCK\fP
98 .\" Actually EAGAIN on Linux
99 ファイルディスクリプタ \fIfd\fP がソケットを参照していて、非停止 (nonblocking) モード (\fBO_NONBLOCK\fP)
100 に設定されており、書き込みを行うと停止する状況にある。 POSIX.1\-2001 は、この場合にどちらのエラーを返すことも認めており、 これら 2
101 つの定数が同じ値を持つことも求めていない。 したがって、移植性が必要なアプリケーションでは、両方の可能性を 確認すべきである。
102 .TP 
103 \fBEBADF\fP
104 \fIfd\fP が有効なファイルディスクリプタでないか書き込みのためにオープン (open) されていない。
105 .TP 
106 \fBEDESTADDRREQ\fP
107 \fIfd\fP が、 \fBconnect\fP(2)  を使って通信相手のアドレスが設定されていないデータグラムソケットを 参照している。
108 .TP 
109 \fBEDQUOT\fP
110 The user's quota of disk blocks on the filesystem containing the file
111 referred to by \fIfd\fP has been exhausted.
112 .TP 
113 \fBEFAULT\fP
114 \fIbuf\fP がアクセス可能なアドレス空間の外にある。
115 .TP 
116 \fBEFBIG\fP
117 実装定義の最大ファイルサイズまたはプロセスのファイルサイズ制限を 超えてファイルに書き込もうとした。
118 または許可されたオフセット値の限界を超えた先の位置に 書き込もうとした。
119 .TP 
120 \fBEINTR\fP
121 何のデータも書かない間にシグナルにより割り込まれた (interrupt)。 \fBsignal\fP(7)  参照。
122 .TP 
123 \fBEINVAL\fP
124 \fIfd\fP が書き込みが不適切なオブジェクトを参照している。 もしくは、ファイルが \fBO_DIRECT\fP フラグを指定してオープンされているが、
125 \fIbuf\fP に指定されたアドレス、 \fIcount\fP に指定された値、 現在のファイルオフセットのいずれかの アラインメントが不適切である。
126 .TP 
127 \fBEIO\fP
128 inode の修正中に低レべル (low\-level) I/O エラーが発生した。
129 .TP 
130 \fBENOSPC\fP
131 \fIfd\fP によって参照されるファイルを含むデバイス (device) に十分な空きがない。
132 .TP 
133 \fBEPIPE\fP
134 \fIfd\fP がパイプ (pipe) かソケット (socket) に接続されており、 その反対側 (読み込み側) がクローズ (close)
135 されている。 これが発生した場合には、書き込みを行なうプロセスは \fBSIGPIPE\fP シグナル (signal)も受ける。
136 (したがって、プログラムがこのシグナルを捕獲 (catch)、停止 (block)、無視 (ignore)  した場合のみ、write
137 の返り値を参照できる。)
138 .PP
139 \fIfd\fP に接続されたオブジェクトによっては、他のエラーが起こるかもしれない。
140 .SH 準拠
141 .\" SVr4 documents additional error
142 .\" conditions EDEADLK, ENOLCK, ENOLNK, ENOSR, ENXIO, or ERANGE.
143 SVr4, 4.3BSD, POSIX.1\-2001.
144
145 SVr4 では write が割り込まれると、データが書き込まれる直前ではなく、 その時点で \fBEINTR\fP が返る。
146 .SH 注意
147 \fBwrite\fP()  が成功して返ってきても、データがディスクに記録されたことを 保証するものではない。
148 実際、データのためのスペースが確保されたことすら保証されないという バグっぽい実装もある。 これを確実にする唯一の方法は、 全てのデータを write
149 した後に \fBfsync\fP(2)  を呼び出すことである。
150
151 \fBwrite\fP()  が 1 バイトも書き込まないうちにシグナルハンドラにより割り込まれた場合、 \fBwrite\fP()  はエラー \fBEINTR\fP
152 で失敗する。 1バイトでも書き込んだ後で割り込まれた場合には、 \fBwrite\fP()  は成功し、書き込んだバイト数を返す。
153 .SH 関連項目
154 \fBclose\fP(2), \fBfcntl\fP(2), \fBfsync\fP(2), \fBioctl\fP(2), \fBlseek\fP(2), \fBopen\fP(2),
155 \fBpwrite\fP(2), \fBread\fP(2), \fBselect\fP(2), \fBwritev\fP(2), \fBfwrite\fP(3)
156 .SH この文書について
157 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
158 である。プロジェクトの説明とバグ報告に関する情報は
159 http://www.kernel.org/doc/man\-pages/ に書かれている。