diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2015-06-15 17:25:40 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-06-15 17:25:40 -0300 |
| commit | b6d5b37c1b1f358a268ff1c5ea48d314fbf9d726 (patch) | |
| tree | a0cc295bb8db8c62973fff3f6113c6e8c7c469dc /src | |
| parent | 5f8b6461a2deedd0eacd62fc20ea46f944307f7b (diff) | |
| parent | c315150aff4496eb50f4b9a4d9da9f7869710d36 (diff) | |
| download | luafilesystem-b6d5b37c1b1f358a268ff1c5ea48d314fbf9d726.tar.gz luafilesystem-b6d5b37c1b1f358a268ff1c5ea48d314fbf9d726.tar.bz2 luafilesystem-b6d5b37c1b1f358a268ff1c5ea48d314fbf9d726.zip | |
Merge pull request #52 from siffiejoe/checkfile
Fix detection of closed files on Lua 5.2/5.3.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lfs.c | 16 |
1 files changed, 12 insertions, 4 deletions
| @@ -197,15 +197,23 @@ static int get_dir (lua_State *L) { | |||
| 197 | ** Check if the given element on the stack is a file and returns it. | 197 | ** Check if the given element on the stack is a file and returns it. |
| 198 | */ | 198 | */ |
| 199 | static FILE *check_file (lua_State *L, int idx, const char *funcname) { | 199 | static FILE *check_file (lua_State *L, int idx, const char *funcname) { |
| 200 | #if LUA_VERSION_NUM == 501 | ||
| 200 | FILE **fh = (FILE **)luaL_checkudata (L, idx, "FILE*"); | 201 | FILE **fh = (FILE **)luaL_checkudata (L, idx, "FILE*"); |
| 201 | if (fh == NULL) { | 202 | if (*fh == NULL) { |
| 202 | luaL_error (L, "%s: not a file", funcname); | ||
| 203 | return 0; | ||
| 204 | } else if (*fh == NULL) { | ||
| 205 | luaL_error (L, "%s: closed file", funcname); | 203 | luaL_error (L, "%s: closed file", funcname); |
| 206 | return 0; | 204 | return 0; |
| 207 | } else | 205 | } else |
| 208 | return *fh; | 206 | return *fh; |
| 207 | #elif LUA_VERSION_NUM >= 502 && LUA_VERSION_NUM <= 503 | ||
| 208 | luaL_Stream *fh = (luaL_Stream *)luaL_checkudata (L, idx, "FILE*"); | ||
| 209 | if (fh->closef == 0 || fh->f == NULL) { | ||
| 210 | luaL_error (L, "%s: closed file", funcname); | ||
| 211 | return 0; | ||
| 212 | } else | ||
| 213 | return fh->f; | ||
| 214 | #else | ||
| 215 | #error unsupported Lua version | ||
| 216 | #endif | ||
| 209 | } | 217 | } |
| 210 | 218 | ||
| 211 | 219 | ||
