mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-24 12:23:08 +00:00
Merge pull request #48 from trms/upmaster
Lua 5.3, warnings in windows, extra null byte
This commit is contained in:
36
src/lfs.c
36
src/lfs.c
@@ -375,8 +375,8 @@ static int lfs_f_setmode(lua_State *L) {
|
|||||||
static int file_lock (lua_State *L) {
|
static int file_lock (lua_State *L) {
|
||||||
FILE *fh = check_file (L, 1, "lock");
|
FILE *fh = check_file (L, 1, "lock");
|
||||||
const char *mode = luaL_checkstring (L, 2);
|
const char *mode = luaL_checkstring (L, 2);
|
||||||
const long start = luaL_optlong (L, 3, 0);
|
const long start = (long) luaL_optinteger (L, 3, 0);
|
||||||
long len = luaL_optlong (L, 4, 0);
|
long len = (long) luaL_optinteger (L, 4, 0);
|
||||||
if (_file_lock (L, fh, mode, start, len, "lock")) {
|
if (_file_lock (L, fh, mode, start, len, "lock")) {
|
||||||
lua_pushboolean (L, 1);
|
lua_pushboolean (L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -396,8 +396,8 @@ static int file_lock (lua_State *L) {
|
|||||||
*/
|
*/
|
||||||
static int file_unlock (lua_State *L) {
|
static int file_unlock (lua_State *L) {
|
||||||
FILE *fh = check_file (L, 1, "unlock");
|
FILE *fh = check_file (L, 1, "unlock");
|
||||||
const long start = luaL_optlong (L, 2, 0);
|
const long start = (long) luaL_optinteger (L, 2, 0);
|
||||||
long len = luaL_optlong (L, 3, 0);
|
long len = (long) luaL_optinteger (L, 3, 0);
|
||||||
if (_file_lock (L, fh, "u", start, len, "unlock")) {
|
if (_file_lock (L, fh, "u", start, len, "unlock")) {
|
||||||
lua_pushboolean (L, 1);
|
lua_pushboolean (L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -664,7 +664,7 @@ static int file_utime (lua_State *L) {
|
|||||||
buf = NULL;
|
buf = NULL;
|
||||||
else {
|
else {
|
||||||
utb.actime = (time_t)luaL_optnumber (L, 2, 0);
|
utb.actime = (time_t)luaL_optnumber (L, 2, 0);
|
||||||
utb.modtime = (time_t)luaL_optnumber (L, 3, utb.actime);
|
utb.modtime = (time_t) luaL_optinteger (L, 3, utb.actime);
|
||||||
buf = &utb;
|
buf = &utb;
|
||||||
}
|
}
|
||||||
if (utime (file, buf)) {
|
if (utime (file, buf)) {
|
||||||
@@ -683,52 +683,52 @@ static void push_st_mode (lua_State *L, STAT_STRUCT *info) {
|
|||||||
}
|
}
|
||||||
/* device inode resides on */
|
/* device inode resides on */
|
||||||
static void push_st_dev (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_dev (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_dev);
|
lua_pushinteger (L, (lua_Integer) info->st_dev);
|
||||||
}
|
}
|
||||||
/* inode's number */
|
/* inode's number */
|
||||||
static void push_st_ino (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_ino (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_ino);
|
lua_pushinteger (L, (lua_Integer) info->st_ino);
|
||||||
}
|
}
|
||||||
/* number of hard links to the file */
|
/* number of hard links to the file */
|
||||||
static void push_st_nlink (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_nlink (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_nlink);
|
lua_pushinteger (L, (lua_Integer)info->st_nlink);
|
||||||
}
|
}
|
||||||
/* user-id of owner */
|
/* user-id of owner */
|
||||||
static void push_st_uid (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_uid (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_uid);
|
lua_pushinteger (L, (lua_Integer)info->st_uid);
|
||||||
}
|
}
|
||||||
/* group-id of owner */
|
/* group-id of owner */
|
||||||
static void push_st_gid (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_gid (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_gid);
|
lua_pushinteger (L, (lua_Integer)info->st_gid);
|
||||||
}
|
}
|
||||||
/* device type, for special file inode */
|
/* device type, for special file inode */
|
||||||
static void push_st_rdev (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_rdev (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_rdev);
|
lua_pushinteger (L, (lua_Integer) info->st_rdev);
|
||||||
}
|
}
|
||||||
/* time of last access */
|
/* time of last access */
|
||||||
static void push_st_atime (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_atime (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, info->st_atime);
|
lua_pushinteger (L, (lua_Integer) info->st_atime);
|
||||||
}
|
}
|
||||||
/* time of last data modification */
|
/* time of last data modification */
|
||||||
static void push_st_mtime (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_mtime (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, info->st_mtime);
|
lua_pushinteger (L, (lua_Integer) info->st_mtime);
|
||||||
}
|
}
|
||||||
/* time of last file status change */
|
/* time of last file status change */
|
||||||
static void push_st_ctime (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_ctime (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, info->st_ctime);
|
lua_pushinteger (L, (lua_Integer) info->st_ctime);
|
||||||
}
|
}
|
||||||
/* file size, in bytes */
|
/* file size, in bytes */
|
||||||
static void push_st_size (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_size (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_size);
|
lua_pushinteger (L, (lua_Integer)info->st_size);
|
||||||
}
|
}
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
/* blocks allocated for file */
|
/* blocks allocated for file */
|
||||||
static void push_st_blocks (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_blocks (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_blocks);
|
lua_pushinteger (L, (lua_Integer)info->st_blocks);
|
||||||
}
|
}
|
||||||
/* optimal file system I/O blocksize */
|
/* optimal file system I/O blocksize */
|
||||||
static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
|
static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
|
||||||
lua_pushnumber (L, (lua_Number)info->st_blksize);
|
lua_pushinteger (L, (lua_Integer)info->st_blksize);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -738,7 +738,7 @@ static void push_st_blksize (lua_State *L, STAT_STRUCT *info) {
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static const char *perm2string (unsigned short mode) {
|
static const char *perm2string (unsigned short mode) {
|
||||||
static char perms[10] = "---------\0";
|
static char perms[10] = "---------"; //removed explicit \0 (it would be the second, since "" adds one already and perms[10] is only 10 big.
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<9;i++) perms[i]='-';
|
for (i=0;i<9;i++) perms[i]='-';
|
||||||
if (mode & _S_IREAD)
|
if (mode & _S_IREAD)
|
||||||
|
|||||||
@@ -11,6 +11,14 @@
|
|||||||
#define chdir_error "Function 'chdir' not provided by system"
|
#define chdir_error "Function 'chdir' not provided by system"
|
||||||
#else
|
#else
|
||||||
#define chdir_error strerror(errno)
|
#define chdir_error strerror(errno)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define chdir(p) (_chdir(p))
|
||||||
|
#define getcwd(d, s) (_getcwd(d, s))
|
||||||
|
#define rmdir(p) (_rmdir(p))
|
||||||
|
#define fileno(f) (_fileno(f))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user