diff options
-rw-r--r-- | src/lfs.c | 36 | ||||
-rw-r--r-- | src/lfs.h | 8 |
2 files changed, 26 insertions, 18 deletions
@@ -375,8 +375,8 @@ static int lfs_f_setmode(lua_State *L) { | |||
375 | static int file_lock (lua_State *L) { | 375 | static int file_lock (lua_State *L) { |
376 | FILE *fh = check_file (L, 1, "lock"); | 376 | FILE *fh = check_file (L, 1, "lock"); |
377 | const char *mode = luaL_checkstring (L, 2); | 377 | const char *mode = luaL_checkstring (L, 2); |
378 | const long start = luaL_optlong (L, 3, 0); | 378 | const long start = (long) luaL_optinteger (L, 3, 0); |
379 | long len = luaL_optlong (L, 4, 0); | 379 | long len = (long) luaL_optinteger (L, 4, 0); |
380 | if (_file_lock (L, fh, mode, start, len, "lock")) { | 380 | if (_file_lock (L, fh, mode, start, len, "lock")) { |
381 | lua_pushboolean (L, 1); | 381 | lua_pushboolean (L, 1); |
382 | return 1; | 382 | return 1; |
@@ -396,8 +396,8 @@ static int file_lock (lua_State *L) { | |||
396 | */ | 396 | */ |
397 | static int file_unlock (lua_State *L) { | 397 | static int file_unlock (lua_State *L) { |
398 | FILE *fh = check_file (L, 1, "unlock"); | 398 | FILE *fh = check_file (L, 1, "unlock"); |
399 | const long start = luaL_optlong (L, 2, 0); | 399 | const long start = (long) luaL_optinteger (L, 2, 0); |
400 | long len = luaL_optlong (L, 3, 0); | 400 | long len = (long) luaL_optinteger (L, 3, 0); |
401 | if (_file_lock (L, fh, "u", start, len, "unlock")) { | 401 | if (_file_lock (L, fh, "u", start, len, "unlock")) { |
402 | lua_pushboolean (L, 1); | 402 | lua_pushboolean (L, 1); |
403 | return 1; | 403 | return 1; |
@@ -664,7 +664,7 @@ static int file_utime (lua_State *L) { | |||
664 | buf = NULL; | 664 | buf = NULL; |
665 | else { | 665 | else { |
666 | utb.actime = (time_t)luaL_optnumber (L, 2, 0); | 666 | utb.actime = (time_t)luaL_optnumber (L, 2, 0); |
667 | utb.modtime = (time_t)luaL_optnumber (L, 3, utb.actime); | 667 | utb.modtime = (time_t) luaL_optinteger (L, 3, utb.actime); |
668 | buf = &utb; | 668 | buf = &utb; |
669 | } | 669 | } |
670 | if (utime (file, buf)) { | 670 | if (utime (file, buf)) { |
@@ -683,52 +683,52 @@ static void push_st_mode (lua_State *L, STAT_STRUCT *info) { | |||
683 | } | 683 | } |
684 | /* device inode resides on */ | 684 | /* device inode resides on */ |
685 | static void push_st_dev (lua_State *L, STAT_STRUCT *info) { | 685 | static void push_st_dev (lua_State *L, STAT_STRUCT *info) { |
686 | lua_pushnumber (L, (lua_Number)info->st_dev); | 686 | lua_pushinteger (L, (lua_Integer) info->st_dev); |
687 | } | 687 | } |
688 | /* inode's number */ | 688 | /* inode's number */ |
689 | static void push_st_ino (lua_State *L, STAT_STRUCT *info) { | 689 | static void push_st_ino (lua_State *L, STAT_STRUCT *info) { |
690 | lua_pushnumber (L, (lua_Number)info->st_ino); | 690 | lua_pushinteger (L, (lua_Integer) info->st_ino); |
691 | } | 691 | } |
692 | /* number of hard links to the file */ | 692 | /* number of hard links to the file */ |
693 | static void push_st_nlink (lua_State *L, STAT_STRUCT *info) { | 693 | static void push_st_nlink (lua_State *L, STAT_STRUCT *info) { |
694 | lua_pushnumber (L, (lua_Number)info->st_nlink); | 694 | lua_pushinteger (L, (lua_Integer)info->st_nlink); |
695 | } | 695 | } |
696 | /* user-id of owner */ | 696 | /* user-id of owner */ |
697 | static void push_st_uid (lua_State *L, STAT_STRUCT *info) { | 697 | static void push_st_uid (lua_State *L, STAT_STRUCT *info) { |
698 | lua_pushnumber (L, (lua_Number)info->st_uid); | 698 | lua_pushinteger (L, (lua_Integer)info->st_uid); |
699 | } | 699 | } |
700 | /* group-id of owner */ | 700 | /* group-id of owner */ |
701 | static void push_st_gid (lua_State *L, STAT_STRUCT *info) { | 701 | static void push_st_gid (lua_State *L, STAT_STRUCT *info) { |
702 | lua_pushnumber (L, (lua_Number)info->st_gid); | 702 | lua_pushinteger (L, (lua_Integer)info->st_gid); |
703 | } | 703 | } |
704 | /* device type, for special file inode */ | 704 | /* device type, for special file inode */ |
705 | static void push_st_rdev (lua_State *L, STAT_STRUCT *info) { | 705 | static void push_st_rdev (lua_State *L, STAT_STRUCT *info) { |
706 | lua_pushnumber (L, (lua_Number)info->st_rdev); | 706 | lua_pushinteger (L, (lua_Integer) info->st_rdev); |
707 | } | 707 | } |
708 | /* time of last access */ | 708 | /* time of last access */ |
709 | static void push_st_atime (lua_State *L, STAT_STRUCT *info) { | 709 | static void push_st_atime (lua_State *L, STAT_STRUCT *info) { |
710 | lua_pushnumber (L, info->st_atime); | 710 | lua_pushinteger (L, (lua_Integer) info->st_atime); |
711 | } | 711 | } |
712 | /* time of last data modification */ | 712 | /* time of last data modification */ |
713 | static void push_st_mtime (lua_State *L, STAT_STRUCT *info) { | 713 | static void push_st_mtime (lua_State *L, STAT_STRUCT *info) { |
714 | lua_pushnumber (L, info->st_mtime); | 714 | lua_pushinteger (L, (lua_Integer) info->st_mtime); |
715 | } | 715 | } |
716 | /* time of last file status change */ | 716 | /* time of last file status change */ |
717 | static void push_st_ctime (lua_State *L, STAT_STRUCT *info) { | 717 | static void push_st_ctime (lua_State *L, STAT_STRUCT *info) { |
718 | lua_pushnumber (L, info->st_ctime); | 718 | lua_pushinteger (L, (lua_Integer) info->st_ctime); |
719 | } | 719 | } |
720 | /* file size, in bytes */ | 720 | /* file size, in bytes */ |
721 | static void push_st_size (lua_State *L, STAT_STRUCT *info) { | 721 | static void push_st_size (lua_State *L, STAT_STRUCT *info) { |
722 | lua_pushnumber (L, (lua_Number)info->st_size); | 722 | lua_pushinteger (L, (lua_Integer)info->st_size); |
723 | } | 723 | } |
724 | #ifndef _WIN32 | 724 | #ifndef _WIN32 |
725 | /* blocks allocated for file */ | 725 | /* blocks allocated for file */ |
726 | static void push_st_blocks (lua_State *L, STAT_STRUCT *info) { | 726 | static void push_st_blocks (lua_State *L, STAT_STRUCT *info) { |
727 | lua_pushnumber (L, (lua_Number)info->st_blocks); | 727 | lua_pushinteger (L, (lua_Integer)info->st_blocks); |
728 | } | 728 | } |
729 | /* optimal file system I/O blocksize */ | 729 | /* optimal file system I/O blocksize */ |
730 | static void push_st_blksize (lua_State *L, STAT_STRUCT *info) { | 730 | static void push_st_blksize (lua_State *L, STAT_STRUCT *info) { |
731 | lua_pushnumber (L, (lua_Number)info->st_blksize); | 731 | lua_pushinteger (L, (lua_Integer)info->st_blksize); |
732 | } | 732 | } |
733 | #endif | 733 | #endif |
734 | 734 | ||
@@ -738,7 +738,7 @@ static void push_st_blksize (lua_State *L, STAT_STRUCT *info) { | |||
738 | 738 | ||
739 | #ifdef _WIN32 | 739 | #ifdef _WIN32 |
740 | static const char *perm2string (unsigned short mode) { | 740 | static const char *perm2string (unsigned short mode) { |
741 | static char perms[10] = "---------\0"; | 741 | static char perms[10] = "---------"; //removed explicit \0 (it would be the second, since "" adds one already and perms[10] is only 10 big. |
742 | int i; | 742 | int i; |
743 | for (i=0;i<9;i++) perms[i]='-'; | 743 | for (i=0;i<9;i++) perms[i]='-'; |
744 | if (mode & _S_IREAD) | 744 | if (mode & _S_IREAD) |
@@ -11,6 +11,14 @@ | |||
11 | #define chdir_error "Function 'chdir' not provided by system" | 11 | #define chdir_error "Function 'chdir' not provided by system" |
12 | #else | 12 | #else |
13 | #define chdir_error strerror(errno) | 13 | #define chdir_error strerror(errno) |
14 | |||
15 | #endif | ||
16 | |||
17 | #ifdef _WIN32 | ||
18 | #define chdir(p) (_chdir(p)) | ||
19 | #define getcwd(d, s) (_getcwd(d, s)) | ||
20 | #define rmdir(p) (_rmdir(p)) | ||
21 | #define fileno(f) (_fileno(f)) | ||
14 | #endif | 22 | #endif |
15 | 23 | ||
16 | 24 | ||