From 9b2653be1ef81437fe73fe9a8670ab3fcddeda78 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Jan 2017 09:31:12 +0100 Subject: Forgot to commit a file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/stream.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/stream.c') diff --git a/src/stream.c b/src/stream.c index 04dd516..4b2cc23 100644 --- a/src/stream.c +++ b/src/stream.c @@ -17,13 +17,17 @@ eninit_stream(int status, struct stream *stream) size_t n; char *p = NULL, *w, *h, *f, *end; - for (stream->ptr = 0; stream->fd >= 0 && !p;) { - r = read(stream->fd, stream->buf + stream->ptr, sizeof(stream->buf) - stream->ptr); - if (r < 0) - enprintf(status, "read %s:", stream->file); - if (r == 0) - goto bad_format; - stream->ptr += (size_t)r; + if (stream->fd >= 0) { + for (stream->ptr = 0; !p;) { + r = read(stream->fd, stream->buf + stream->ptr, sizeof(stream->buf) - stream->ptr); + if (r < 0) + enprintf(status, "read %s:", stream->file); + if (r == 0) + goto bad_format; + stream->ptr += (size_t)r; + p = memchr(stream->buf, '\n', stream->ptr); + } + } else { p = memchr(stream->buf, '\n', stream->ptr); } @@ -281,7 +285,7 @@ nprocess_multiple_streams(int status, struct stream *streams, size_t n_streams, while (n_streams) { n = SIZE_MAX; for (i = 0; i < n_streams; i++) { - if (streams[i].ptr < sizeof(streams->buf) && !eread_stream(streams + i, SIZE_MAX)) { + if (streams[i].ptr < sizeof(streams->buf) && !enread_stream(status, streams + i, SIZE_MAX)) { close(streams[i].fd); streams[i].fd = -1; } -- cgit v1.2.3-70-g09d2