diff options
author | tomas <tomas> | 2005-01-18 10:48:02 +0000 |
---|---|---|
committer | tomas <tomas> | 2005-01-18 10:48:02 +0000 |
commit | 86e97088a0e6c6a1ad0af79991ade650f0b51faa (patch) | |
tree | 30ca6c1ec04fd4ef16c3a9dff163ff0a4d13d6a1 /src | |
parent | 7a93f7ee03c7cbbda3ea33b0ad9fce6c319b91c8 (diff) | |
download | luafilesystem-86e97088a0e6c6a1ad0af79991ade650f0b51faa.tar.gz luafilesystem-86e97088a0e6c6a1ad0af79991ade650f0b51faa.tar.bz2 luafilesystem-86e97088a0e6c6a1ad0af79991ade650f0b51faa.zip |
Acrescimo da funcao lfs.touch (lfs.c e test.lua).
Pequenas correcoes para evitar warnings de redefinicao de macros.
Diffstat (limited to 'src')
-rw-r--r-- | src/lfs.c | 59 |
1 files changed, 50 insertions, 9 deletions
@@ -7,9 +7,10 @@ | |||
7 | ** lfs.dir (path) | 7 | ** lfs.dir (path) |
8 | ** lfs.mkdir (path) | 8 | ** lfs.mkdir (path) |
9 | ** lfs.lock (fh, mode) | 9 | ** lfs.lock (fh, mode) |
10 | ** lfs.touch (filepath [, atime [, mtime]]) | ||
10 | ** lfs.unlock (fh) | 11 | ** lfs.unlock (fh) |
11 | ** | 12 | ** |
12 | ** $Id: lfs.c,v 1.14 2004/11/17 14:08:04 tomas Exp $ | 13 | ** $Id: lfs.c,v 1.15 2005/01/18 10:48:02 tomas Exp $ |
13 | */ | 14 | */ |
14 | 15 | ||
15 | #include <errno.h> | 16 | #include <errno.h> |
@@ -17,6 +18,7 @@ | |||
17 | #include <string.h> | 18 | #include <string.h> |
18 | #include <time.h> | 19 | #include <time.h> |
19 | #include <sys/stat.h> | 20 | #include <sys/stat.h> |
21 | #include <utime.h> | ||
20 | 22 | ||
21 | #ifdef WIN32 | 23 | #ifdef WIN32 |
22 | #include <direct.h> | 24 | #include <direct.h> |
@@ -131,7 +133,7 @@ static int _file_lock (lua_State *L, FILE *fh, const char *mode, const long star | |||
131 | case 'r': lkmode = _LK_NBLCK; break; | 133 | case 'r': lkmode = _LK_NBLCK; break; |
132 | case 'w': lkmode = _LK_NBLCK; break; | 134 | case 'w': lkmode = _LK_NBLCK; break; |
133 | case 'u': lkmode = _LK_UNLCK; break; | 135 | case 'u': lkmode = _LK_UNLCK; break; |
134 | default : luaL_error (L, "%s: invalid mode", funcname); | 136 | default : return luaL_error (L, "%s: invalid mode", funcname); |
135 | } | 137 | } |
136 | if (!len) { | 138 | if (!len) { |
137 | fseek (fh, 0L, SEEK_END); | 139 | fseek (fh, 0L, SEEK_END); |
@@ -345,13 +347,27 @@ static int dir_create_meta (lua_State *L) { | |||
345 | 347 | ||
346 | 348 | ||
347 | #ifdef _WIN32 | 349 | #ifdef _WIN32 |
348 | #define S_ISDIR(mode) (mode&_S_IFDIR) | 350 | #ifndef S_ISDIR |
349 | #define S_ISREG(mode) (mode&_S_IFREG) | 351 | #define S_ISDIR(mode) (mode&_S_IFDIR) |
350 | #define S_ISLNK(mode) (0) | 352 | #endif |
351 | #define S_ISSOCK(mode) (0) | 353 | #ifndef S_ISREG |
352 | #define S_ISFIFO(mode) (0) | 354 | #define S_ISREG(mode) (mode&_S_IFREG) |
353 | #define S_ISCHR(mode) (mode&_S_IFCHR) | 355 | #endif |
354 | #define S_ISBLK(mode) (0) | 356 | #ifndef S_ISLNK |
357 | #define S_ISLNK(mode) (0) | ||
358 | #endif | ||
359 | #ifndef S_ISSOCK | ||
360 | #define S_ISSOCK(mode) (0) | ||
361 | #endif | ||
362 | #ifndef S_ISFIFO | ||
363 | #define S_ISFIFO(mode) (0) | ||
364 | #endif | ||
365 | #ifndef S_ISCHR | ||
366 | #define S_ISCHR(mode) (mode&_S_IFCHR) | ||
367 | #endif | ||
368 | #ifndef S_ISBLK | ||
369 | #define S_ISBLK(mode) (0) | ||
370 | #endif | ||
355 | #endif | 371 | #endif |
356 | /* | 372 | /* |
357 | ** Convert the inode protection mode to a string. | 373 | ** Convert the inode protection mode to a string. |
@@ -381,6 +397,30 @@ static const char *mode2string (mode_t mode) { | |||
381 | 397 | ||
382 | 398 | ||
383 | /* | 399 | /* |
400 | ** Set access time and modification values for file | ||
401 | */ | ||
402 | static int file_utime (lua_State *L) { | ||
403 | const char *file = luaL_checkstring (L, 1); | ||
404 | struct utimbuf utb, *buf; | ||
405 | |||
406 | if (lua_gettop (L) == 1) /* set to current date/time */ | ||
407 | buf = NULL; | ||
408 | else { | ||
409 | utb.actime = (time_t)luaL_optnumber (L, 2, 0); | ||
410 | utb.modtime = (time_t)luaL_optnumber (L, 3, utb.actime); | ||
411 | buf = &utb; | ||
412 | } | ||
413 | if (utime (file, buf)) { | ||
414 | lua_pushnil (L); | ||
415 | lua_pushfstring (L, "%s", strerror (errno)); | ||
416 | return 2; | ||
417 | } | ||
418 | lua_pushboolean (L, 1); | ||
419 | return 1; | ||
420 | } | ||
421 | |||
422 | |||
423 | /* | ||
384 | ** Get file information | 424 | ** Get file information |
385 | */ | 425 | */ |
386 | static int file_info (lua_State *L) { | 426 | static int file_info (lua_State *L) { |
@@ -478,6 +518,7 @@ static const struct luaL_reg fslib[] = { | |||
478 | {"dir", dir_iter_factory}, | 518 | {"dir", dir_iter_factory}, |
479 | {"lock", file_lock}, | 519 | {"lock", file_lock}, |
480 | {"mkdir", make_dir}, | 520 | {"mkdir", make_dir}, |
521 | {"touch", file_utime}, | ||
481 | {"unlock", file_unlock}, | 522 | {"unlock", file_unlock}, |
482 | {NULL, NULL}, | 523 | {NULL, NULL}, |
483 | }; | 524 | }; |