Skip to content

Commit d0f67c2

Browse files
committed
feature: resume read system call upon EINTR during file readall.
1 parent 39eff8e commit d0f67c2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib_io.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,14 @@ static void io_file_readall(lua_State *L, FILE *fp)
164164
MSize m, n;
165165
for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) {
166166
char *buf = lj_buf_tmp(L, m);
167-
n += (MSize)fread(buf+n, 1, m-n, fp);
168-
if (n != m) {
167+
for (;;) {
168+
n += (MSize)fread(buf+n, 1, m-n, fp);
169+
if (n == m) break;
170+
else if (ferror(fp) != 0) {
171+
if (errno != EINTR) return;
172+
clearerr(fp); /* EINTR, retry */
173+
continue;
174+
}
169175
setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
170176
lj_gc_check(L);
171177
return;

0 commit comments

Comments
 (0)