HP 3000 Manuals

write [ MPE/iX Developer's Kit Reference Manual Volume I ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume I

write 

Writes data to a file.

Syntax 

     ssize_t write (int fildes, const void *buffer, size_t nbyte);

Parameters 

fildes     An open file descriptor.

buffer     A pointer to a buffer containing data to be written.  The size
           of the buffer must be greater than nbyte.

nbyte      The maximum number of bytes to write.

Return Values 

>=0        Success.  An integer indicating the number of bytes actually
           written is returned.

-1         An error occurred.  No data is written, and errno is set to
           indicate the error condition.

Description 

The write() function attempts to writes nbyte bytes from the buffer
pointed to by buffer to the open file associated with the open file
descriptor fildes.

On a file capable of seeking, write() starts from the current file offset
position.  Before successful return from write(), the file offset is
incremented by the number of bytes actually written.  If the incremented
file offset is greater than the EOF of the file, the EOF of the file is
set to the new file offset.

If the O_APPEND file status flag is set, the file offset is set to the
end of the file prior to each write.

On a file not capable of seeking, write() starts from the current
position.  (The file offset for such a file is undefined.)

Upon successful completion, the write() function returns the actual
number of bytes written to the file and, if nbyte is greater than 0,
marks for update the st_ctime and st_mtime time fields of the file.

If write() requests that more bytes be written than there is room for
(for example, the physical end of medium), only as many bytes as there is
room for are written.  In this case, the next write to the file of a
nonzero number of bytes fails, and an error is returned.

If nbytes is zero, the write() function writes zero bytes of data.  In
this case, the file offset position is not changed and no time fields are
marked for update.

Implementation Considerations 

Refer to the EFBIG, EFAULT, EIMPL, and ESYSERR error descriptions below.

Signals generated for the calling process during execution of write() are
deferred from delivery until completion of this function.

Errors 

If an error occurs, errno is set to one of the following values:

EBADF             CAUSE           The fildes parameter is not a valid open file
                                  descriptor open for writing.
                  ACTION          Pass a valid open file descriptor of a file open for
                                  writing by the calling process.

EFAULT            CAUSE           The system detected a NULL or bad address in
                                  attempting to use the buffer parameter.
                  ACTION          Make sure that the pointer is correctly initialized.

EFBIG             CAUSE           The file size has exceeded the file limit.  The
                                  default file limit is 2 gigabytes.
                  ACTION          Reduce the size of the file.

          Table 4-0.  (cont.) 

EIMPL             CAUSE           The file size has exceeded the disk space limit
                                  established by the MPE/iX accounting facility.
                  ACTION          Make sure that the MPE/iX accounting facility allows
                                  you to increase the size of the file.

ENOSPC            CAUSE           There is no free space remaining on the device
                                  containing the file.
                  ACTION          Deallocate space on the device.

ESYSERR           CAUSE           An operating system error has occurred that does not
                                  map directly to any of the above errors.
                  ACTION          Examine the MPE/iX error stack for the type of system
                                  error.

See Also 

creat(), dup(), lseek(), open(), POSIX.1 (Section 6.4.2)



MPE/iX 5.0 Documentation