diff options
| author | Fabio Mascarenhas <mascarenhas@acm.org> | 2012-04-08 20:25:40 -0300 |
|---|---|---|
| committer | Fabio Mascarenhas <mascarenhas@acm.org> | 2012-04-08 20:25:40 -0300 |
| commit | 84f1af5eef6af267109eaa84c18c5a70edaf65ea (patch) | |
| tree | adb555999c0713cf1ba0f70e530658eec41e6b66 /src | |
| parent | 149e0fb8ec6295325e1e448bbe79b7e9bf2285aa (diff) | |
| download | luafilesystem-84f1af5eef6af267109eaa84c18c5a70edaf65ea.tar.gz luafilesystem-84f1af5eef6af267109eaa84c18c5a70edaf65ea.tar.bz2 luafilesystem-84f1af5eef6af267109eaa84c18c5a70edaf65ea.zip | |
applied debian patches from enrico tassi
Diffstat (limited to 'src')
| -rw-r--r-- | src/lfs.c | 60 |
1 files changed, 57 insertions, 3 deletions
| @@ -61,6 +61,16 @@ | |||
| 61 | #include "lualib.h" | 61 | #include "lualib.h" |
| 62 | #include "lfs.h" | 62 | #include "lfs.h" |
| 63 | 63 | ||
| 64 | /* | ||
| 65 | * ** compatibility with Lua 5.2 | ||
| 66 | * */ | ||
| 67 | #if (LUA_VERSION_NUM == 502) | ||
| 68 | #undef luaL_register | ||
| 69 | #define luaL_register(L,n,f) \ | ||
| 70 | { if ((n) == NULL) luaL_setfuncs(L,f,0); else luaL_newlib(L,f); } | ||
| 71 | |||
| 72 | #endif | ||
| 73 | |||
| 64 | /* Define 'strerror' for systems that do not implement it */ | 74 | /* Define 'strerror' for systems that do not implement it */ |
| 65 | #ifdef NO_STRERROR | 75 | #ifdef NO_STRERROR |
| 66 | #define strerror(_) "System unable to describe the error" | 76 | #define strerror(_) "System unable to describe the error" |
| @@ -150,16 +160,19 @@ static int change_dir (lua_State *L) { | |||
| 150 | ** If unable to get the current directory, it returns nil | 160 | ** If unable to get the current directory, it returns nil |
| 151 | ** and a string describing the error | 161 | ** and a string describing the error |
| 152 | */ | 162 | */ |
| 163 | #ifndef PATH_MAX | ||
| 164 | #define PATH_MAX 4096 | ||
| 165 | #endif | ||
| 166 | |||
| 153 | static int get_dir (lua_State *L) { | 167 | static int get_dir (lua_State *L) { |
| 154 | char *path; | 168 | char path[PATH_MAX]; |
| 155 | if ((path = getcwd(NULL, 0)) == NULL) { | 169 | if (getcwd((char *)path, PATH_MAX) == NULL) { |
| 156 | lua_pushnil(L); | 170 | lua_pushnil(L); |
| 157 | lua_pushstring(L, getcwd_error); | 171 | lua_pushstring(L, getcwd_error); |
| 158 | return 2; | 172 | return 2; |
| 159 | } | 173 | } |
| 160 | else { | 174 | else { |
| 161 | lua_pushstring(L, path); | 175 | lua_pushstring(L, path); |
| 162 | free(path); | ||
| 163 | return 1; | 176 | return 1; |
| 164 | } | 177 | } |
| 165 | } | 178 | } |
| @@ -703,6 +716,46 @@ static void push_invalid (lua_State *L, STAT_STRUCT *info) { | |||
| 703 | #endif | 716 | #endif |
| 704 | } | 717 | } |
| 705 | 718 | ||
| 719 | /* | ||
| 720 | ** Convert the inode protection mode to a permission list. | ||
| 721 | */ | ||
| 722 | |||
| 723 | #ifdef _WIN32 | ||
| 724 | static const char *perm2string (unsigned short mode) { | ||
| 725 | static char perms[10] = "---------\0"; | ||
| 726 | int i; | ||
| 727 | for (i=0;i<9;i++) perms[i]='-'; | ||
| 728 | if (mode & _S_IREAD) | ||
| 729 | { perms[0] = 'r'; perms[3] = 'r'; perms[6] = 'r'; } | ||
| 730 | if (mode & _S_IWRITE) | ||
| 731 | { perms[1] = 'w'; perms[4] = 'w'; perms[7] = 'w'; } | ||
| 732 | if (mode & _S_IEXEC) | ||
| 733 | { perms[2] = 'x'; perms[5] = 'x'; perms[8] = 'x'; } | ||
| 734 | return perms; | ||
| 735 | } | ||
| 736 | #else | ||
| 737 | static const char *perm2string (mode_t mode) { | ||
| 738 | static char perms[10] = "---------\0"; | ||
| 739 | int i; | ||
| 740 | for (i=0;i<9;i++) perms[i]='-'; | ||
| 741 | if (mode & S_IRUSR) perms[0] = 'r'; | ||
| 742 | if (mode & S_IWUSR) perms[1] = 'w'; | ||
| 743 | if (mode & S_IXUSR) perms[2] = 'x'; | ||
| 744 | if (mode & S_IRGRP) perms[3] = 'r'; | ||
| 745 | if (mode & S_IWGRP) perms[4] = 'w'; | ||
| 746 | if (mode & S_IXGRP) perms[5] = 'x'; | ||
| 747 | if (mode & S_IROTH) perms[6] = 'r'; | ||
| 748 | if (mode & S_IWOTH) perms[7] = 'w'; | ||
| 749 | if (mode & S_IXOTH) perms[8] = 'x'; | ||
| 750 | return perms; | ||
| 751 | } | ||
| 752 | #endif | ||
| 753 | |||
| 754 | /* permssions string */ | ||
| 755 | static void push_st_perm (lua_State *L, STAT_STRUCT *info) { | ||
| 756 | lua_pushstring (L, perm2string (info->st_mode)); | ||
| 757 | } | ||
| 758 | |||
| 706 | typedef void (*_push_function) (lua_State *L, STAT_STRUCT *info); | 759 | typedef void (*_push_function) (lua_State *L, STAT_STRUCT *info); |
| 707 | 760 | ||
| 708 | struct _stat_members { | 761 | struct _stat_members { |
| @@ -722,6 +775,7 @@ struct _stat_members members[] = { | |||
| 722 | { "modification", push_st_mtime }, | 775 | { "modification", push_st_mtime }, |
| 723 | { "change", push_st_ctime }, | 776 | { "change", push_st_ctime }, |
| 724 | { "size", push_st_size }, | 777 | { "size", push_st_size }, |
| 778 | { "permissions", push_st_perm }, | ||
| 725 | #ifndef _WIN32 | 779 | #ifndef _WIN32 |
| 726 | { "blocks", push_st_blocks }, | 780 | { "blocks", push_st_blocks }, |
| 727 | { "blksize", push_st_blksize }, | 781 | { "blksize", push_st_blksize }, |
