📄 write.2
字号:
.\" Copyright (c) 1980, 1991, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)write.2 8.5 (Berkeley) 4/2/94.\".Dd April 2, 1994.Dt WRITE 2.Os BSD 4.Sh NAME.Nm write ,.Nm writev.Nd write output.Sh SYNOPSIS.Fd #include <sys/types.h>.Fd #include <sys/uio.h>.Fd #include <unistd.h>.Ft ssize_t.Fn write "int d" "const void *buf" "size_t nbytes".Ft ssize_t.Fn writev "int d" "const struct iovec *iov" "int iovcnt".Sh DESCRIPTION.Fn Writeattempts to write.Fa nbytesof data to the object referenced by the descriptor.Fa dfrom the buffer pointed to by.Fa buf ..Fn Writevperforms the same action, but gathers the output datafrom the .Fa iovcntbuffers specified by the members of the.Fa iovarray: iov[0], iov[1], ..., iov[iovcnt\|-\|1]..PpFor .Fn writev ,the .Fa iovecstructure is defined as:.Pp.Bd -literal -offset indent -compactstruct iovec { void *iov_base; size_t iov_len;};.Ed.PpEach .Fa iovecentry specifies the base address and length of an areain memory from which data should be written..Fn Writevwill always write a complete area before proceedingto the next..PpOn objects capable of seeking, the.Fn writestarts at a positiongiven by the pointer associated with.Fa d ,see.Xr lseek 2 .Upon return from.Fn write ,the pointer is incremented by the number of bytes which were written..PpObjects that are not capable of seeking always write from the currentposition. The value of the pointer associated with such an objectis undefined..PpIf the real user is not the super-user, then.Fn writeclears the set-user-id bit on a file.This prevents penetration of system securityby a user who.Dq capturesa writable set-user-id fileowned by the super-user..PpWhen using non-blocking I/O on objects such as sockets that are subjectto flow control,.Fn writeand.Fn writevmay write fewer bytes than requested;the return value must be noted,and the remainder of the operation should be retried when possible..Sh RETURN VALUESUpon successful completion the number of bytes which were writtenis returned. Otherwise a -1 is returned and the global variable.Va errnois set to indicate the error..Sh ERRORS.Fn Writeand.Fn writevwill fail and the file pointer will remain unchanged if:.Bl -tag -width Er.It Bq Er EBADF.Fa Dis not a valid descriptor open for writing..It Bq Er EPIPEAn attempt is made to write to a pipe that is not openfor reading by any process..It Bq Er EPIPEAn attempt is made to write to a socket of type.DV SOCK_STREAMthat is not connected to a peer socket..It Bq Er EFBIGAn attempt was made to write a file that exceeds the process'sfile size limit or the maximum file size..It Bq Er EFAULTPart of.Fa iovor data to be written to the filepoints outside the process's allocated address space..It Bq Er EINVALThe pointer associated with.Fa dwas negative..It Bq Er ENOSPCThere is no free space remaining on the file systemcontaining the file..It Bq Er EDQUOTThe user's quota of disk blocks on the file systemcontaining the file has been exhausted..It Bq Er EIOAn I/O error occurred while reading from or writing to the file system..It Bq Er EAGAINThe file was marked for non-blocking I/O,and no data could be written immediately..El.PpIn addition, .Fn writevmay return one of the following errors:.Bl -tag -width Er.It Bq Er EINVAL.Fa Iovcntwas less than or equal to 0, or greater than.Dv UIO_MAXIOV ..It Bq Er EINVALOne of the.Fa iov_lenvalues in the.Fa iovarray was negative..It Bq Er EINVALThe sum of the.Fa iov_lenvalues in the.Fa iovarray overflowed a 32-bit integer..El.Sh SEE ALSO.Xr fcntl 2 ,.Xr lseek 2 ,.Xr open 2 ,.Xr pipe 2 ,.Xr select 2.Sh STANDARDS.Fn Writeis expected to conform to IEEE Std 1003.1-1988.Pq Dq Tn POSIX ..Sh HISTORYThe.Fn writevfunction callappeared in.Bx 4.2 .A.Nm writefunction callappeared inVersion 6 AT&T UNIX.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -