From 97ee3e9f9865ac8ad10e92ced073f905d61e75d7 Mon Sep 17 00:00:00 2001 From: Jacob Evan Shreve Date: Fri, 20 Sep 2019 01:01:52 -0400 Subject: [PATCH] Accept EOF as well as newline to complete line read Currently a line isn't read if any error is reached, including EAGAIN, which indicates you've reached the end of a file descriptor. This commit allows EAGAIN to terminate a line if anything else has been read from that fd. If nothing else has been read, it's either non-existent or empty, which makes sense to error instead. --- line.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/line.c b/line.c index 5cf738e5..646e1156 100644 --- a/line.c +++ b/line.c @@ -37,8 +37,13 @@ static ssize_t line_gets(int fd, char *buf, size_t size) return -ENOSPC; err = line_getc(fd, buf + len); - if (err) + if (err) { + if (err == -EAGAIN && len > 0) { + len++; + break; + } return err; + } if (buf[len++] == '\n') break;