mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-22 02:53:06 +00:00
Acrescimo da funcao lfs.touch, inaugurando a versao 1.1.
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,10 +1,10 @@
|
||||
# $Id: Makefile,v 1.12 2005/01/19 14:28:58 tomas Exp $
|
||||
# $Id: Makefile,v 1.13 2005/01/21 10:19:04 tomas Exp $
|
||||
|
||||
T= lfs
|
||||
|
||||
include ./config
|
||||
|
||||
V= 1.0
|
||||
V= 1.1b
|
||||
DIST_DIR= luafilesystem-$V
|
||||
TAR_FILE= $(DIST_DIR).tar.gz
|
||||
ZIP_FILE= $(DIST_DIR).zip
|
||||
|
||||
34
src/lfs.c
34
src/lfs.c
@@ -5,11 +5,12 @@
|
||||
** lfs.chdir (path)
|
||||
** lfs.currentdir ()
|
||||
** lfs.dir (path)
|
||||
** lfs.mkdir (path)
|
||||
** lfs.lock (fh, mode)
|
||||
** lfs.mkdir (path)
|
||||
** lfs.touch (filepath [, atime [, mtime]])
|
||||
** lfs.unlock (fh)
|
||||
**
|
||||
** $Id: lfs.c,v 1.17 2005/01/19 14:28:58 tomas Exp $
|
||||
** $Id: lfs.c,v 1.18 2005/01/21 10:19:04 tomas Exp $
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
@@ -22,11 +23,13 @@
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <sys/locking.h>
|
||||
#include <sys/utime.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <utime.h>
|
||||
#endif
|
||||
|
||||
#include "lua.h"
|
||||
@@ -394,6 +397,30 @@ static const char *mode2string (mode_t mode) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Set access time and modification values for file
|
||||
*/
|
||||
static int file_utime (lua_State *L) {
|
||||
const char *file = luaL_checkstring (L, 1);
|
||||
struct utimbuf utb, *buf;
|
||||
|
||||
if (lua_gettop (L) == 1) /* set to current date/time */
|
||||
buf = NULL;
|
||||
else {
|
||||
utb.actime = (time_t)luaL_optnumber (L, 2, 0);
|
||||
utb.modtime = (time_t)luaL_optnumber (L, 3, utb.actime);
|
||||
buf = &utb;
|
||||
}
|
||||
if (utime (file, buf)) {
|
||||
lua_pushnil (L);
|
||||
lua_pushfstring (L, "%s", strerror (errno));
|
||||
return 2;
|
||||
}
|
||||
lua_pushboolean (L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Get file information
|
||||
*/
|
||||
@@ -480,7 +507,7 @@ static void set_info (lua_State *L) {
|
||||
lua_pushliteral (L, "LuaFileSystem");
|
||||
lua_settable (L, -3);
|
||||
lua_pushliteral (L, "_VERSION");
|
||||
lua_pushliteral (L, "1.0");
|
||||
lua_pushliteral (L, "1.1b");
|
||||
lua_settable (L, -3);
|
||||
}
|
||||
|
||||
@@ -492,6 +519,7 @@ static const struct luaL_reg fslib[] = {
|
||||
{"dir", dir_iter_factory},
|
||||
{"lock", file_lock},
|
||||
{"mkdir", make_dir},
|
||||
{"touch", file_utime},
|
||||
{"unlock", file_unlock},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
LIBRARY lfs.dll
|
||||
DESCRIPTION "LuaFileSystem"
|
||||
VERSION 1.0
|
||||
VERSION 1.1
|
||||
EXPORTS
|
||||
luaopen_lfs
|
||||
|
||||
Reference in New Issue
Block a user