Writes data from a buffer to a file.
#include <io.h> int write (int handle, const char *buffer, unsigned int count);
handle
buffer
count
Writing begins at the current file pointer position. If the file is open for appending, the operation begins at the end-of-file. After writing, the file pointer increases by the number of bytes actually written.
When writing more than 2 gigabytes to a file, the return value must be of type unsigned integer. However, the maximum number of bytes that can be written to a file at one time is 4 gigabytes -2, since 4 gigabytes -1 (or 0xFFFFFFF) is indistinguishable from -1 and would return an error.
When write is received, the file descriptor is checked for text or binary mode.
If the file was opened in text mode, the output buffer is written up to each <LF> character, then a <CR><LF> pair is written separately. If multiple threads are writing to the same output, scrambling will occur in text mode; use binary mode. When writing to files opened in text mode, write treats a <Ctrl-Z> character as the logical end-of-file. When writing to a device, write treats a <Ctrl-Z> in the buffer as an output terminator.
count
, as when disk space is filled before count
bytes are written.
EBADF | Invalid file descriptor or file not opened for writing. |
ENOSPC | No space left on device. |
Versions | Defined in | Include | Link to |
---|---|---|---|
INtime 3.0 | intime/rt/include/io.h | io.h | clib.lib |