-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
-.\" 1993 Michael Haardt, Ian Jackson.
+.\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
.\" and Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
+.\" %%%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.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" Modified Sat Jul 24 13:35:59 1993 by Rik Faith <faith@cs.unc.edu>
.\" Modified Sun Nov 28 17:19:01 1993 by Rik Faith <faith@cs.unc.edu>
.\" gave some examples of why this might occur.
.\" Noted what happens if write() is interrupted by a signal.
.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
.\" all rights reserved.
.\" Translated Tue Mar 4 00:18:20 JST 1997
.\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
.\" Updated 2007-09-01, Akihiro MOTOKI, LDP v2.64
.\" Updated 2008-04-13, Akihiro MOTOKI, LDP v3.20
+.\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-05-04, Akihiro MOTOKI <amotoki@gmail.com>
.\"
-.\"WORD: descriptor ¥Ç¥£¥¹¥¯¥ê¥×¥¿
-.\"WORD: buffer ¥Ð¥Ã¥Õ¥¡¡¼
-.\"WORD: file system ¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à
-.\"WORD: object ¥ª¥Ö¥¸¥§¥¯¥È
-.\"WORD: pipe ¥Ñ¥¤¥×
-.\"WORD: socket ¥½¥±¥Ã¥È
-.\"WORD: signal ¥·¥°¥Ê¥ë
-.\"WORD: catch Êá³Í(catch)
-.\"WORD: block Ää»ß(block)
-.\"WORD: interrupt ³ä¤ê¹þ¤ß
-.\"WORD: nonblocking I/O ÈóÄä»ß I/O
-.\"WORD: device ¥Ç¥Ð¥¤¥¹
-.\"WORD: low-level I/O Äã¥ì¤Ù¥ë I/O
-.\"
-.TH WRITE 2 2009-02-23 "Linux" "Linux Programmer's Manual"
-.\"O .SH NAME
-.SH ̾Á°
-.\"O write \- write to a file descriptor
-write \- ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿ (file descriptor) ¤Ë½ñ¤¹þ¤à
-.\"O .SH SYNOPSIS
-.SH ½ñ¼°
-.B #include <unistd.h>
+.TH WRITE 2 2014\-05\-04 Linux "Linux Programmer's Manual"
+.SH 名前
+write \- ファイルディスクリプタ (file descriptor) に書き込む
+.SH 書式
+\fB#include <unistd.h>\fP
.sp
-.BI "ssize_t write(int " fd ", const void *" buf ", size_t " count );
-.\"O .SH DESCRIPTION
-.SH ÀâÌÀ
-.\"O .BR write ()
-.\"O writes up to
-.\"O .I count
-.\"O bytes from the buffer pointed
-.\"O .I buf
-.\"O to the file referred to by the file descriptor
-.\"O .IR fd .
-.BR write ()
-¤Ï¡¢
-.I buf
-¤¬»Ø¤¹¥Ð¥Ã¥Õ¥¡¤«¤é¡¢¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
-.I fd
-¤¬»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¤Ø¡¢ºÇÂç
-.I count
-¥Ð¥¤¥È¤ò½ñ¤¹þ¤à¡£
+\fBssize_t write(int \fP\fIfd\fP\fB, const void *\fP\fIbuf\fP\fB, size_t \fP\fIcount\fP\fB);\fP
+.SH 説明
+\fBwrite\fP() は、 \fIbuf\fP が指すバッファから、ファイルディスクリプタ \fIfd\fP が参照するファイルへ、最大 \fIcount\fP
+バイトを書き込む。
-.\"O The number of bytes written may be less than
-.\"O .I count
-.\"O if, for example,
-.\"O there is insufficient space on the underlying physical medium, or the
-.\"O .B RLIMIT_FSIZE
-.\"O resource limit is encountered (see
-.\"O .BR setrlimit (2)),
-.\"O or the call was interrupted by a signal
-.\"O handler after having written less than
-.\"O .I count
-.\"O bytes.
-.\"O (See also
-.\"O .BR pipe (7).)
-½ñ¤¹þ¤Þ¤ì¤ë¥Ð¥¤¥È¿ô¤Ï
-.I count
-¤è¤ê¤â¾®¤µ¤¯¤Ê¤ë¤³¤È¤¬¤¢¤ë¡£
-Î㤨¤Ð¡¢½ñ¤¹þ¤ßÂоݤÎʪÍý¥á¥Ç¥£¥¢¤Ë½½Ê¬¤ÊÎΰ褬¤Ê¤¤¾ì¹ç¡¢
-¥ê¥½¡¼¥¹¾å¸Â
-.B RLIMIT_FSIZE
-¤Ë㤷¤¿¾ì¹ç
-.RB ( setrlimit (2)
-»²¾È)¡¢
-.I count
-¥Ð¥¤¥È̤Ëþ¤Î½ñ¤¹þ¤ß¤¬¹Ô¤ï¤ì¤¿¸å¤Ç
-¸Æ¤Ó½Ð¤·¤¬¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¡¢
-¤Ê¤É¤Ç¤¢¤ë¡£
-.RB ( pipe (7)
-¤â»²¾È¤Î¤³¤È¡£)
+書き込まれるバイト数は \fIcount\fP よりも小さくなることがある。 例えば、書き込み対象の物理メディアに十分な領域がない場合、 リソース上限
+\fBRLIMIT_FSIZE\fP に達した場合 (\fBsetrlimit\fP(2) 参照)、 \fIcount\fP バイト未満の書き込みが行われた後で
+呼び出しがシグナルハンドラにより割り込まれた場合、 などである。 (\fBpipe\fP(7) も参照のこと。)
-.\"O For a seekable file (i.e., one to which
-.\"O .BR lseek (2)
-.\"O may be applied, for example, a regular file)
-.\"O writing takes place at the current file offset,
-.\"O and the file offset is incremented by
-.\"O the number of bytes actually written.
-.\"O If the file was
-.\"O .BR open (2)ed
-.\"O with
-.\"O .BR O_APPEND ,
-.\"O the file offset is first set to the end of the file before writing.
-.\"O The adjustment of the file offset and the write operation
-.\"O are performed as an atomic step.
-seek ²Äǽ¤Ê¥Õ¥¡¥¤¥ë (¤Ä¤Þ¤ê
-.BR lseek (2)
-¤¬Å¬ÍѤǤ¤ë¥Õ¥¡¥¤¥ë¡¢Î㤨¤ÐÄ̾ï¤Î¥Õ¥¡¥¤¥ë) ¤Ç¤Ï¡¢
-½ñ¤¹þ¤ß¤Ï¸½ºß¤Î¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤«¤é¹Ô¤ï¤ì¡¢
-¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤Ï¼ÂºÝ¤Ë½ñ¤¹þ¤ß¤¬¹Ô¤ï¤ì¤¿¥Ð¥¤¥È¿ôʬ
-²Ã»»¤µ¤ì¤ë¡£¥Õ¥¡¥¤¥ë¤¬
-.B O_APPEND
-¤Ç
-.BR open (2)
-¤µ¤ì¤¿¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤Ï½ñ¤¹þ¤ßÁ°¤Ë
-¥Õ¥¡¥¤¥ë¤ÎËöÈø¤ËÀßÄꤵ¤ì¤ë¡£
-¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤ÎÄ´À°¤È½ñ¤¹þ¤ßÁàºî¤Ï¥¢¥È¥ß¥Ã¥¯¤Ê½èÍý¤È¤·¤Æ
-¼Â¹Ô¤µ¤ì¤ë¡£
+seek 可能なファイル (つまり \fBlseek\fP(2) が適用できるファイル、例えば通常のファイル) では、
+書き込みは現在のファイルオフセットから行われ、 ファイルオフセットは実際に書き込みが行われたバイト数分 加算される。ファイルが \fBO_APPEND\fP
+で \fBopen\fP(2) された場合、ファイルオフセットは書き込み前に ファイルの末尾に設定される。
+ファイルオフセットの調整と書き込み操作はアトミックな処理として 実行される。
-.\"O POSIX requires that a
-.\"O .BR read (2)
-.\"O which can be proved to occur after a
-.\"O .BR write ()
-.\"O has returned returns the new data.
-.\"O Note that not all file systems are POSIX conforming.
-POSIX ¤Ï
-.BR write ()
-¤¬¹Ô¤Ê¤ï¤ì¤¿¸å¤Ë¼Â¹Ô¤·¤¿
-.BR read (2)
-¤¬
-¿·¤·¤¤¥Ç¡¼¥¿¤òÊÖ¤¹¤³¤È¤òÍ׵ᤷ¤Æ¤¤¤ë¡£
-Á´¤Æ¤Î¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¤¬ POSIX ½àµò¤Ç¤Ï¤Ê¤¤ÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£
-.\"O .SH "RETURN VALUE"
-.SH ÊÖ¤êÃÍ
-.\"O On success, the number of bytes written is returned (zero indicates
-.\"O nothing was written).
-.\"O On error, \-1 is returned, and \fIerrno\fP is set
-.\"O appropriately.
-À®¸ù¤·¤¿¾ì¹ç¡¢½ñ¤¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô¤¬ÊÖ¤µ¤ì¤ë
-(¥¼¥í¤Ï²¿¤â½ñ¤¹þ¤Þ¤ì¤Ê¤«¤Ã¤¿¤³¤È¤ò¼¨¤¹)¡£
-¥¨¥é¡¼¤Ê¤é¤Ð \-1 ¤¬ÊÖ¤µ¤ì¡¢\fIerrno\fP ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
+POSIX は \fBwrite\fP() が行なわれた後に実行した \fBread\fP(2) が 新しいデータを返すことを要求している。
+全てのファイルシステムが POSIX 準拠ではない点に注意すること。
+.SH 返り値
+成功した場合、書き込まれたバイト数が返される (ゼロは何も書き込まれなかったことを示す)。 エラーならば \-1 が返され、\fIerrno\fP
+が適切に設定される。
-.\"O If \fIcount\fP is zero and
-.\"O .I fd
-.\"O refers to a regular file, then
-.\"O .BR write ()
-.\"O may return a failure status if one of the errors below is detected.
-.\"O If no errors are detected,
-.\"O 0 will be returned without causing any other effect.
-.\"O If
-.\"O \fIcount\fP is zero and
-.\"O .I fd
-.\"O refers to a file other than a regular file,
-.\"O the results are not specified.
-\fIcount\fP ¤¬ 0 ¤Ç¡¢
-.I fd
-¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë (regular file) ¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¡¢
-.BR write ()
-¤Ï¸å½Ò¤Î¥¨¥é¡¼¤Î¤¤¤º¤ì¤«¤ò¸¡½Ð¤·¤¿¾ì¹ç¡¢¼ºÇÔ¤òÊÖ¤¹¤³¤È¤¬¤¢¤ë¡£
-¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢
-0 ¤òÊÖ¤·¡¢Â¾¤Ë²¿¤Î±Æ¶Á¤âÍ¿¤¨¤Ê¤¤¡£
-\fIcount\fP ¤¬ 0 ¤Ç¡¢
-.I fd
-¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë°Ê³°¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¡¢
-¤½¤Î·ë²Ì¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
-.\"O .SH ERRORS
-.SH ¥¨¥é¡¼
-.TP
-.B EAGAIN
-.\"O The file descriptor
-.\"O .I fd
-.\"O refers to a file other than a socket and has been marked nonblocking
-.\"O .RB ( O_NONBLOCK ),
-.\"O and the write would block.
-¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
-.I fd
-¤¬¥½¥±¥Ã¥È°Ê³°¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤Æ¡¢
-ÈóÄä»ß (nonblocking) ¥â¡¼¥É
-.RB ( O_NONBLOCK )
-¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢½ñ¤¹þ¤ß¤ò¹Ô¤¦¤ÈÄä»ß¤¹¤ë¾õ¶·¤Ë¤¢¤ë¡£
-.TP
-.\"O .BR EAGAIN " or " EWOULDBLOCK
-.BR EAGAIN " ¤Þ¤¿¤Ï " EWOULDBLOCK
+\fIcount\fP が 0 で、 \fIfd\fP が通常のファイル (regular file) を参照している場合、 \fBwrite\fP()
+は後述のエラーのいずれかを検出した場合、失敗を返すことがある。 エラーが検出されなかった場合は、 0 を返し、他に何の影響も与えない。 \fIcount\fP
+が 0 で、 \fIfd\fP が通常のファイル以外のファイルを参照している場合、 その結果は規定されていない。
+.SH エラー
+.TP
+\fBEAGAIN\fP
+ファイルディスクリプタ \fIfd\fP がソケット以外のファイルを参照していて、 非停止 (nonblocking) モード (\fBO_NONBLOCK\fP)
+に設定されており、書き込みを行うと停止する状況にある。
+.TP
+\fBEAGAIN\fP または \fBEWOULDBLOCK\fP
.\" Actually EAGAIN on Linux
-.\"O The file descriptor
-.\"O .I fd
-.\"O refers to a socket and has been marked nonblocking
-.\"O .RB ( O_NONBLOCK ),
-.\"O and the write would block.
-.\"O POSIX.1-2001 allows either error to be returned for this case,
-.\"O and does not require these constants to have the same value,
-.\"O so a portable application should check for both possibilities.
-¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
-.I fd
-¤¬¥½¥±¥Ã¥È¤ò»²¾È¤·¤Æ¤¤¤Æ¡¢ÈóÄä»ß (nonblocking) ¥â¡¼¥É
-.RB ( O_NONBLOCK )
-¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢½ñ¤¹þ¤ß¤ò¹Ô¤¦¤ÈÄä»ß¤¹¤ë¾õ¶·¤Ë¤¢¤ë¡£
-POSIX.1-2001 ¤Ï¡¢¤³¤Î¾ì¹ç¤Ë¤É¤Á¤é¤Î¥¨¥é¡¼¤òÊÖ¤¹¤³¤È¤âǧ¤á¤Æ¤ª¤ê¡¢
-¤³¤ì¤é 2 ¤Ä¤ÎÄê¿ô¤¬Æ±¤¸Ãͤò»ý¤Ä¤³¤È¤âµá¤á¤Æ¤¤¤Ê¤¤¡£
-¤·¤¿¤¬¤Ã¤Æ¡¢°Ü¿¢À¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢Î¾Êý¤Î²ÄǽÀ¤ò
-³Îǧ¤¹¤Ù¤¤Ç¤¢¤ë¡£
-.TP
-.B EBADF
-.\"O .I fd
-.\"O is not a valid file descriptor or is not open for writing.
-.I fd
-¤¬Í¸ú¤Ê¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¤«½ñ¤¹þ¤ß¤Î¤¿¤á¤Ë¥ª¡¼¥×¥ó
-(open) ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
-.TP
-.B EFAULT
-.\"O .I buf
-.\"O is outside your accessible address space.
-.I buf
-¤¬¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö (address space) ¤Î³°¤Ë¤¢¤ë¡£
-.TP
-.B EFBIG
-.\"O An attempt was made to write a file that exceeds the implementation-defined
-.\"O maximum file size or the process's file size limit,
-.\"O or to write at a position past the maximum allowed offset.
-¼ÂÁõÄêµÁ¤ÎºÇÂç¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤Þ¤¿¤Ï¥×¥í¥»¥¹¤Î¥Õ¥¡¥¤¥ë¥µ¥¤¥ºÀ©¸Â¤ò
-Ķ¤¨¤Æ¥Õ¥¡¥¤¥ë¤Ë½ñ¤¹þ¤â¤¦¤È¤·¤¿¡£
-¤Þ¤¿¤Ïµö²Ä¤µ¤ì¤¿¥ª¥Õ¥»¥Ã¥ÈÃͤ賦¤òĶ¤¨¤¿Àè¤Î°ÌÃÖ¤Ë
-½ñ¤¹þ¤â¤¦¤È¤·¤¿¡£
-.TP
-.B EINTR
-.\"O The call was interrupted by a signal before any data was written; see
-.\"O .BR signal (7).
-²¿¤Î¥Ç¡¼¥¿¤â½ñ¤«¤Ê¤¤´Ö¤Ë¥·¥°¥Ê¥ë¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿ (interrupt)¡£
-.BR signal (7)
-»²¾È¡£
-.TP
-.B EINVAL
-.\"O .I fd
-.\"O is attached to an object which is unsuitable for writing;
-.\"O or the file was opened with the
-.\"O .B O_DIRECT
-.\"O flag, and either the address specified in
-.\"O .IR buf ,
-.\"O the value specified in
-.\"O .IR count ,
-.\"O or the current file offset is not suitably aligned.
-.I fd
-¤¬½ñ¤¹þ¤ß¤¬ÉÔŬÀڤʥª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤¤¤ë¡£
-¤â¤·¤¯¤Ï¡¢¥Õ¥¡¥¤¥ë¤¬
-.B O_DIRECT
-¥Õ¥é¥°¤ò»ØÄꤷ¤Æ¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¤¬¡¢
-.I buf
-¤Ë»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¡¢
-.I count
-¤Ë»ØÄꤵ¤ì¤¿ÃÍ¡¢
-¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤Î¤¤¤º¤ì¤«¤Î
-¥¢¥é¥¤¥ó¥á¥ó¥È¤¬ÉÔŬÀڤǤ¢¤ë¡£
-.TP
-.B EIO
-.\"O A low-level I/O error occurred while modifying the inode.
-inode ¤Î½¤ÀµÃæ¤ËÄã¥ì¤Ù¥ë (low-level) I/O ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¡£
-.TP
-.B ENOSPC
-.\"O The device containing the file referred to by
-.\"O .I fd
-.\"O has no room for the data.
-.I fd
-¤Ë¤è¤Ã¤Æ»²¾È¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò´Þ¤à¥Ç¥Ð¥¤¥¹ (device) ¤Ë½½Ê¬¤Ê¶õ¤¤¬¤Ê¤¤¡£
-.TP
-.B EPIPE
-.\"O .I fd
-.\"O is connected to a pipe or socket whose reading end is closed.
-.\"O When this happens the writing process will also receive a
-.\"O .B SIGPIPE
-.\"O signal.
-.\"O (Thus, the write return value is seen only if the program
-.\"O catches, blocks or ignores this signal.)
-.I fd
-¤¬¥Ñ¥¤¥× (pipe) ¤«¥½¥±¥Ã¥È (socket) ¤ËÀܳ¤µ¤ì¤Æ¤ª¤ê¡¢
-¤½¤ÎÈ¿ÂЦ (Æɤ߹þ¤ß¦) ¤¬¥¯¥í¡¼¥º (close) ¤µ¤ì¤Æ¤¤¤ë¡£
-¤³¤ì¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¤Ï¡¢½ñ¤¹þ¤ß¤ò¹Ô¤Ê¤¦¥×¥í¥»¥¹¤Ï
-.B SIGPIPE
-¥·¥°¥Ê¥ë (signal)¤â¼õ¤±¤ë¡£
-(¤·¤¿¤¬¤Ã¤Æ¡¢¥×¥í¥°¥é¥à¤¬¤³¤Î¥·¥°¥Ê¥ë¤òÊá³Í (catch)¡¢Ää»ß (block)¡¢Ìµ»ë (ignore)
-¤·¤¿¾ì¹ç¤Î¤ß¡¢write ¤ÎÊÖ¤êÃͤò»²¾È¤Ç¤¤ë¡£)
+ファイルディスクリプタ \fIfd\fP がソケットを参照していて、非停止 (nonblocking) モード (\fBO_NONBLOCK\fP)
+に設定されており、書き込みを行うと停止する状況にある。 POSIX.1\-2001 は、この場合にどちらのエラーを返すことも認めており、 これら 2
+つの定数が同じ値を持つことも求めていない。 したがって、移植性が必要なアプリケーションでは、両方の可能性を 確認すべきである。
+.TP
+\fBEBADF\fP
+\fIfd\fP が有効なファイルディスクリプタでないか書き込みのためにオープン (open) されていない。
+.TP
+\fBEDESTADDRREQ\fP
+\fIfd\fP が、 \fBconnect\fP(2) を使って通信相手のアドレスが設定されていないデータグラムソケットを 参照している。
+.TP
+\fBEDQUOT\fP
+\fIfd\fP が参照するファイルを含むファイルシステムのディスクブロックのユーザクォータの上限に達している。
+.TP
+\fBEFAULT\fP
+\fIbuf\fP がアクセス可能なアドレス空間の外にある。
+.TP
+\fBEFBIG\fP
+実装定義の最大ファイルサイズまたはプロセスのファイルサイズ制限を 超えてファイルに書き込もうとした。
+または許可されたオフセット値の限界を超えた先の位置に 書き込もうとした。
+.TP
+\fBEINTR\fP
+何のデータも書かない間にシグナルにより割り込まれた (interrupt)。 \fBsignal\fP(7) 参照。
+.TP
+\fBEINVAL\fP
+\fIfd\fP が書き込みが不適切なオブジェクトを参照している。 もしくは、ファイルが \fBO_DIRECT\fP フラグを指定してオープンされているが、
+\fIbuf\fP に指定されたアドレス、 \fIcount\fP に指定された値、 現在のファイルオフセットのいずれかの アラインメントが不適切である。
+.TP
+\fBEIO\fP
+inode の修正中に低レべル (low\-level) I/O エラーが発生した。
+.TP
+\fBENOSPC\fP
+\fIfd\fP によって参照されるファイルを含むデバイス (device) に十分な空きがない。
+.TP
+\fBEPIPE\fP
+\fIfd\fP がパイプ (pipe) かソケット (socket) に接続されており、 その反対側 (読み込み側) がクローズ (close)
+されている。 これが発生した場合には、書き込みを行なうプロセスは \fBSIGPIPE\fP シグナル (signal)も受ける。
+(したがって、プログラムがこのシグナルを捕獲 (catch)、停止 (block)、無視 (ignore) した場合のみ、write
+の返り値を参照できる。)
.PP
-.\"O Other errors may occur, depending on the object connected to
-.\"O .IR fd .
-.I fd
-¤ËÀܳ¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤è¤Ã¤Æ¤Ï¡¢Â¾¤Î¥¨¥é¡¼¤¬µ¯¤³¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
-.\"O .SH "CONFORMING TO"
-.SH ½àµò
-SVr4, 4.3BSD, POSIX.1-2001.
-.\"O .\" SVr4 documents additional error
-.\"O .\" conditions EDEADLK, ENOLCK, ENOLNK, ENOSR, ENXIO, or ERANGE.
-.\" SVr4 ¤Ë¤Ï¾¤Ë EDEADLK, ENOLCK, ENOLNK,
-.\" ENOSR, ENXIO, ERANGE ¥¨¥é¡¼¤Ë¤Ä¤¤¤Æ¤Îµ½Ò¤¬¤¢¤ë¡£
+\fIfd\fP に接続されたオブジェクトによっては、他のエラーが起こるかもしれない。
+.SH 準拠
+.\" SVr4 documents additional error
+.\" conditions EDEADLK, ENOLCK, ENOLNK, ENOSR, ENXIO, or ERANGE.
+SVr4, 4.3BSD, POSIX.1\-2001.
+
+SVr4 では write が割り込まれると、データが書き込まれる直前ではなく、 その時点で \fBEINTR\fP が返る。
+.SH 注意
+\fBwrite\fP() が成功して返ってきても、データがディスクに記録されたことを 保証するものではない。
+実際、データのためのスペースが確保されたことすら保証されないという バグっぽい実装もある。 これを確実にする唯一の方法は、 全てのデータを write
+した後に \fBfsync\fP(2) を呼び出すことである。
-.\"O Under SVr4 a write may be interrupted and return
-.\"O .B EINTR
-.\"O at any point,
-.\"O not just before any data is written.
-SVr4 ¤Ç¤Ï write ¤¬³ä¤ê¹þ¤Þ¤ì¤ë¤È¡¢¥Ç¡¼¥¿¤¬½ñ¤¹þ¤Þ¤ì¤ëľÁ°¤Ç¤Ï¤Ê¤¯¡¢
-¤½¤Î»þÅÀ¤Ç
-.B EINTR
-¤¬Ê֤롣
-.\"O .SH NOTES
-.SH Ãí°Õ
-.\"O A successful return from
-.\"O .BR write ()
-.\"O does not make any guarantee that data has been committed to disk.
-.BR write ()
-¤¬À®¸ù¤·¤ÆÊ֤äƤ¤Æ¤â¡¢¥Ç¡¼¥¿¤¬¥Ç¥£¥¹¥¯¤ËµÏ¿¤µ¤ì¤¿¤³¤È¤ò
-Êݾڤ¹¤ë¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
-.\"O In fact, on some buggy implementations, it does not even guarantee
-.\"O that space has successfully been reserved for the data.
-¼ÂºÝ¡¢¥Ç¡¼¥¿¤Î¤¿¤á¤Î¥¹¥Ú¡¼¥¹¤¬³ÎÊݤµ¤ì¤¿¤³¤È¤¹¤éÊݾڤµ¤ì¤Ê¤¤¤È¤¤¤¦
-¥Ð¥°¤Ã¤Ý¤¤¼ÂÁõ¤â¤¢¤ë¡£
-.\"O The only way to be sure is to call
-.\"O .BR fsync (2)
-.\"O after you are done writing all your data.
-¤³¤ì¤ò³Î¼Â¤Ë¤¹¤ëÍ£°ì¤ÎÊýË¡¤Ï¡¢
-Á´¤Æ¤Î¥Ç¡¼¥¿¤ò write ¤·¤¿¸å¤Ë
-.BR fsync (2)
-¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤Ç¤¢¤ë¡£
+\fBwrite\fP() が 1 バイトも書き込まないうちにシグナルハンドラにより割り込まれた場合、 \fBwrite\fP() はエラー \fBEINTR\fP
+で失敗する。 1バイトでも書き込んだ後で割り込まれた場合には、 \fBwrite\fP() は成功し、書き込んだバイト数を返す。
+.SH バグ
+According to POSIX.1\-2008/SUSv4 Section XSI 2.9.7 ("Thread Interactions with
+Regular File Operations"):
-.\"O If a
-.\"O .BR write ()
-.\"O is interrupted by a signal handler before any bytes are written,
-.\"O then the call fails with the error
-.\"O .BR EINTR ;
-.\"O if it is interrupted after at least one byte has been written,
-.\"O the call succeeds, and returns the number of bytes written.
-.BR write ()
-¤¬ 1 ¥Ð¥¤¥È¤â½ñ¤¹þ¤Þ¤Ê¤¤¤¦¤Á¤Ë¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¡¢
-.BR write ()
-¤Ï¥¨¥é¡¼
-.B EINTR
-¤Ç¼ºÇÔ¤¹¤ë¡£
-1¥Ð¥¤¥È¤Ç¤â½ñ¤¹þ¤ó¤À¸å¤Ç³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
-.BR write ()
-¤ÏÀ®¸ù¤·¡¢½ñ¤¹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
-.\"O .SH "SEE ALSO"
-.SH ´ØÏ¢¹àÌÜ
-.BR close (2),
-.BR fcntl (2),
-.BR fsync (2),
-.BR ioctl (2),
-.BR lseek (2),
-.BR open (2),
-.BR pwrite (2),
-.BR read (2),
-.BR select (2),
-.BR writev (2),
-.BR fwrite (3)
+.RS 4
+All of the following functions shall be atomic with respect to each other in
+the effects specified in POSIX.1\-2008 when they operate on regular files or
+symbolic links: ...
+.RE
+
+.\" http://thread.gmane.org/gmane.linux.kernel/1649458
+.\" From: Michael Kerrisk (man-pages <mtk.manpages <at> gmail.com>
+.\" Subject: Update of file offset on write() etc. is non-atomic with I/O
+.\" Date: 2014-02-17 15:41:37 GMT
+.\" Newsgroups: gmane.linux.kernel, gmane.linux.file-systems
+.\" commit 9c225f2655e36a470c4f58dbbc99244c5fc7f2d4
+.\" Author: Linus Torvalds <torvalds@linux-foundation.org>
+.\" Date: Mon Mar 3 09:36:58 2014 -0800
+.\"
+.\" vfs: atomic f_pos accesses as per POSIX
+Among the APIs subsequently listed are \fBwrite\fP() and \fBwritev\fP(2). And
+among the effects that should be atomic across threads (and processes) are
+updates of the file offset. However, on Linux before version 3.14, this was
+not the case: if two processes that share an open file description (see
+\fBopen\fP(2)) perform a \fBwrite\fP() (or \fBwritev\fP(2)) at the same time, then
+the I/O operations were not atomic with respect updating the file offset,
+with the result that the blocks of data output by the two processes might
+(incorrectly) overlap. This problem was fixed in Linux 3.14.
+.SH 関連項目
+\fBclose\fP(2), \fBfcntl\fP(2), \fBfsync\fP(2), \fBioctl\fP(2), \fBlseek\fP(2), \fBopen\fP(2),
+\fBpwrite\fP(2), \fBread\fP(2), \fBselect\fP(2), \fBwritev\fP(2), \fBfwrite\fP(3)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.76 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。