Imported upstream version 1.5
[manpages-zh.git] / src / man2 / write.2
blob2d27cf8a589054afc531aaceb21796ce09e1481c
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\"                               1993 Michael Haardt, Ian Jackson.
5 .\"
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 .\"
26 .\" Modified Sat Jul 24 13:35:59 1993 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified Sun Nov 28 17:19:01 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Sat Jan 13 12:58:08 1996 by Michael Haardt
29 .\"   <michael@cantor.informatik.rwth-aachen.de>
30 .\" Modified Sun Jul 21 18:59:33 1996 by Andries Brouwer <aeb@cwi.nl>
31 .\" 中文版版权所有 byeyear AND www.linuxforum.net 2002
32 .\"
33 .TH WRITE 2 "13 January 1996" "Linux 2.0.32" "Linux Programmer's Manual"
34 .SH NAME
35 write \-在一个文件描述符上执行写操作
36 .SH 概述
37 .B #include <unistd.h>
38 .sp
39 .BI "ssize_t write(int " fd ", const void *" buf ", size_t " count );
40 .SH 描述
41 .B write
42 向文件描述符
43 .I fd
44 所引用的文件中写入
45
46 .I buf
47 开始的缓冲区中
48 .I count
49 字节的数据.
50 POSIX规定,当使用了\fBwrite()\fP之后再使用
51 \fBread()\fP,那么读取到的应该是更新后的数据.
52 但请注意并不是所有的文件系统都是
53 POSIX兼容的.
54 .SH "返回值"
55 成功时返回所写入的字节数(若为零则表示没有写入数据).
56 错误时返回\-1,并置\fIerrno\fP为相应值.
57 若\fIcount\fP为零,对于普通文件无任何影响,但对特殊文件
58 将产生不可预料的后果.
59 .SH 错误代码
60 .TP
61 .B EBADF
62 .I fd
63 不是一个合法的文件描述符或者没有以写方式打开.
64 .TP
65 .B EINVAL
66 .I fd
67 所指向的对象不可写.
68 .TP
69 .B EFAULT
70 .I buf
71 不在用户可访问地址空间内.
72 .TP
73 .B EPIPE
74 .I fd
75 连接到一个管道,或者套接字的读方向一端已关闭.此时写进程
76 将接收到
77 .B SIGPIPE
78 信号;如果此信号被捕获,阻塞或忽略,那么将返回错误
79 .B EPIPE.
80 .TP
81 .B EAGAIN
82 读操作阻塞,但使用
83 .B O_NONBLOCK
84 指定了非阻塞式输入输出.
85 .TP
86 .B EINTR
87 在写数据以前调用被信号中断.
88 .TP
89 .B ENOSPC
90 .I fd
91 指向的文件所在的设备无可用空间.
92 .TP
93 .B EIO
94 当编辑一个节点时发生了底层输入输出错误.
95 .PP
96 可能发生了其他错误,取决于
97 .IR fd
98 所连接的对象.
99 .SH "兼容于"
100 SVr4, SVID, POSIX, X/OPEN, 4.3BSD.
101 SVr4文档添加了以下错误代码:
102 EDEADLK, EFBIG, ENOLCK, ENOLNK, ENOSR,
103 ENXIO, EPIPE,或者ERANGE.
104 对于SVr4有可能在写入部分数据时发生中断并返回EINTR. 
105 .SH "参见"
106 .BR open (2),
107 .BR read (2),
108 .BR fcntl (2),
109 .BR close (2),
110 .BR lseek (2),
111 .BR select (2),
112 .BR ioctl (2),
113 .BR fsync (2),
114 .BR fwrite (3)
116 .SH "[中文版维护人]"
117 .B byeyear <love_my_love@263.net >
118 .SH "[中文版最新更新]"
119 .B 2002.02.07
120 .SH "《中国linux论坛man手册页翻译计划》:"
121 .BI http://cmpp.linuxforum.net