aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lfs.c15
-rw-r--r--src/lfs.def2
2 files changed, 8 insertions, 9 deletions
diff --git a/src/lfs.c b/src/lfs.c
index 522da46..85f01e3 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -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
79typedef struct dir_data { 78typedef 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 @@
1LIBRARY lfs.dll 1LIBRARY lfs.dll
2DESCRIPTION "LuaFileSystem" 2DESCRIPTION "LuaFileSystem"
3VERSION 1.4.2 3VERSION 1.5.0
4EXPORTS 4EXPORTS
5luaopen_lfs 5luaopen_lfs