diff --git a/Makefile b/Makefile index 5a75e04..b0bf741 100644 --- a/Makefile +++ b/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 diff --git a/src/lfs.c b/src/lfs.c index 4b4db61..5e09823 100644 --- a/src/lfs.c +++ b/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 @@ -22,11 +23,13 @@ #include #include #include +#include #else #include #include #include #include +#include #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}, }; diff --git a/vc6/lfs.def b/vc6/lfs.def index b2d5650..29d8a1f 100644 --- a/vc6/lfs.def +++ b/vc6/lfs.def @@ -1,5 +1,5 @@ LIBRARY lfs.dll DESCRIPTION "LuaFileSystem" -VERSION 1.0 +VERSION 1.1 EXPORTS luaopen_lfs