diff options
Diffstat (limited to 'src/lib_io.c')
-rw-r--r-- | src/lib_io.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/lib_io.c b/src/lib_io.c index e0c6908f..5369d450 100644 --- a/src/lib_io.c +++ b/src/lib_io.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "lj_obj.h" | 19 | #include "lj_obj.h" |
20 | #include "lj_gc.h" | 20 | #include "lj_gc.h" |
21 | #include "lj_err.h" | 21 | #include "lj_err.h" |
22 | #include "lj_buf.h" | ||
22 | #include "lj_str.h" | 23 | #include "lj_str.h" |
23 | #include "lj_state.h" | 24 | #include "lj_state.h" |
24 | #include "lj_ff.h" | 25 | #include "lj_ff.h" |
@@ -145,7 +146,7 @@ static int io_file_readline(lua_State *L, FILE *fp, MSize chop) | |||
145 | MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0; | 146 | MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0; |
146 | char *buf; | 147 | char *buf; |
147 | for (;;) { | 148 | for (;;) { |
148 | buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); | 149 | buf = lj_buf_tmp(L, m); |
149 | if (fgets(buf+n, m-n, fp) == NULL) break; | 150 | if (fgets(buf+n, m-n, fp) == NULL) break; |
150 | n += (MSize)strlen(buf+n); | 151 | n += (MSize)strlen(buf+n); |
151 | ok |= n; | 152 | ok |= n; |
@@ -161,7 +162,7 @@ static void io_file_readall(lua_State *L, FILE *fp) | |||
161 | { | 162 | { |
162 | MSize m, n; | 163 | MSize m, n; |
163 | for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) { | 164 | for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) { |
164 | char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); | 165 | char *buf = lj_buf_tmp(L, m); |
165 | n += (MSize)fread(buf+n, 1, m-n, fp); | 166 | n += (MSize)fread(buf+n, 1, m-n, fp); |
166 | if (n != m) { | 167 | if (n != m) { |
167 | setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); | 168 | setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); |
@@ -174,7 +175,7 @@ static void io_file_readall(lua_State *L, FILE *fp) | |||
174 | static int io_file_readlen(lua_State *L, FILE *fp, MSize m) | 175 | static int io_file_readlen(lua_State *L, FILE *fp, MSize m) |
175 | { | 176 | { |
176 | if (m) { | 177 | if (m) { |
177 | char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); | 178 | char *buf = lj_buf_tmp(L, m); |
178 | MSize n = (MSize)fread(buf, 1, m, fp); | 179 | MSize n = (MSize)fread(buf, 1, m, fp); |
179 | setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); | 180 | setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); |
180 | lj_gc_check(L); | 181 | lj_gc_check(L); |