aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lj_load.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lj_load.c b/src/lj_load.c
index d92bd1b4..1524aeb6 100644
--- a/src/lj_load.c
+++ b/src/lj_load.c
@@ -87,6 +87,7 @@ LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,
87 FileReaderCtx ctx; 87 FileReaderCtx ctx;
88 int status; 88 int status;
89 const char *chunkname; 89 const char *chunkname;
90 int err = 0;
90 if (filename) { 91 if (filename) {
91 chunkname = lua_pushfstring(L, "@%s", filename); 92 chunkname = lua_pushfstring(L, "@%s", filename);
92 ctx.fp = fopen(filename, "rb"); 93 ctx.fp = fopen(filename, "rb");
@@ -100,17 +101,16 @@ LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename,
100 chunkname = "=stdin"; 101 chunkname = "=stdin";
101 } 102 }
102 status = lua_loadx(L, reader_file, &ctx, chunkname, mode); 103 status = lua_loadx(L, reader_file, &ctx, chunkname, mode);
103 if (ferror(ctx.fp)) { 104 if (ferror(ctx.fp)) err = errno;
104 L->top -= filename ? 2 : 1;
105 lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(errno));
106 if (filename)
107 fclose(ctx.fp);
108 return LUA_ERRFILE;
109 }
110 if (filename) { 105 if (filename) {
106 fclose(ctx.fp);
111 L->top--; 107 L->top--;
112 copyTV(L, L->top-1, L->top); 108 copyTV(L, L->top-1, L->top);
113 fclose(ctx.fp); 109 }
110 if (err) {
111 L->top--;
112 lua_pushfstring(L, "cannot read %s: %s", chunkname+1, strerror(err));
113 return LUA_ERRFILE;
114 } 114 }
115 return status; 115 return status;
116} 116}