diff options
| author | tomas <tomas> | 2005-01-21 10:19:04 +0000 |
|---|---|---|
| committer | tomas <tomas> | 2005-01-21 10:19:04 +0000 |
| commit | 57d3fc1c31e1d14446b491b135505beed3f347c3 (patch) | |
| tree | 77595d850bd925ede11c2a41f02302f010a1538a /src | |
| parent | 12ff66217ff4edc168a9282f5d7fc536a30331a8 (diff) | |
| download | luafilesystem-57d3fc1c31e1d14446b491b135505beed3f347c3.tar.gz luafilesystem-57d3fc1c31e1d14446b491b135505beed3f347c3.tar.bz2 luafilesystem-57d3fc1c31e1d14446b491b135505beed3f347c3.zip | |
Acrescimo da funcao lfs.touch, inaugurando a versao 1.1.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lfs.c | 34 |
1 files changed, 31 insertions, 3 deletions
| @@ -5,11 +5,12 @@ | |||
| 5 | ** lfs.chdir (path) | 5 | ** lfs.chdir (path) |
| 6 | ** lfs.currentdir () | 6 | ** lfs.currentdir () |
| 7 | ** lfs.dir (path) | 7 | ** lfs.dir (path) |
| 8 | ** lfs.mkdir (path) | ||
| 9 | ** lfs.lock (fh, mode) | 8 | ** lfs.lock (fh, mode) |
| 9 | ** lfs.mkdir (path) | ||
| 10 | ** lfs.touch (filepath [, atime [, mtime]]) | ||
| 10 | ** lfs.unlock (fh) | 11 | ** lfs.unlock (fh) |
| 11 | ** | 12 | ** |
| 12 | ** $Id: lfs.c,v 1.17 2005/01/19 14:28:58 tomas Exp $ | 13 | ** $Id: lfs.c,v 1.18 2005/01/21 10:19:04 tomas Exp $ |
| 13 | */ | 14 | */ |
| 14 | 15 | ||
| 15 | #include <errno.h> | 16 | #include <errno.h> |
| @@ -22,11 +23,13 @@ | |||
| 22 | #include <direct.h> | 23 | #include <direct.h> |
| 23 | #include <io.h> | 24 | #include <io.h> |
| 24 | #include <sys/locking.h> | 25 | #include <sys/locking.h> |
| 26 | #include <sys/utime.h> | ||
| 25 | #else | 27 | #else |
| 26 | #include <unistd.h> | 28 | #include <unistd.h> |
| 27 | #include <dirent.h> | 29 | #include <dirent.h> |
| 28 | #include <fcntl.h> | 30 | #include <fcntl.h> |
| 29 | #include <sys/types.h> | 31 | #include <sys/types.h> |
| 32 | #include <utime.h> | ||
| 30 | #endif | 33 | #endif |
| 31 | 34 | ||
| 32 | #include "lua.h" | 35 | #include "lua.h" |
| @@ -395,6 +398,30 @@ static const char *mode2string (mode_t mode) { | |||
| 395 | 398 | ||
| 396 | 399 | ||
| 397 | /* | 400 | /* |
| 401 | ** Set access time and modification values for file | ||
| 402 | */ | ||
| 403 | static int file_utime (lua_State *L) { | ||
| 404 | const char *file = luaL_checkstring (L, 1); | ||
| 405 | struct utimbuf utb, *buf; | ||
| 406 | |||
| 407 | if (lua_gettop (L) == 1) /* set to current date/time */ | ||
| 408 | buf = NULL; | ||
| 409 | else { | ||
| 410 | utb.actime = (time_t)luaL_optnumber (L, 2, 0); | ||
| 411 | utb.modtime = (time_t)luaL_optnumber (L, 3, utb.actime); | ||
| 412 | buf = &utb; | ||
| 413 | } | ||
| 414 | if (utime (file, buf)) { | ||
| 415 | lua_pushnil (L); | ||
| 416 | lua_pushfstring (L, "%s", strerror (errno)); | ||
| 417 | return 2; | ||
| 418 | } | ||
| 419 | lua_pushboolean (L, 1); | ||
| 420 | return 1; | ||
| 421 | } | ||
| 422 | |||
| 423 | |||
| 424 | /* | ||
| 398 | ** Get file information | 425 | ** Get file information |
| 399 | */ | 426 | */ |
| 400 | static int file_info (lua_State *L) { | 427 | static int file_info (lua_State *L) { |
| @@ -480,7 +507,7 @@ static void set_info (lua_State *L) { | |||
| 480 | lua_pushliteral (L, "LuaFileSystem"); | 507 | lua_pushliteral (L, "LuaFileSystem"); |
| 481 | lua_settable (L, -3); | 508 | lua_settable (L, -3); |
| 482 | lua_pushliteral (L, "_VERSION"); | 509 | lua_pushliteral (L, "_VERSION"); |
| 483 | lua_pushliteral (L, "1.0"); | 510 | lua_pushliteral (L, "1.1b"); |
| 484 | lua_settable (L, -3); | 511 | lua_settable (L, -3); |
| 485 | } | 512 | } |
| 486 | 513 | ||
| @@ -492,6 +519,7 @@ static const struct luaL_reg fslib[] = { | |||
| 492 | {"dir", dir_iter_factory}, | 519 | {"dir", dir_iter_factory}, |
| 493 | {"lock", file_lock}, | 520 | {"lock", file_lock}, |
| 494 | {"mkdir", make_dir}, | 521 | {"mkdir", make_dir}, |
| 522 | {"touch", file_utime}, | ||
| 495 | {"unlock", file_unlock}, | 523 | {"unlock", file_unlock}, |
| 496 | {NULL, NULL}, | 524 | {NULL, NULL}, |
| 497 | }; | 525 | }; |
