.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" This manpage is Copyright (C) 1992 Drew Eckhardt; .\" 1993 Michael Haardt, Ian Jackson. .\" .\" 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. .\" .\" Modified Sat Jul 24 13:35:59 1993 by Rik Faith .\" Modified Sun Nov 28 17:19:01 1993 by Rik Faith .\" Modified Sat Jan 13 12:58:08 1996 by Michael Haardt .\" .\" Modified Sun Jul 21 18:59:33 1996 by Andries Brouwer .\" 中文版版權所有 byeyear AND www.linuxforum.net 2002 .\" .TH WRITE 2 "13 January 1996" "Linux 2.0.32" "Linux Programmer's Manual" .SH NAME write \-在一個檔案描述符上執行寫操作 .SH 概述 .B #include .sp .BI "ssize_t write(int " fd ", const void *" buf ", size_t " count ); .SH 描述 .B write 向檔案描述符 .I fd 所引用的檔案中寫入 從 .I buf 開始的緩沖區中 .I count 字節的數據. POSIX規定,當使用了\fBwrite()\fP之後再使用 \fBread()\fP,那麼讀取到的應該是更新後的數據. 但請注意並不是所有的檔案系統都是 POSIX相容的. .SH "返回值" 成功時返回所寫入的字節數(若為零則表示沒有寫入數據). 錯誤時返回\-1,並置\fIerrno\fP為相應值. 若\fIcount\fP為零,對於普通檔案無任何影響,但對特殊檔案 將產生不可預料的後果. .SH 錯誤代碼 .TP .B EBADF .I fd 不是一個合法的檔案描述符或者沒有以寫方式打開. .TP .B EINVAL .I fd 所指向的對象不可寫. .TP .B EFAULT .I buf 不在使用者可訪問地址空間內. .TP .B EPIPE .I fd 連接到一個管道,或者套接字的讀方向一端已關閉.此時寫進程 將接收到 .B SIGPIPE 信號;如果此信號被捕獲,阻塞或忽略,那麼將返回錯誤 .B EPIPE. .TP .B EAGAIN 讀操作阻塞,但使用 .B O_NONBLOCK 指定了非阻塞式輸入輸出. .TP .B EINTR 在寫數據以前調用被信號中斷. .TP .B ENOSPC .I fd 指向的檔案所在的設備無可用空間. .TP .B EIO 當編輯一個節點時發生了底層輸入輸出錯誤. .PP 可能發生了其他錯誤,取決於 .IR fd 所連接的對象. .SH "相容於" SVr4, SVID, POSIX, X/OPEN, 4.3BSD. SVr4文件添加了以下錯誤代碼: EDEADLK, EFBIG, ENOLCK, ENOLNK, ENOSR, ENXIO, EPIPE,或者ERANGE. 對於SVr4有可能在寫入部分數據時發生中斷並返回EINTR. .SH "參見" .BR open (2), .BR read (2), .BR fcntl (2), .BR close (2), .BR lseek (2), .BR select (2), .BR ioctl (2), .BR fsync (2), .BR fwrite (3) .SH "[中文版維護人]" .B byeyear .SH "[中文版最新更新]" .B 2002.02.07 .SH "《中國linux論壇man手冊頁翻譯計劃》:" .BI http://cmpp.linuxforum.net