aboutsummaryrefslogtreecommitdiff
path: root/src/lfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lfs.c')
-rw-r--r--src/lfs.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/lfs.c b/src/lfs.c
index bc763c1..e86840a 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -1,6 +1,6 @@
1/* 1/*
2** LuaFileSystem 2** LuaFileSystem
3** Copyright Kepler Project 2004-2006 (http://www.keplerproject.org/luafilesystem) 3** Copyright Kepler Project 2004-2007 (http://www.keplerproject.org/luafilesystem)
4** 4**
5** File system manipulation library. 5** File system manipulation library.
6** This library offers these functions: 6** This library offers these functions:
@@ -11,10 +11,11 @@
11** lfs.lock (fh, mode) 11** lfs.lock (fh, mode)
12** lfs.mkdir (path) 12** lfs.mkdir (path)
13** lfs.rmdir (path) 13** lfs.rmdir (path)
14** lfs.symlinkattributes (filepath [, attributename]) -- thanks to Sam Roberts
14** lfs.touch (filepath [, atime [, mtime]]) 15** lfs.touch (filepath [, atime [, mtime]])
15** lfs.unlock (fh) 16** lfs.unlock (fh)
16** 17**
17** $Id: lfs.c,v 1.37 2007/05/15 12:58:35 tomas Exp $ 18** $Id: lfs.c,v 1.38 2007/06/07 01:28:08 tomas Exp $
18*/ 19*/
19 20
20#include <errno.h> 21#include <errno.h>
@@ -511,14 +512,14 @@ struct _stat_members members[] = {
511}; 512};
512 513
513/* 514/*
514** Get file information 515** Get file or symbolic link information
515*/ 516*/
516static int file_info (lua_State *L) { 517static int _file_info_ (lua_State *L, int (*st)(const char*, struct stat*)) {
517 int i; 518 int i;
518 struct stat info; 519 struct stat info;
519 const char *file = luaL_checkstring (L, 1); 520 const char *file = luaL_checkstring (L, 1);
520 521
521 if (stat(file, &info)) { 522 if (st(file, &info)) {
522 lua_pushnil (L); 523 lua_pushnil (L);
523 lua_pushfstring (L, "cannot obtain information from file `%s'", file); 524 lua_pushfstring (L, "cannot obtain information from file `%s'", file);
524 return 2; 525 return 2;
@@ -551,6 +552,22 @@ static int file_info (lua_State *L) {
551 552
552 553
553/* 554/*
555** Get file information using stat.
556*/
557static int file_info (lua_State *L) {
558 return _file_info_ (L, stat);
559}
560
561
562/*
563** Get symbolic link information using lstat.
564*/
565static int link_info (lua_State *L) {
566 return _file_info_ (L, lstat);
567}
568
569
570/*
554** Assumes the table is on top of the stack. 571** Assumes the table is on top of the stack.
555*/ 572*/
556static void set_info (lua_State *L) { 573static void set_info (lua_State *L) {
@@ -561,7 +578,7 @@ static void set_info (lua_State *L) {
561 lua_pushliteral (L, "LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution"); 578 lua_pushliteral (L, "LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution");
562 lua_settable (L, -3); 579 lua_settable (L, -3);
563 lua_pushliteral (L, "_VERSION"); 580 lua_pushliteral (L, "_VERSION");
564 lua_pushliteral (L, "LuaFileSystem 1.2.1"); 581 lua_pushliteral (L, "LuaFileSystem 1.3.0");
565 lua_settable (L, -3); 582 lua_settable (L, -3);
566} 583}
567 584
@@ -574,6 +591,7 @@ static const struct luaL_reg fslib[] = {
574 {"lock", file_lock}, 591 {"lock", file_lock},
575 {"mkdir", make_dir}, 592 {"mkdir", make_dir},
576 {"rmdir", remove_dir}, 593 {"rmdir", remove_dir},
594 {"symlinkattributes", link_info},
577 {"touch", file_utime}, 595 {"touch", file_utime},
578 {"unlock", file_unlock}, 596 {"unlock", file_unlock},
579 {NULL, NULL}, 597 {NULL, NULL},