aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/liolib.c b/liolib.c
index 1978c510..8a543a81 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.79 2008/02/12 17:05:36 roberto Exp roberto $ 2** $Id: liolib.c,v 2.80 2009/02/20 13:50:27 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*/
@@ -165,7 +165,16 @@ static int io_tostring (lua_State *L) {
165static int io_open (lua_State *L) { 165static int io_open (lua_State *L) {
166 const char *filename = luaL_checkstring(L, 1); 166 const char *filename = luaL_checkstring(L, 1);
167 const char *mode = luaL_optstring(L, 2, "r"); 167 const char *mode = luaL_optstring(L, 2, "r");
168 FILE **pf = newfile(L); 168 FILE **pf;
169 int i = 0;
170 /* check whether 'mode' matches '[rwa]%+?b?' */
171 if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
172 (mode[i] != '+' || ++i) && /* skip if char is '+' */
173 (mode[i] != 'b' || ++i) && /* skip if char is 'b' */
174 (mode[i] == '\0')))
175 luaL_error(L, "invalid mode " LUA_QL("%s")
176 " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
177 pf = newfile(L);
169 *pf = fopen(filename, mode); 178 *pf = fopen(filename, mode);
170 return (*pf == NULL) ? pushresult(L, 0, filename) : 1; 179 return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
171} 180}