diff options
-rw-r--r-- | lauxlib.c | 12 |
1 files changed, 3 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.138 2005/07/11 14:01:28 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.139 2005/07/11 16:41:51 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -354,13 +354,10 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, | |||
354 | 354 | ||
355 | 355 | ||
356 | static int readable (const char *fname) { | 356 | static int readable (const char *fname) { |
357 | int err; | ||
358 | FILE *f = fopen(fname, "r"); /* try to open file */ | 357 | FILE *f = fopen(fname, "r"); /* try to open file */ |
359 | if (f == NULL) return 0; /* open failed */ | 358 | if (f == NULL) return 0; /* open failed */ |
360 | getc(f); /* try to read it */ | ||
361 | err = ferror(f); | ||
362 | fclose(f); | 359 | fclose(f); |
363 | return (err == 0); | 360 | return 1; |
364 | } | 361 | } |
365 | 362 | ||
366 | 363 | ||
@@ -369,11 +366,8 @@ LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name, | |||
369 | const char *p = path; | 366 | const char *p = path; |
370 | for (;;) { | 367 | for (;;) { |
371 | const char *fname; | 368 | const char *fname; |
372 | if ((p = pushnexttemplate(L, p)) == NULL) { | 369 | if ((p = pushnexttemplate(L, p)) == NULL) |
373 | lua_pushfstring(L, "no readable " LUA_QS " in path " LUA_QS "", | ||
374 | name, path); | ||
375 | return NULL; | 370 | return NULL; |
376 | } | ||
377 | fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); | 371 | fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); |
378 | lua_remove(L, -2); /* remove path template */ | 372 | lua_remove(L, -2); /* remove path template */ |
379 | if (readable(fname)) /* does file exist and is readable? */ | 373 | if (readable(fname)) /* does file exist and is readable? */ |