Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.unix.programmer > #13635
| From | Steve Keller <keller.steve@gmx.de> |
|---|---|
| Newsgroups | comp.unix.programmer |
| Subject | Re: How to check for error with write(2) |
| Date | 2021-12-17 04:35 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <sph0hg$1u7q$1@gioia.aioe.org> (permalink) |
| References | <spfuo5$lb0$1@gioia.aioe.org> <b6f9685b-3f40-4b2a-8e1d-1fe2f08a5f11n@googlegroups.com> |
Philip Guenther <guenther@gmail.com> writes: > Uh, actually look at the return value and see if it matches the > number of bytes you asked to write: on partial success, write() will > return less than the requested count. Note that a short write won't > change errno; if you need to know why it was unable to write more > than you need to keep calling write() until it completely fails > (usually the next call) and check errno then. > > To quote the (next issue) of the POSIX spec's description of write(): > If a write( ) requests that more bytes be written than > there is room for (for example, the file size limit of the > process or the physical end of a medium), only as many > bytes as there is room for shall be written. For example, > suppose there is space for 20 bytes more in a file before > reaching a limit. A write of 512 bytes will return 20. The > next write of a non-zero number of bytes would give a > failure return (except as noted below). > > If the request would cause the file size to exceed the soft > file size limit for the process and there is no room for > any bytes to be written, the request shall fail and the > implementation shall generate the SIGXFSZ signal for the > thread. > > And then in the ERRORS section: > ERRORS > These functions shall fail if: > ... > [EFBIG] An attempt was made to write a file that exceeds the > implementation-defined maximum file size and there was > no room for any bytes to be written. > > [EFBIG] An attempt was made to write a file that exceeds the > file size limit of the process, and there was no room > for any bytes to be written. A SIGXFSZ signal shall > also be sent to the thread. Ah, thanks. How to handle a short write, i.e. with no error return code, is exactly what I was looking for. This information is not in the Linux write(2) man page. BTW, is it possible that after a short write the next write() syscall for the remaining data will write some more data, possibly even the whole remaining data successfully? I think of something like a pipe or a socket where not the whole data can be sent immediately. Or will the write() syscall always block until all data could be written? I.e. will the next write syscall after a short write always fail and return -1? Steve
Back to comp.unix.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to check for error with write(2) Steve Keller <keller.steve@gmx.de> - 2021-12-16 18:58 +0100
Re: How to check for error with write(2) scott@slp53.sl.home (Scott Lurndal) - 2021-12-16 18:26 +0000
Re: How to check for error with write(2) Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2021-12-20 13:52 +0000
Re: How to check for error with write(2) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-12-16 18:49 +0000
Re: How to check for error with write(2) Rainer Weikusat <rweikusat@talktalk.net> - 2021-12-16 19:00 +0000
Re: How to check for error with write(2) Rainer Weikusat <rweikusat@talktalk.net> - 2021-12-16 19:06 +0000
Re: How to check for error with write(2) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-12-16 22:34 +0000
Re: How to check for error with write(2) Steve Keller <keller.steve@gmx.de> - 2021-12-17 04:38 +0100
Re: How to check for error with write(2) Rainer Weikusat <rweikusat@talktalk.net> - 2021-12-17 15:14 +0000
Re: How to check for error with write(2) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-12-18 10:25 +0000
Re: How to check for error with write(2) Philip Guenther <guenther@gmail.com> - 2021-12-16 15:04 -0800
Re: How to check for error with write(2) Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-12-16 20:10 -0700
Re: How to check for error with write(2) Steve Keller <keller.steve@gmx.de> - 2021-12-17 04:35 +0100
Re: How to check for error with write(2) Philip Guenther <guenther@gmail.com> - 2021-12-18 14:58 -0800
Re: How to check for error with write(2) scott@slp53.sl.home (Scott Lurndal) - 2021-12-19 16:07 +0000
csiph-web