diff options
| author | Fabio Mascarenhas <mascarenhas@lambda-2.local> | 2010-06-09 14:14:25 -0300 |
|---|---|---|
| committer | Fabio Mascarenhas <mascarenhas@lambda-2.local> | 2010-06-09 14:14:25 -0300 |
| commit | ae5a05deec8a3737bd6972213b5495108b6566cc (patch) | |
| tree | fa50e8f4e819ad5677b9cbf65f13a48a9013c71a | |
| parent | fd028d32578fa0b7d5dfc89345f851b02a5af196 (diff) | |
| download | luafilesystem-ae5a05deec8a3737bd6972213b5495108b6566cc.tar.gz luafilesystem-ae5a05deec8a3737bd6972213b5495108b6566cc.tar.bz2 luafilesystem-ae5a05deec8a3737bd6972213b5495108b6566cc.zip | |
fixed dir length bug in windows directory iterator
| -rw-r--r-- | src/lfs.c | 15 | ||||
| -rw-r--r-- | src/lfs.def | 2 |
2 files changed, 8 insertions, 9 deletions
| @@ -75,12 +75,11 @@ | |||
| 75 | #endif | 75 | #endif |
| 76 | 76 | ||
| 77 | #define DIR_METATABLE "directory metatable" | 77 | #define DIR_METATABLE "directory metatable" |
| 78 | #define MAX_DIR_LENGTH 1023 | ||
| 79 | typedef struct dir_data { | 78 | typedef struct dir_data { |
| 80 | int closed; | 79 | int closed; |
| 81 | #ifdef _WIN32 | 80 | #ifdef _WIN32 |
| 82 | long hFile; | 81 | long hFile; |
| 83 | char pattern[MAX_DIR_LENGTH+1]; | 82 | char pattern[MAX_PATH+1]; |
| 84 | #else | 83 | #else |
| 85 | DIR *dir; | 84 | DIR *dir; |
| 86 | #endif | 85 | #endif |
| @@ -410,12 +409,13 @@ static int dir_iter (lua_State *L) { | |||
| 410 | struct dirent *entry; | 409 | struct dirent *entry; |
| 411 | #endif | 410 | #endif |
| 412 | dir_data *d = (dir_data *)luaL_checkudata (L, 1, DIR_METATABLE); | 411 | dir_data *d = (dir_data *)luaL_checkudata (L, 1, DIR_METATABLE); |
| 413 | luaL_argcheck (L, !d->closed, 1, "closed directory"); | 412 | luaL_argcheck (L, d->closed == 0, 1, "closed directory"); |
| 414 | #ifdef _WIN32 | 413 | #ifdef _WIN32 |
| 415 | if (d->hFile == 0L) { /* first entry */ | 414 | if (d->hFile == 0L) { /* first entry */ |
| 416 | if ((d->hFile = _findfirst (d->pattern, &c_file)) == -1L) { | 415 | if ((d->hFile = _findfirst (d->pattern, &c_file)) == -1L) { |
| 417 | lua_pushnil (L); | 416 | lua_pushnil (L); |
| 418 | lua_pushstring (L, strerror (errno)); | 417 | lua_pushstring (L, strerror (errno)); |
| 418 | d->closed = 1; | ||
| 419 | return 2; | 419 | return 2; |
| 420 | } else { | 420 | } else { |
| 421 | lua_pushstring (L, c_file.name); | 421 | lua_pushstring (L, c_file.name); |
| @@ -454,14 +454,13 @@ static int dir_close (lua_State *L) { | |||
| 454 | #ifdef _WIN32 | 454 | #ifdef _WIN32 |
| 455 | if (!d->closed && d->hFile) { | 455 | if (!d->closed && d->hFile) { |
| 456 | _findclose (d->hFile); | 456 | _findclose (d->hFile); |
| 457 | d->closed = 1; | ||
| 458 | } | 457 | } |
| 459 | #else | 458 | #else |
| 460 | if (!d->closed && d->dir) { | 459 | if (!d->closed && d->dir) { |
| 461 | closedir (d->dir); | 460 | closedir (d->dir); |
| 462 | d->closed = 1; | ||
| 463 | } | 461 | } |
| 464 | #endif | 462 | #endif |
| 463 | d->closed = 1; | ||
| 465 | return 0; | 464 | return 0; |
| 466 | } | 465 | } |
| 467 | 466 | ||
| @@ -479,10 +478,10 @@ static int dir_iter_factory (lua_State *L) { | |||
| 479 | d->hFile = 0L; | 478 | d->hFile = 0L; |
| 480 | luaL_getmetatable (L, DIR_METATABLE); | 479 | luaL_getmetatable (L, DIR_METATABLE); |
| 481 | lua_setmetatable (L, -2); | 480 | lua_setmetatable (L, -2); |
| 482 | if (strlen(path) > MAX_DIR_LENGTH) | 481 | if (strlen(path) > MAX_PATH-2) |
| 483 | luaL_error (L, "path too long: %s", path); | 482 | luaL_error (L, "path too long: %s", path); |
| 484 | else | 483 | else |
| 485 | sprintf (d->pattern, "%s/*", path); | 484 | sprintf (d->pattern, "%s/*", path); |
| 486 | #else | 485 | #else |
| 487 | luaL_getmetatable (L, DIR_METATABLE); | 486 | luaL_getmetatable (L, DIR_METATABLE); |
| 488 | lua_setmetatable (L, -2); | 487 | lua_setmetatable (L, -2); |
diff --git a/src/lfs.def b/src/lfs.def index f79cd29..7aa7a35 100644 --- a/src/lfs.def +++ b/src/lfs.def | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | LIBRARY lfs.dll | 1 | LIBRARY lfs.dll |
| 2 | DESCRIPTION "LuaFileSystem" | 2 | DESCRIPTION "LuaFileSystem" |
| 3 | VERSION 1.4.2 | 3 | VERSION 1.5.0 |
| 4 | EXPORTS | 4 | EXPORTS |
| 5 | luaopen_lfs | 5 | luaopen_lfs |
