aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2011-02-20 21:07:19 +0100
committerMike Pall <mike>2011-02-20 21:07:19 +0100
commit2bae11a49a4b69b9f0b51dfd33c703f261b789cd (patch)
tree7dbf14e500a4036e17310d7de993be7fcca8b73a /src
parentc823e26b8bb2980d4ee829713be96e52560b2935 (diff)
downloadluajit-2bae11a49a4b69b9f0b51dfd33c703f261b789cd.tar.gz
luajit-2bae11a49a4b69b9f0b51dfd33c703f261b789cd.tar.bz2
luajit-2bae11a49a4b69b9f0b51dfd33c703f261b789cd.zip
From Lua 5.2: fp:read("*L").
Diffstat (limited to 'src')
-rw-r--r--src/lib_io.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib_io.c b/src/lib_io.c
index 66b174f8..d3dac7a0 100644
--- a/src/lib_io.c
+++ b/src/lib_io.c
@@ -3,7 +3,7 @@
3** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h 3** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
4** 4**
5** Major portions taken verbatim or adapted from the Lua interpreter. 5** Major portions taken verbatim or adapted from the Lua interpreter.
6** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h 6** Copyright (C) 1994-2011 Lua.org, PUC-Rio. See Copyright Notice in lua.h
7*/ 7*/
8 8
9#include <errno.h> 9#include <errno.h>
@@ -153,7 +153,7 @@ static int io_file_testeof(lua_State *L, FILE *fp)
153 return (c != EOF); 153 return (c != EOF);
154} 154}
155 155
156static int io_file_readline(lua_State *L, FILE *fp) 156static int io_file_readline(lua_State *L, FILE *fp, size_t chop)
157{ 157{
158 luaL_Buffer b; 158 luaL_Buffer b;
159 luaL_buffinit(L, &b); 159 luaL_buffinit(L, &b);
@@ -168,7 +168,7 @@ static int io_file_readline(lua_State *L, FILE *fp)
168 if (len == 0 || p[len-1] != '\n') { /* Partial line? */ 168 if (len == 0 || p[len-1] != '\n') { /* Partial line? */
169 luaL_addsize(&b, len); 169 luaL_addsize(&b, len);
170 } else { 170 } else {
171 luaL_addsize(&b, len - 1); /* Don't include EOL. */ 171 luaL_addsize(&b, len - chop); /* Keep or remove EOL. */
172 luaL_pushresult(&b); 172 luaL_pushresult(&b);
173 return 1; /* Got at least an EOL. */ 173 return 1; /* Got at least an EOL. */
174 } 174 }
@@ -198,7 +198,7 @@ static int io_file_read(lua_State *L, FILE *fp, int start)
198 int ok, n, nargs = (int)(L->top - L->base) - start; 198 int ok, n, nargs = (int)(L->top - L->base) - start;
199 clearerr(fp); 199 clearerr(fp);
200 if (nargs == 0) { 200 if (nargs == 0) {
201 ok = io_file_readline(L, fp); 201 ok = io_file_readline(L, fp, 1);
202 n = start+1; /* Return 1 result. */ 202 n = start+1; /* Return 1 result. */
203 } else { 203 } else {
204 /* The results plus the buffers go on top of the args. */ 204 /* The results plus the buffers go on top of the args. */
@@ -211,8 +211,8 @@ static int io_file_read(lua_State *L, FILE *fp, int start)
211 lj_err_arg(L, n+1, LJ_ERR_INVOPT); 211 lj_err_arg(L, n+1, LJ_ERR_INVOPT);
212 if (p[1] == 'n') 212 if (p[1] == 'n')
213 ok = io_file_readnum(L, fp); 213 ok = io_file_readnum(L, fp);
214 else if (p[1] == 'l') 214 else if ((p[1] & ~0x20) == 'L')
215 ok = io_file_readline(L, fp); 215 ok = io_file_readline(L, fp, (p[1] == 'l'));
216 else if (p[1] == 'a') 216 else if (p[1] == 'a')
217 io_file_readchars(L, fp, ~((size_t)0)); 217 io_file_readchars(L, fp, ~((size_t)0));
218 else 218 else
@@ -459,7 +459,7 @@ LJLIB_CF(io_output)
459LJLIB_NOREG LJLIB_CF(io_lines_iter) 459LJLIB_NOREG LJLIB_CF(io_lines_iter)
460{ 460{
461 IOFileUD *iof = io_tofile(L); 461 IOFileUD *iof = io_tofile(L);
462 int ok = io_file_readline(L, iof->fp); 462 int ok = io_file_readline(L, iof->fp, 1);
463 if (ferror(iof->fp)) 463 if (ferror(iof->fp))
464 lj_err_callermsg(L, strerror(errno)); 464 lj_err_callermsg(L, strerror(errno));
465 if (!ok && (iof->type & IOFILE_FLAG_CLOSE)) 465 if (!ok && (iof->type & IOFILE_FLAG_CLOSE))