diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-08-16 12:38:34 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-08-16 12:38:34 -0400 |
commit | 7848df8f2a5bc3b95e2b05b8876708bb93230de7 (patch) | |
tree | 21909f412cab89e5c0145861e1d7e387acaca6b5 | |
parent | 8fd71ec34243fcee92c84548dbb3ef4f4316ccb3 (diff) |
check return of write() properly
set err on stream if write error occurs
reset bpos to 0
-rw-r--r-- | src/stdio/putc_unlocked.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/stdio/putc_unlocked.c b/src/stdio/putc_unlocked.c index cf8c9cb4..4a3937e8 100644 --- a/src/stdio/putc_unlocked.c +++ b/src/stdio/putc_unlocked.c @@ -22,10 +22,12 @@ int putc_unlocked(int c, FILE *stream) if (stream->bpos == stream->bsize || (stream->bmode == _IOLBF && ch == '\n') || (stream->bmode == _IONBF)) { - if (write(stream->fd, stream->buf, stream->bpos) != 1) { + if (write(stream->fd, stream->buf, stream->bpos) < 0) { /* errno handled by write() */ + stream->err = 1; return EOF; } + stream->bpos = 0; } return ch; |