applied debian patches from enrico tassi

This commit is contained in:
Fabio Mascarenhas
2012-04-08 20:25:40 -03:00
parent 149e0fb8ec
commit 84f1af5eef
2 changed files with 58 additions and 4 deletions

View File

@@ -61,6 +61,16 @@
#include "lualib.h" #include "lualib.h"
#include "lfs.h" #include "lfs.h"
/*
* ** compatibility with Lua 5.2
* */
#if (LUA_VERSION_NUM == 502)
#undef luaL_register
#define luaL_register(L,n,f) \
{ if ((n) == NULL) luaL_setfuncs(L,f,0); else luaL_newlib(L,f); }
#endif
/* Define 'strerror' for systems that do not implement it */ /* Define 'strerror' for systems that do not implement it */
#ifdef NO_STRERROR #ifdef NO_STRERROR
#define strerror(_) "System unable to describe the error" #define strerror(_) "System unable to describe the error"
@@ -150,16 +160,19 @@ static int change_dir (lua_State *L) {
** If unable to get the current directory, it returns nil ** If unable to get the current directory, it returns nil
** and a string describing the error ** and a string describing the error
*/ */
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
static int get_dir (lua_State *L) { static int get_dir (lua_State *L) {
char *path; char path[PATH_MAX];
if ((path = getcwd(NULL, 0)) == NULL) { if (getcwd((char *)path, PATH_MAX) == NULL) {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, getcwd_error); lua_pushstring(L, getcwd_error);
return 2; return 2;
} }
else { else {
lua_pushstring(L, path); lua_pushstring(L, path);
free(path);
return 1; return 1;
} }
} }
@@ -703,6 +716,46 @@ static void push_invalid (lua_State *L, STAT_STRUCT *info) {
#endif #endif
} }
/*
** Convert the inode protection mode to a permission list.
*/
#ifdef _WIN32
static const char *perm2string (unsigned short mode) {
static char perms[10] = "---------\0";
int i;
for (i=0;i<9;i++) perms[i]='-';
if (mode & _S_IREAD)
{ perms[0] = 'r'; perms[3] = 'r'; perms[6] = 'r'; }
if (mode & _S_IWRITE)
{ perms[1] = 'w'; perms[4] = 'w'; perms[7] = 'w'; }
if (mode & _S_IEXEC)
{ perms[2] = 'x'; perms[5] = 'x'; perms[8] = 'x'; }
return perms;
}
#else
static const char *perm2string (mode_t mode) {
static char perms[10] = "---------\0";
int i;
for (i=0;i<9;i++) perms[i]='-';
if (mode & S_IRUSR) perms[0] = 'r';
if (mode & S_IWUSR) perms[1] = 'w';
if (mode & S_IXUSR) perms[2] = 'x';
if (mode & S_IRGRP) perms[3] = 'r';
if (mode & S_IWGRP) perms[4] = 'w';
if (mode & S_IXGRP) perms[5] = 'x';
if (mode & S_IROTH) perms[6] = 'r';
if (mode & S_IWOTH) perms[7] = 'w';
if (mode & S_IXOTH) perms[8] = 'x';
return perms;
}
#endif
/* permssions string */
static void push_st_perm (lua_State *L, STAT_STRUCT *info) {
lua_pushstring (L, perm2string (info->st_mode));
}
typedef void (*_push_function) (lua_State *L, STAT_STRUCT *info); typedef void (*_push_function) (lua_State *L, STAT_STRUCT *info);
struct _stat_members { struct _stat_members {
@@ -722,6 +775,7 @@ struct _stat_members members[] = {
{ "modification", push_st_mtime }, { "modification", push_st_mtime },
{ "change", push_st_ctime }, { "change", push_st_ctime },
{ "size", push_st_size }, { "size", push_st_size },
{ "permissions", push_st_perm },
#ifndef _WIN32 #ifndef _WIN32
{ "blocks", push_st_blocks }, { "blocks", push_st_blocks },
{ "blksize", push_st_blksize }, { "blksize", push_st_blksize },

View File

@@ -4,7 +4,7 @@ local tmp = "/tmp"
local sep = string.match (package.config, "[^\n]+") local sep = string.match (package.config, "[^\n]+")
local upper = ".." local upper = ".."
require"lfs" local lfs = require"lfs"
print (lfs._VERSION) print (lfs._VERSION)
function attrdir (path) function attrdir (path)