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"
69 write \- ファイル・ディスクリプタ (file descriptor) に書き込む
71 .B #include <unistd.h>
73 .BI "ssize_t write(int " fd ", const void *" buf ", size_t " count );
78 が指すバッファから、ファイル・ディスクリプタ
87 例えば、書き込み対象の物理メディアに十分な領域がない場合、
95 呼び出しがシグナルハンドラにより割り込まれた場合、
102 が適用できるファイル、例えば通常のファイル) では、
103 書き込みは現在のファイル・オフセットから行われ、
104 ファイル・オフセットは実際に書き込みが行われたバイト数分
109 された場合、ファイル・オフセットは書き込み前に
111 ファイル・オフセットの調整と書き込み操作はアトミックな処理として
120 全てのファイル・システムが POSIX 準拠ではない点に注意すること。
122 成功した場合、書き込まれたバイト数が返される
123 (ゼロは何も書き込まれなかったことを示す)。
124 エラーならば \-1 が返され、\fIerrno\fP が適切に設定される。
128 が通常のファイル (regular file) を参照している場合、
130 は後述のエラーのいずれかを検出した場合、失敗を返すことがある。
135 が通常のファイル以外のファイルを参照している場合、
143 非停止 (nonblocking) モード
145 に設定されており、書き込みを行うと停止する状況にある。
147 .BR EAGAIN " または " EWOULDBLOCK
148 .\" Actually EAGAIN on Linux
151 がソケットを参照していて、非停止 (nonblocking) モード
153 に設定されており、書き込みを行うと停止する状況にある。
154 POSIX.1-2001 は、この場合にどちらのエラーを返すことも認めており、
155 これら 2 つの定数が同じ値を持つことも求めていない。
156 したがって、移植性が必要なアプリケーションでは、両方の可能性を
161 が有効なファイル・ディスクリプタでないか書き込みのためにオープン
168 を使って通信相手のアドレスが設定されていないデータグラムソケットを
173 がアクセス可能なアドレス空間 (address space) の外にある。
176 実装定義の最大ファイルサイズまたはプロセスのファイルサイズ制限を
178 または許可されたオフセット値の限界を超えた先の位置に
182 何のデータも書かない間にシグナルにより割り込まれた (interrupt)。
188 が書き込みが不適切なオブジェクトを参照している。
200 inode の修正中に低レべル (low-level) I/O エラーが発生した。
204 によって参照されるファイルを含むデバイス (device) に十分な空きがない。
208 がパイプ (pipe) かソケット (socket) に接続されており、
209 その反対側 (読み込み側) がクローズ (close) されている。
210 これが発生した場合には、書き込みを行なうプロセスは
213 (したがって、プログラムがこのシグナルを捕獲 (catch)、停止 (block)、無視 (ignore)
214 した場合のみ、write の返り値を参照できる。)
217 に接続されたオブジェクトによっては、他のエラーが起こるかもしれない。
219 SVr4, 4.3BSD, POSIX.1-2001.
220 .\" SVr4 には他に EDEADLK, ENOLCK, ENOLNK,
221 .\" ENOSR, ENXIO, ERANGE エラーについての記述がある。
223 SVr4 では write が割り込まれると、データが書き込まれる直前ではなく、
229 が成功して返ってきても、データがディスクに記録されたことを
231 実際、データのためのスペースが確保されたことすら保証されないという
239 が 1 バイトも書き込まないうちにシグナルハンドラにより割り込まれた場合、
244 1バイトでも書き込んだ後で割り込まれた場合には、