147208Scael.\" Copyright (c) 1980, 1991 Regents of the University of California. 247208Scael.\" All rights reserved. 320053Smckusick.\" 447208Scael.\" %sccs.include.redist.man% 520053Smckusick.\" 6*53310Sbostic.\" @(#)write.2 6.8 (Berkeley) 05/04/92 747208Scael.\" 847208Scael.Dd 947208Scael.Dt WRITE 2 1047208Scael.Os BSD 4 1147208Scael.Sh NAME 1247208Scael.Nm write , 1347208Scael.Nm writev 1447208Scael.Nd write output 1547208Scael.Sh SYNOPSIS 1647208Scael.Fd #include <unistd.h> 1747208Scael.Fd #include <sys/types.h> 1847208Scael.Fd #include <sys/uio.h> 1947208Scael.Ft ssize_t 2053284Sbostic.Fn write "int d" "const void *buf" "size_t nbytes" 2147208Scael.Ft int 2247208Scael.Fn writev "int d" "struct iovec *iov" "int iovcnt" 2347208Scael.Sh DESCRIPTION 2447208Scael.Fn Write 2520054Smckusickattempts to write 2647208Scael.Fa nbytes 2720054Smckusickof data to the object referenced by the descriptor 2847208Scael.Fa d 2920054Smckusickfrom the buffer pointed to by 3047208Scael.Fa buf . 3147208Scael.Fn Writev 3220054Smckusickperforms the same action, but gathers the output data 3326400Slepreaufrom the 3447208Scael.Fa iovcnt 3526400Slepreaubuffers specified by the members of the 3647208Scael.Fa iov 3747208Scaelarray: iov[0], iov[1], ..., iov[iovcnt\|-\|1]. 3847208Scael.Pp 3926400SlepreauFor 4047208Scael.Fn writev , 4126400Slepreauthe 4247208Scael.Fa iovec 4347208Scaelstructure is defined as: 4447208Scael.Bd -literal -offset indent -compact 4526400Slepreaustruct iovec { 4653284Sbostic void *iov_base; 4753284Sbostic int iov_len; 4826400Slepreau}; 4947208Scael.Ed 5047208Scael.Pp 5126400SlepreauEach 5247208Scael.Fa iovec 5326400Slepreauentry specifies the base address and length of an area 5426400Slepreauin memory from which data should be written. 5547208Scael.Fn Writev 5626400Slepreauwill always write a complete area before proceeding 5726400Slepreauto the next. 5847208Scael.Pp 5947208ScaelOn objects capable of seeking, the 6047208Scael.Fn write 6147208Scaelstarts at a position 6220054Smckusickgiven by the pointer associated with 6347208Scael.Fa d , 6420054Smckusicksee 6547208Scael.Xr lseek 2 . 6620054SmckusickUpon return from 6747208Scael.Fn write , 6847208Scaelthe pointer is incremented by the number of bytes which were written. 6947208Scael.Pp 7020054SmckusickObjects that are not capable of seeking always write from the current 7120054Smckusickposition. The value of the pointer associated with such an object 7220054Smckusickis undefined. 7347208Scael.Pp 7420054SmckusickIf the real user is not the super-user, then 7547208Scael.Fn write 7620053Smckusickclears the set-user-id bit on a file. 7720053SmckusickThis prevents penetration of system security 7820053Smckusickby a user who 7947208Scael.Dq captures 8047208Scaela writable set-user-id file 8120053Smckusickowned by the super-user. 8247208Scael.Pp 8328125SkarelsWhen using non-blocking I/O on objects such as sockets that are subject 8428125Skarelsto flow control, 8547208Scael.Fn write 8628125Skarelsand 8747208Scael.Fn writev 8828125Skarelsmay write fewer bytes than requested; 8928125Skarelsthe return value must be noted, 9028125Skarelsand the remainder of the operation should be retried when possible. 9147208Scael.Sh RETURN VALUES 9247208ScaelUpon successful completion the number of bytes which were written 9347208Scaelis returned. Otherwise a -1 is returned and the global variable 9447208Scael.Va errno 9520054Smckusickis set to indicate the error. 9647208Scael.Sh ERRORS 9747208Scael.Fn Write 9826400Slepreauand 9947208Scael.Fn writev 10047208Scaelwill fail and the file pointer will remain unchanged if: 10147208Scael.Bl -tag -width Er 10247208Scael.It Bq Er EBADF 10347208Scael.Fa D 10447208Scaelis not a valid descriptor open for writing. 10547208Scael.It Bq Er EPIPE 10620054SmckusickAn attempt is made to write to a pipe that is not open 10720054Smckusickfor reading by any process. 10847208Scael.It Bq Er EPIPE 10947208ScaelAn attempt is made to write to a socket of type 11047208Scael.DV SOCK_STREAM 11123831Ssechrestthat is not connected to a peer socket. 11247208Scael.It Bq Er EFBIG 11320054SmckusickAn attempt was made to write a file that exceeds the process's 11420054Smckusickfile size limit or the maximum file size. 11547208Scael.It Bq Er EFAULT 11647208ScaelPart of 11747208Scael.Fa iov 11847208Scaelor data to be written to the file 11920054Smckusickpoints outside the process's allocated address space. 12047208Scael.It Bq Er EINVAL 12126400SlepreauThe pointer associated with 12247208Scael.Fa d 12326400Slepreauwas negative. 12447208Scael.It Bq Er ENOSPC 12524439SmckusickThere is no free space remaining on the file system 12624439Smckusickcontaining the file. 12747208Scael.It Bq Er EDQUOT 12824439SmckusickThe user's quota of disk blocks on the file system 12924439Smckusickcontaining the file has been exhausted. 13047208Scael.It Bq Er EIO 13124439SmckusickAn I/O error occurred while reading from or writing to the file system. 132*53310Sbostic.It Bq Er EAGAIN 13328125SkarelsThe file was marked for non-blocking I/O, 13428125Skarelsand no data could be written immediately. 13547208Scael.El 13647208Scael.Pp 13726400SlepreauIn addition, 13847208Scael.Fn writev 13926400Slepreaumay return one of the following errors: 14047208Scael.Bl -tag -width Er 14147208Scael.It Bq Er EINVAL 14247208Scael.Fa Iovcnt 14326400Slepreauwas less than or equal to 0, or greater than 16. 14447208Scael.It Bq Er EINVAL 14526400SlepreauOne of the 14647208Scael.Fa iov_len 14726400Slepreauvalues in the 14847208Scael.Fa iov 14926400Slepreauarray was negative. 15047208Scael.It Bq Er EINVAL 15126400SlepreauThe sum of the 15247208Scael.Fa iov_len 15326400Slepreauvalues in the 15447208Scael.Fa iov 15526400Slepreauarray overflowed a 32-bit integer. 15647208Scael.El 15747208Scael.Sh SEE ALSO 15847208Scael.Xr fcntl 2 , 15947208Scael.Xr lseek 2 , 16047208Scael.Xr open 2 , 16147208Scael.Xr pipe 2 , 16247208Scael.Xr select 2 16347208Scael.Sh STANDARDS 16447208Scael.Fn Write 16547208Scaelis expected to conform to IEEE Std 1003.1-1988 16647208Scael.Pq Dq Tn POSIX . 16747208Scael.Sh HISTORY 16847208ScaelThe 16947208Scael.Fn writev 17047208Scaelfunction call 17147208Scaelappeared in 17247208Scael.Bx 4.2 . 17347208ScaelA 17447208Scael.Nm write 17547208Scaelfunction call 17647208Scaelappeared in 17747208ScaelVersion 6 AT&T UNIX. 178