aboutsummaryrefslogtreecommitdiff
path: root/src/lib_io.c
diff options
context:
space:
mode:
authorMike Pall <mike>2013-02-27 17:11:31 +0100
committerMike Pall <mike>2013-02-27 17:29:35 +0100
commit28cfcf77445e144335961a020e3e08d84cf0091f (patch)
tree1a769d0ee0fab26a79073a118ba4f9e1557b081a /src/lib_io.c
parentd44337a566bb3de06a6ac4ecf2d2a77767b86029 (diff)
downloadluajit-28cfcf77445e144335961a020e3e08d84cf0091f.tar.gz
luajit-28cfcf77445e144335961a020e3e08d84cf0091f.tar.bz2
luajit-28cfcf77445e144335961a020e3e08d84cf0091f.zip
String buffer refactoring, part 1.
Move string buffer handling to lj_buf.*. Use common buffer resizing function.
Diffstat (limited to 'src/lib_io.c')
-rw-r--r--src/lib_io.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/lib_io.c b/src/lib_io.c
index 8858683f..e9472ba5 100644
--- a/src/lib_io.c
+++ b/src/lib_io.c
@@ -18,6 +18,7 @@
18 18
19#include "lj_obj.h" 19#include "lj_obj.h"
20#include "lj_err.h" 20#include "lj_err.h"
21#include "lj_buf.h"
21#include "lj_str.h" 22#include "lj_str.h"
22#include "lj_state.h" 23#include "lj_state.h"
23#include "lj_ff.h" 24#include "lj_ff.h"
@@ -144,7 +145,7 @@ static int io_file_readline(lua_State *L, FILE *fp, MSize chop)
144 MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0; 145 MSize m = LUAL_BUFFERSIZE, n = 0, ok = 0;
145 char *buf; 146 char *buf;
146 for (;;) { 147 for (;;) {
147 buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); 148 buf = lj_buf_tmp(L, m);
148 if (fgets(buf+n, m-n, fp) == NULL) break; 149 if (fgets(buf+n, m-n, fp) == NULL) break;
149 n += (MSize)strlen(buf+n); 150 n += (MSize)strlen(buf+n);
150 ok |= n; 151 ok |= n;
@@ -159,7 +160,7 @@ static void io_file_readall(lua_State *L, FILE *fp)
159{ 160{
160 MSize m, n; 161 MSize m, n;
161 for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) { 162 for (m = LUAL_BUFFERSIZE, n = 0; ; m += m) {
162 char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); 163 char *buf = lj_buf_tmp(L, m);
163 n += (MSize)fread(buf+n, 1, m-n, fp); 164 n += (MSize)fread(buf+n, 1, m-n, fp);
164 if (n != m) { 165 if (n != m) {
165 setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); 166 setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
@@ -171,7 +172,7 @@ static void io_file_readall(lua_State *L, FILE *fp)
171static int io_file_readlen(lua_State *L, FILE *fp, MSize m) 172static int io_file_readlen(lua_State *L, FILE *fp, MSize m)
172{ 173{
173 if (m) { 174 if (m) {
174 char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m); 175 char *buf = lj_buf_tmp(L, m);
175 MSize n = (MSize)fread(buf, 1, m, fp); 176 MSize n = (MSize)fread(buf, 1, m, fp);
176 setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n)); 177 setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
177 return (n > 0 || m == 0); 178 return (n > 0 || m == 0);