Skip to content

Commit 465e325

Browse files
committed
fix getline() issues in non-blocking mode on non-OpenBSD
1 parent d3c3cca commit 465e325

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tlc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ proceed_input(FILE *f, long long *lineno) {
221221
char *line = NULL, *out_str;
222222

223223
while ((linelen = getline(&line, &linesize, f)) != (size_t)-1) {
224+
// fix non-blocking problems on non-OpenBSD (e.g., Linux)
225+
if (ferror(f) && errno == EAGAIN) {
226+
while (linelen--)
227+
if (ungetc(line[linelen], f) == EOF)
228+
err(1, "ungetc");
229+
break;
230+
}
231+
224232
(*lineno)++;
225233

226234
if (passthrough)
@@ -240,6 +248,11 @@ proceed_input(FILE *f, long long *lineno) {
240248
free(out_str);
241249
}
242250
}
251+
252+
// fix non-blocking problems on non-OpenBSD (e.g., Linux)
253+
if (ferror(f) && errno == EAGAIN)
254+
clearerr(f);
255+
243256
free(line);
244257
}
245258

0 commit comments

Comments
 (0)