write(2) System Calls Manual write(2) write - LIBRARY Standard C library (libc, -lc) #include ssize_t write(int fd, const void buf[.count], size_t count); write() count , buf, , fd. count , , , RLIMIT_FSIZE (. setrlimit(2)), count . (. pipe(7).) , (.., lseek(2), , ), , . open(2) O_APPEND, . . POSIX , read(2), write(), . , POSIX. POSIX.1, count SSIZE_MAX, ; Linux. On success, the number of bytes written is returned. On error, -1 is returned, and errno is set to indicate the error. , write() count . ; , - , - write() , , , . write() . , (, ). count fd , write() , . , 0 - . count fd , . EAGAIN fd , / (O_NONBLOCK), . . open(2) O_NONBLOCK. EAGAIN EWOULDBLOCK fd , / (O_NONBLOCK), . POSIX.1-2001 , , . EBADF fd . EDESTADDRREQ fd , connect(2) . EDQUOT , fd. EFAULT buf . EFBIG , , . EINTR , - ; signal(7). EINVAL fd , ; O_DIRECT, buf, count . EIO /. (write-back) write(), . Linux 4.13 , . write() fsync(2) ( , write()). EIO , . fcntl(2). ENOSPC , , fd, . EPERM (file seal); fcntl(2). EPIPE fd , . , SIGPIPE. ( , , .) , fd, . POSIX.1-2008. SVr4, 4.3BSD, POSIX.1-2001. SVr4, ( EINTR), - . write() , . , NFS, , . write(), fsync(2) close(2). -- fsync(2) . write() , EINTR; , , . Linux write() ( ) 0x7ffff000 (2 147 479 552) , , ( 32-, 64- ). write() - . , , write() , . POSIX.1-2008/SUSv4 XSI 2.9.7 ("Thread Interactions with Regular File Operations"): , , POSIX.1-2008: Among the APIs subsequently listed are write() and writev(2). And among the effects that should be atomic across threads (and processes) are updates of the file offset. However, before Linux 3.14, this was not the case: if two processes that share an open file description (see open(2)) perform a write() (or writev(2)) at the same time, then the I/O operations were not atomic with respect to updating the file offset, with the result that the blocks of data output by the two processes might (incorrectly) overlap. This problem was fixed in Linux 3.14. . close(2), fcntl(2), fsync(2), ioctl(2), lseek(2), open(2), pwrite(2), read(2), select(2), writev(2), fwrite(3) Azamat Hackimov Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . write(2)