diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-08-02 15:00:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-08-02 15:00:01 -0300 |
commit | ae14adc272ae60457c519e55653bd2770655ac18 (patch) | |
tree | 3ca41c6e3830b8b0501b2832884bb103c4787510 | |
parent | ff98f17d273317059d06683dd5487e07a8abffc0 (diff) | |
download | lua-ae14adc272ae60457c519e55653bd2770655ac18.tar.gz lua-ae14adc272ae60457c519e55653bd2770655ac18.tar.bz2 lua-ae14adc272ae60457c519e55653bd2770655ac18.zip |
better error message when trying to open files
-rw-r--r-- | liolib.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.101 2011/06/27 19:42:31 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.102 2011/07/28 18:41:15 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 | */ |
@@ -157,10 +157,8 @@ static LStream *newfile (lua_State *L) { | |||
157 | static void opencheck (lua_State *L, const char *fname, const char *mode) { | 157 | static void opencheck (lua_State *L, const char *fname, const char *mode) { |
158 | LStream *p = newfile(L); | 158 | LStream *p = newfile(L); |
159 | p->f = fopen(fname, mode); | 159 | p->f = fopen(fname, mode); |
160 | if (p->f == NULL) { | 160 | if (p->f == NULL) |
161 | lua_pushfstring(L, "%s: %s", fname, strerror(errno)); | 161 | luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno)); |
162 | luaL_argerror(L, 1, lua_tostring(L, -1)); | ||
163 | } | ||
164 | } | 162 | } |
165 | 163 | ||
166 | 164 | ||
@@ -174,7 +172,7 @@ static int io_open (lua_State *L) { | |||
174 | (mode[i] != '+' || ++i) && /* skip if char is '+' */ | 172 | (mode[i] != '+' || ++i) && /* skip if char is '+' */ |
175 | (mode[i] != 'b' || ++i) && /* skip if char is 'b' */ | 173 | (mode[i] != 'b' || ++i) && /* skip if char is 'b' */ |
176 | (mode[i] == '\0'))) | 174 | (mode[i] == '\0'))) |
177 | return luaL_error(L, "invalid mode " LUA_QL("%s") | 175 | return luaL_error(L, "invalid mode " LUA_QS |
178 | " (should match " LUA_QL("[rwa]%%+?b?") ")", mode); | 176 | " (should match " LUA_QL("[rwa]%%+?b?") ")", mode); |
179 | p->f = fopen(filename, mode); | 177 | p->f = fopen(filename, mode); |
180 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; | 178 | return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; |