aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomas <tomas>2004-10-23 22:33:11 +0000
committertomas <tomas>2004-10-23 22:33:11 +0000
commit7049b69af19dfbe3fced0e0a02e07af809a7c1b6 (patch)
treeb5e6cf2cba0562c2b3188479dbaaa1a126395aca
parentb191446532a020ab0b2734cf64d99a1599b9cdb1 (diff)
downloadluafilesystem-7049b69af19dfbe3fced0e0a02e07af809a7c1b6.tar.gz
luafilesystem-7049b69af19dfbe3fced0e0a02e07af809a7c1b6.tar.bz2
luafilesystem-7049b69af19dfbe3fced0e0a02e07af809a7c1b6.zip
Pequenas melhorias na documentacao.
Implementacao da funcao `attributes' que recupera informacoes sobre os arquivos.
-rw-r--r--doc/us/index.html33
-rw-r--r--src/lfs.c123
2 files changed, 152 insertions, 4 deletions
diff --git a/doc/us/index.html b/doc/us/index.html
index 6b81ad9..78b38e3 100644
--- a/doc/us/index.html
+++ b/doc/us/index.html
@@ -60,6 +60,11 @@ as Lua 5.0.
60Current version is 1.0 alpha. 60Current version is 1.0 alpha.
61It was developed for Lua 5.0. 61It was developed for Lua 5.0.
62</p> 62</p>
63<p>
64Version 1.0 follows the
65<a href="http://www.keplerproject.org/compat">package proposal</a>
66for Lua 5.1
67(see section <a href="#installation">Installation</a> for more details).
63 68
64 69
65<a name="download"></a> 70<a name="download"></a>
@@ -77,10 +82,34 @@ LuaFileSystem can be downloaded in source code from the following links:
77<h2>What's new</h2> 82<h2>What's new</h2>
78<p> 83<p>
79<ul> 84<ul>
80 <li>[2/Aug/2004] Version 1.0 alpha released 85 <li>[?/?/2004] Version 1.0 alpha released
81</ul> 86</ul>
82 87
83 88
89<a name="installation"></a>
90<h2>Installation</h2>
91<p>
92LuaFileSystem is distributed as a pair of C source and header files.
93The distribution provides a <tt>Makefile</tt> prepared to compile the
94library and install it.
95The file <tt>config</tt> should be edited to suit the needs of the aimed
96platform.
97</p>
98<p>
99LuaFileSystem follows the
100<a href="http://www.keplerproject.org/compat">package proposal</a>
101for Lua 5.1,
102therefore this package should be "installed".
103In other words,
104if you are using Lua 5.0,
105the files <tt>compat-5.1.c</tt> and <tt>compat-5.1.h</tt> must be used
106in the compilation and the file <tt>compat-5.1.lua</tt> must be installed
107in the <tt>LUA_PATH</tt>.
108If you are using Lua 5.1,
109nothing should be done.
110</p>
111
112
84<a name="credits"></a> 113<a name="credits"></a>
85<h2>Credits</h2> 114<h2>Credits</h2>
86 115
@@ -106,7 +135,7 @@ Comments are welcome!
106<p> 135<p>
107<hr> 136<hr>
108<small> 137<small>
109$Id: index.html,v 1.1 2004/07/27 14:15:24 tomas Exp $ 138$Id: index.html,v 1.2 2004/10/23 22:33:11 tomas Exp $
110</small> 139</small>
111 140
112</body> 141</body>
diff --git a/src/lfs.c b/src/lfs.c
index 0b947d0..bf0f02b 100644
--- a/src/lfs.c
+++ b/src/lfs.c
@@ -9,13 +9,14 @@
9** lfs.lock (fh, mode) 9** lfs.lock (fh, mode)
10** lfs.unlock (fh) 10** lfs.unlock (fh)
11** 11**
12** $Id: lfs.c,v 1.3 2004/10/15 10:04:15 tomas Exp $ 12** $Id: lfs.c,v 1.4 2004/10/23 22:33:11 tomas Exp $
13*/ 13*/
14 14
15#include <errno.h> 15#include <errno.h>
16#include <stdio.h> 16#include <stdio.h>
17#include <string.h> 17#include <string.h>
18#include <time.h> 18#include <time.h>
19#include <sys/stat.h>
19 20
20#ifdef WIN32 21#ifdef WIN32
21#include <direct.h> 22#include <direct.h>
@@ -26,7 +27,6 @@
26#include <dirent.h> 27#include <dirent.h>
27#include <fcntl.h> 28#include <fcntl.h>
28#include <sys/types.h> 29#include <sys/types.h>
29#include <sys/stat.h>
30#endif 30#endif
31 31
32#include <lua.h> 32#include <lua.h>
@@ -335,7 +335,126 @@ static int dir_create_meta (lua_State *L) {
335} 335}
336 336
337 337
338#ifdef _WIN32
339 #define S_ISDIR(mode) (mode&_S_IFDIR)
340 #define S_ISREG(mode) (mode&_S_IFREG)
341 #define S_ISLNK(mode) (0)
342 #define S_ISSOCK(mode) (0)
343 #define S_ISFIFO(mode) (0)
344 #define S_ISCHR(mode) (0)
345 #define S_ISBLK(mode) (0)
346#endif
347/*
348** Convert the inode protection mode to a string.
349*/
350static const char *mode2string (mode_t mode) {
351 if ( S_ISREG(mode) )
352 return "file";
353 else if ( S_ISDIR(mode) )
354 return "directory";
355 else if ( S_ISLNK(mode) )
356 return "link";
357 else if ( S_ISSOCK(mode) )
358 return "socket";
359 else if ( S_ISFIFO(mode) )
360 return "named pipe";
361 else if ( S_ISCHR(mode) )
362 return "char device";
363 else if ( S_ISBLK(mode) )
364 return "block device";
365 else
366 return "other";
367}
368
369
370/*
371** Convert a struct timespec to a Lua table.
372*/
373static lua_Number time2number (struct timespec t) {
374 return (lua_Number)t.tv_sec + (lua_Number)t.tv_nsec / 1000000000.0;
375}
376
377
378/*
379** Get file information
380*/
381static int file_info (lua_State *L) {
382 struct stat info;
383 const char *file = luaL_checkstring (L, 1);
384
385 if (stat(file, &info)) {
386 lua_pushnil (L);
387 lua_pushfstring (L, "cannot obtain information from file `%s'", file);
388 return 2;
389 }
390 lua_newtable (L);
391 /* device inode resides on */
392 lua_pushliteral (L, "dev");
393 lua_pushnumber (L, (lua_Number)info.st_dev);
394 lua_rawset (L, -3);
395 /* inode's number */
396 lua_pushliteral (L, "ino");
397 lua_pushnumber (L, (lua_Number)info.st_ino);
398 lua_rawset (L, -3);
399 /* inode protection mode */
400 lua_pushliteral (L, "mode");
401 lua_pushstring (L, mode2string (info.st_mode));
402 lua_rawset (L, -3);
403 /* number or hard links to the file */
404 lua_pushliteral (L, "nlink");
405 lua_pushnumber (L, (lua_Number)info.st_nlink);
406 lua_rawset (L, -3);
407 /* user-id of owner */
408 lua_pushliteral (L, "uid");
409 lua_pushnumber (L, (lua_Number)info.st_uid);
410 lua_rawset (L, -3);
411 /* group-id of owner */
412 lua_pushliteral (L, "gid");
413 lua_pushnumber (L, (lua_Number)info.st_gid);
414 lua_rawset (L, -3);
415 /* device type, for special file inode */
416 lua_pushliteral (L, "rdev");
417 lua_pushnumber (L, (lua_Number)info.st_rdev);
418 lua_rawset (L, -3);
419 /* time of last access */
420 lua_pushliteral (L, "access");
421 lua_pushnumber (L, time2number (info.st_atimespec));
422 lua_rawset (L, -3);
423 /* time of last data modification */
424 lua_pushliteral (L, "modification");
425 lua_pushnumber (L, time2number (info.st_mtimespec));
426 lua_rawset (L, -3);
427 /* time of last file status change */
428 lua_pushliteral (L, "change");
429 lua_pushnumber (L, time2number (info.st_ctimespec));
430 lua_rawset (L, -3);
431 /* file size, in bytes */
432 lua_pushliteral (L, "size");
433 lua_pushnumber (L, (lua_Number)info.st_size);
434 lua_rawset (L, -3);
435 /* blocks allocated for file */
436 lua_pushliteral (L, "blocks");
437 lua_pushnumber (L, (lua_Number)info.st_blocks);
438 lua_rawset (L, -3);
439 /* optimal file system I/O blocksize */
440 lua_pushliteral (L, "blksize");
441 lua_pushnumber (L, (lua_Number)info.st_blksize);
442 lua_rawset (L, -3);
443 /* user defined flags for file */
444 lua_pushliteral (L, "flags");
445 lua_pushnumber (L, (lua_Number)info.st_flags);
446 lua_rawset (L, -3);
447 /* file generation number */
448 lua_pushliteral (L, "gen");
449 lua_pushnumber (L, (lua_Number)info.st_gen);
450 lua_rawset (L, -3);
451
452 return 1;
453}
454
455
338static const struct luaL_reg fslib[] = { 456static const struct luaL_reg fslib[] = {
457 {"attributes", file_info},
339 {"chdir", change_dir}, 458 {"chdir", change_dir},
340 {"currentdir", get_dir}, 459 {"currentdir", get_dir},
341 {"dir", dir_iter_factory}, 460 {"dir", dir_iter_factory},