fn write(fd: fd_t, bytes: []const u8) WriteError!usize

Write to a file descriptor. Retries when interrupted by a signal. Returns the number of bytes written. If nonzero bytes were supplied, this will be nonzero.

Note that a successful write() may transfer fewer than count bytes. Such partial writes can occur for various reasons; for example, because there was insufficient space on the disk device to write all of the requested bytes, or because a blocked write() to a socket, pipe, or similar was interrupted by a signal handler after it had transferred some, but before it had transferred all of the requested bytes. In the event of a partial write, the caller can make another write() call to transfer the remaining bytes. The subsequent call will either transfer further bytes or may result in an error (e.g., if the disk is now full).

For POSIX systems, if fd is opened in non blocking mode, the function will return error.WouldBlock when EAGAIN is received. On Windows, if the application has a global event loop enabled, I/O Completion Ports are used to perform the I/O. error.WouldBlock is not possible on Windows.

Linux has a limit on how many bytes may be transferred in one write call, which is 0x7ffff000 on both 64-bit and 32-bit systems. This is due to using a signed C int as the return value, as well as stuffing the errno codes into the last 4096 values. This is noted on the write man page. The limit on Darwin is 0x7fffffff, trying to read more than that returns EINVAL. The corresponding POSIX limit is math.maxInt(isize).

Parameters

fd: fd_t,
bytes: []const u8,