1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
5 .\" and Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
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
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.
39 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
40 .\" all rights reserved.
41 .\" Translated Tue Mar 4 00:18:20 JST 1997
42 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
43 .\" Updated & Modified Wed Jun 13 20:57:55 JST 2001
44 .\" by Yuichi SATO <ysato@h4.dion.ne.jp>
45 .\" Updated Mon Jun 25 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
46 .\" Updated Fri Dec 21 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2002-09-24 by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
48 .\" Updated 2005-10-14 by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
49 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
50 .\" Updated 2007-09-01, Akihiro MOTOKI, LDP v2.64
51 .\" Updated 2008-04-13, Akihiro MOTOKI, LDP v3.20
53 .\"WORD: descriptor ディスクリプタ
55 .\"WORD: file system ファイル・システム
56 .\"WORD: object オブジェクト
60 .\"WORD: catch 捕獲(catch)
61 .\"WORD: block 停止(block)
62 .\"WORD: interrupt 割り込み
63 .\"WORD: nonblocking I/O 非停止 I/O
65 .\"WORD: low-level I/O 低レべル I/O
67 .TH WRITE 2 2010-08-29 "Linux" "Linux Programmer's Manual"
70 .\"O write \- write to a file descriptor
71 write \- ファイル・ディスクリプタ (file descriptor) に書き込む
74 .B #include <unistd.h>
76 .BI "ssize_t write(int " fd ", const void *" buf ", size_t " count );
82 .\"O bytes from the buffer pointed
84 .\"O to the file referred to by the file descriptor
89 が指すバッファから、ファイル・ディスクリプタ
95 .\"O The number of bytes written may be less than
98 .\"O there is insufficient space on the underlying physical medium, or the
100 .\"O resource limit is encountered (see
101 .\"O .BR setrlimit (2)),
102 .\"O or the call was interrupted by a signal
103 .\"O handler after having written less than
111 例えば、書き込み対象の物理メディアに十分な領域がない場合、
119 呼び出しがシグナルハンドラにより割り込まれた場合、
124 .\"O For a seekable file (i.e., one to which
126 .\"O may be applied, for example, a regular file)
127 .\"O writing takes place at the current file offset,
128 .\"O and the file offset is incremented by
129 .\"O the number of bytes actually written.
134 .\"O the file offset is first set to the end of the file before writing.
135 .\"O The adjustment of the file offset and the write operation
136 .\"O are performed as an atomic step.
139 が適用できるファイル、例えば通常のファイル) では、
140 書き込みは現在のファイル・オフセットから行われ、
141 ファイル・オフセットは実際に書き込みが行われたバイト数分
146 された場合、ファイル・オフセットは書き込み前に
148 ファイル・オフセットの調整と書き込み操作はアトミックな処理として
151 .\"O POSIX requires that a
153 .\"O which can be proved to occur after a
155 .\"O has returned returns the new data.
156 .\"O Note that not all file systems are POSIX conforming.
163 全てのファイル・システムが POSIX 準拠ではない点に注意すること。
164 .\"O .SH "RETURN VALUE"
166 .\"O On success, the number of bytes written is returned (zero indicates
167 .\"O nothing was written).
168 .\"O On error, \-1 is returned, and \fIerrno\fP is set
170 成功した場合、書き込まれたバイト数が返される
171 (ゼロは何も書き込まれなかったことを示す)。
172 エラーならば \-1 が返され、\fIerrno\fP が適切に設定される。
174 .\"O If \fIcount\fP is zero and
176 .\"O refers to a regular file, then
178 .\"O may return a failure status if one of the errors below is detected.
179 .\"O If no errors are detected,
180 .\"O 0 will be returned without causing any other effect.
182 .\"O \fIcount\fP is zero and
184 .\"O refers to a file other than a regular file,
185 .\"O the results are not specified.
188 が通常のファイル (regular file) を参照している場合、
190 は後述のエラーのいずれかを検出した場合、失敗を返すことがある。
195 が通常のファイル以外のファイルを参照している場合、
201 .\"O The file descriptor
203 .\"O refers to a file other than a socket and has been marked nonblocking
204 .\"O .RB ( O_NONBLOCK ),
205 .\"O and the write would block.
209 非停止 (nonblocking) モード
211 に設定されており、書き込みを行うと停止する状況にある。
213 .\"O .BR EAGAIN " or " EWOULDBLOCK
214 .BR EAGAIN " または " EWOULDBLOCK
215 .\" Actually EAGAIN on Linux
216 .\"O The file descriptor
218 .\"O refers to a socket and has been marked nonblocking
219 .\"O .RB ( O_NONBLOCK ),
220 .\"O and the write would block.
221 .\"O POSIX.1-2001 allows either error to be returned for this case,
222 .\"O and does not require these constants to have the same value,
223 .\"O so a portable application should check for both possibilities.
226 がソケットを参照していて、非停止 (nonblocking) モード
228 に設定されており、書き込みを行うと停止する状況にある。
229 POSIX.1-2001 は、この場合にどちらのエラーを返すことも認めており、
230 これら 2 つの定数が同じ値を持つことも求めていない。
231 したがって、移植性が必要なアプリケーションでは、両方の可能性を
236 .\"O is not a valid file descriptor or is not open for writing.
238 が有効なファイル・ディスクリプタでないか書き込みのためにオープン
243 .\"O refers to a datagram socket for which a peer address has not been set using
244 .\"O .BR connect (2).
248 を使って通信相手のアドレスが設定されていないデータグラムソケットを
253 .\"O is outside your accessible address space.
255 がアクセス可能なアドレス空間 (address space) の外にある。
258 .\"O An attempt was made to write a file that exceeds the implementation-defined
259 .\"O maximum file size or the process's file size limit,
260 .\"O or to write at a position past the maximum allowed offset.
261 実装定義の最大ファイルサイズまたはプロセスのファイルサイズ制限を
263 または許可されたオフセット値の限界を超えた先の位置に
267 .\"O The call was interrupted by a signal before any data was written; see
269 何のデータも書かない間にシグナルにより割り込まれた (interrupt)。
275 .\"O is attached to an object which is unsuitable for writing;
276 .\"O or the file was opened with the
278 .\"O flag, and either the address specified in
280 .\"O the value specified in
282 .\"O or the current file offset is not suitably aligned.
284 が書き込みが不適切なオブジェクトを参照している。
296 .\"O A low-level I/O error occurred while modifying the inode.
297 inode の修正中に低レべル (low-level) I/O エラーが発生した。
300 .\"O The device containing the file referred to by
302 .\"O has no room for the data.
304 によって参照されるファイルを含むデバイス (device) に十分な空きがない。
308 .\"O is connected to a pipe or socket whose reading end is closed.
309 .\"O When this happens the writing process will also receive a
312 .\"O (Thus, the write return value is seen only if the program
313 .\"O catches, blocks or ignores this signal.)
315 がパイプ (pipe) かソケット (socket) に接続されており、
316 その反対側 (読み込み側) がクローズ (close) されている。
317 これが発生した場合には、書き込みを行なうプロセスは
320 (したがって、プログラムがこのシグナルを捕獲 (catch)、停止 (block)、無視 (ignore)
321 した場合のみ、write の返り値を参照できる。)
323 .\"O Other errors may occur, depending on the object connected to
326 に接続されたオブジェクトによっては、他のエラーが起こるかもしれない。
327 .\"O .SH "CONFORMING TO"
329 SVr4, 4.3BSD, POSIX.1-2001.
330 .\"O .\" SVr4 documents additional error
331 .\"O .\" conditions EDEADLK, ENOLCK, ENOLNK, ENOSR, ENXIO, or ERANGE.
332 .\" SVr4 には他に EDEADLK, ENOLCK, ENOLNK,
333 .\" ENOSR, ENXIO, ERANGE エラーについての記述がある。
335 .\"O Under SVr4 a write may be interrupted and return
338 .\"O not just before any data is written.
339 SVr4 では write が割り込まれると、データが書き込まれる直前ではなく、
345 .\"O A successful return from
347 .\"O does not make any guarantee that data has been committed to disk.
349 が成功して返ってきても、データがディスクに記録されたことを
351 .\"O In fact, on some buggy implementations, it does not even guarantee
352 .\"O that space has successfully been reserved for the data.
353 実際、データのためのスペースが確保されたことすら保証されないという
355 .\"O The only way to be sure is to call
357 .\"O after you are done writing all your data.
365 .\"O is interrupted by a signal handler before any bytes are written,
366 .\"O then the call fails with the error
368 .\"O if it is interrupted after at least one byte has been written,
369 .\"O the call succeeds, and returns the number of bytes written.
371 が 1 バイトも書き込まないうちにシグナルハンドラにより割り込まれた場合、
376 1バイトでも書き込んだ後で割り込まれた場合には、