WRITE(2) HP Integral PC WRITE(2) WRITE(2) HP Integral PC WRITE(2) WRITE(2) HP Integral PC WRITE(2) WRITE(2) HP Integral PC WRITE(2) NAME NAME NAME NAME write - write on a file SYNOPSIS SYNOPSIS SYNOPSIS SYNOPSIS int write (fildes, buf, nbyte) int fildes; char *buf; unsigned nbyte; DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION Fildes is a file descriptor obtained from a creat , open , dup , fcntl , or pipe system call. Write attempts to write nbyte bytes from the buffer pointed to by buf to the file associated with the fildes . If the user is not the owner of the file, or is not the super-user, the set-user-id bit of the file is cleared. On devices capable of seeking, the actual writing of data proceeds from the position in the file indicated by the file pointer. Upon return from write , the file pointer is incremented by the number of bytes actually written. On devices incapable of seeking, writing always takes place starting at the current position. The value of a file pointer associated with such a device is undefined. If the O_APPEND flag of the file status flags is set, the file pointer will be set to the end of the file prior to each write. Write will fail and the file pointer will remain unchanged if one or more of the following are true: Fildes is not a valid file descriptor open for writing. [EBADF] An attempt is made to write to a pipe that is not open for reading by any process. [EPIPE and SIGPIPE signal] An attempt was made to write a file that exceeds the process's file size limit or the maximum file size. See ulimit (2). [EFBIG] Buf points outside the process's allocated address space. [EFAULT] If a write requests that more bytes be written than there is room for (e.g., the ulimit (see ulimit (2)) or the physical end of a medium), only as many bytes as there is room for will be written. For example, suppose there is space for 20 bytes more in a file before reaching a limit. A write of Hewlett-Packard - 1 - (printed 12/11/84) WRITE(2) HP Integral PC WRITE(2) WRITE(2) HP Integral PC WRITE(2) WRITE(2) HP Integral PC WRITE(2) WRITE(2) HP Integral PC WRITE(2) 512 bytes will return 20. The next write of a non-zero number of bytes will give a failure return (except as noted below). If the file being written is a pipe (or FIFO), no partial writes will be permitted. The follwoing conditions apply: if the O_NDELAY flag of the file flag word is set: if nbyte is less than or equal to 5120 and there is sufficient room in the pipe or FIFO, then the write is successful and returns the number of bytes written; if nbyte is greater than 5120 and there is sufficient room in the pipe or FIFO, the write fails and returns -1; if nbyte is less than or equal to 5120 but there is not enough room in the pipe or FIFO, the write executes correctly and returns 0. if the O_NDELAY flag of the file flag word is clear: the write always executes correctly and returns the number of bytes written. RETURN VALUE RETURN VALUE RETURN VALUE RETURN VALUE Upon successful completion the number of bytes actually written is returned. Otherwise, -1 is returned and errno is set to indicate the error. DIAGNOSTICS DIAGNOSTICS DIAGNOSTICS DIAGNOSTICS On the hp 207 all writes to files cause data to be immediately written out to the physical media. For the purposes of efficiency, data to be written to files should be buffered up as much as possible to minimize the number of physical disc accesses. SEE ALSO SEE ALSO SEE ALSO SEE ALSO creat(2), dup(2), lseek(2), open(2), pipe(2), ulimit(2). Hewlett-Packard - 2 - (printed 12/11/84)