aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--liolib.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/liolib.c b/liolib.c
index 76323112..505ad752 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.54 2004/07/09 15:47:48 roberto Exp roberto $ 2** $Id: liolib.c,v 2.55 2004/07/09 16:01:38 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -44,6 +44,12 @@ static int pushresult (lua_State *L, int i, const char *filename) {
44} 44}
45 45
46 46
47static void fileerror (lua_State *L, int arg, const char *filename) {
48 lua_pushfstring(L, "%s: %s", filename, strerror(errno));
49 luaL_argerror(L, arg, lua_tostring(L, -1));
50}
51
52
47static FILE **topfile (lua_State *L) { 53static FILE **topfile (lua_State *L) {
48 FILE **f = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE); 54 FILE **f = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE);
49 if (f == NULL) luaL_argerror(L, 1, "bad file"); 55 if (f == NULL) luaL_argerror(L, 1, "bad file");
@@ -156,10 +162,8 @@ static int g_iofile (lua_State *L, int f, const char *mode) {
156 if (filename) { 162 if (filename) {
157 FILE **pf = newfile(L); 163 FILE **pf = newfile(L);
158 *pf = fopen(filename, mode); 164 *pf = fopen(filename, mode);
159 if (*pf == NULL) { 165 if (*pf == NULL)
160 lua_pushfstring(L, "%s: %s", filename, strerror(errno)); 166 fileerror(L, 1, filename);
161 luaL_argerror(L, 1, lua_tostring(L, -1));
162 }
163 } 167 }
164 else { 168 else {
165 tofile(L); /* check that it's a valid file handle */ 169 tofile(L); /* check that it's a valid file handle */
@@ -212,7 +216,8 @@ static int io_lines (lua_State *L) {
212 const char *filename = luaL_checkstring(L, 1); 216 const char *filename = luaL_checkstring(L, 1);
213 FILE **pf = newfile(L); 217 FILE **pf = newfile(L);
214 *pf = fopen(filename, "r"); 218 *pf = fopen(filename, "r");
215 luaL_argcheck(L, *pf, 1, strerror(errno)); 219 if (*pf == NULL)
220 fileerror(L, 1, filename);
216 aux_lines(L, lua_gettop(L), 1); 221 aux_lines(L, lua_gettop(L), 1);
217 return 1; 222 return 1;
218 } 223 }