mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-25 13:13:07 +00:00
Pequenas melhorias na documentacao.
Implementacao da funcao `attributes' que recupera informacoes sobre os arquivos.
This commit is contained in:
@@ -60,6 +60,11 @@ as Lua 5.0.
|
|||||||
Current version is 1.0 alpha.
|
Current version is 1.0 alpha.
|
||||||
It was developed for Lua 5.0.
|
It was developed for Lua 5.0.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
Version 1.0 follows the
|
||||||
|
<a href="http://www.keplerproject.org/compat">package proposal</a>
|
||||||
|
for Lua 5.1
|
||||||
|
(see section <a href="#installation">Installation</a> for more details).
|
||||||
|
|
||||||
|
|
||||||
<a name="download"></a>
|
<a name="download"></a>
|
||||||
@@ -77,10 +82,34 @@ LuaFileSystem can be downloaded in source code from the following links:
|
|||||||
<h2>What's new</h2>
|
<h2>What's new</h2>
|
||||||
<p>
|
<p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>[2/Aug/2004] Version 1.0 alpha released
|
<li>[?/?/2004] Version 1.0 alpha released
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
<a name="installation"></a>
|
||||||
|
<h2>Installation</h2>
|
||||||
|
<p>
|
||||||
|
LuaFileSystem is distributed as a pair of C source and header files.
|
||||||
|
The distribution provides a <tt>Makefile</tt> prepared to compile the
|
||||||
|
library and install it.
|
||||||
|
The file <tt>config</tt> should be edited to suit the needs of the aimed
|
||||||
|
platform.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
LuaFileSystem follows the
|
||||||
|
<a href="http://www.keplerproject.org/compat">package proposal</a>
|
||||||
|
for Lua 5.1,
|
||||||
|
therefore this package should be "installed".
|
||||||
|
In other words,
|
||||||
|
if you are using Lua 5.0,
|
||||||
|
the files <tt>compat-5.1.c</tt> and <tt>compat-5.1.h</tt> must be used
|
||||||
|
in the compilation and the file <tt>compat-5.1.lua</tt> must be installed
|
||||||
|
in the <tt>LUA_PATH</tt>.
|
||||||
|
If you are using Lua 5.1,
|
||||||
|
nothing should be done.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<a name="credits"></a>
|
<a name="credits"></a>
|
||||||
<h2>Credits</h2>
|
<h2>Credits</h2>
|
||||||
|
|
||||||
@@ -106,7 +135,7 @@ Comments are welcome!
|
|||||||
<p>
|
<p>
|
||||||
<hr>
|
<hr>
|
||||||
<small>
|
<small>
|
||||||
$Id: index.html,v 1.1 2004/07/27 14:15:24 tomas Exp $
|
$Id: index.html,v 1.2 2004/10/23 22:33:11 tomas Exp $
|
||||||
</small>
|
</small>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
123
src/lfs.c
123
src/lfs.c
@@ -9,13 +9,14 @@
|
|||||||
** lfs.lock (fh, mode)
|
** lfs.lock (fh, mode)
|
||||||
** lfs.unlock (fh)
|
** lfs.unlock (fh)
|
||||||
**
|
**
|
||||||
** $Id: lfs.c,v 1.3 2004/10/15 10:04:15 tomas Exp $
|
** $Id: lfs.c,v 1.4 2004/10/23 22:33:11 tomas Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
@@ -26,7 +27,6 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
@@ -335,7 +335,126 @@ static int dir_create_meta (lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define S_ISDIR(mode) (mode&_S_IFDIR)
|
||||||
|
#define S_ISREG(mode) (mode&_S_IFREG)
|
||||||
|
#define S_ISLNK(mode) (0)
|
||||||
|
#define S_ISSOCK(mode) (0)
|
||||||
|
#define S_ISFIFO(mode) (0)
|
||||||
|
#define S_ISCHR(mode) (0)
|
||||||
|
#define S_ISBLK(mode) (0)
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
** Convert the inode protection mode to a string.
|
||||||
|
*/
|
||||||
|
static const char *mode2string (mode_t mode) {
|
||||||
|
if ( S_ISREG(mode) )
|
||||||
|
return "file";
|
||||||
|
else if ( S_ISDIR(mode) )
|
||||||
|
return "directory";
|
||||||
|
else if ( S_ISLNK(mode) )
|
||||||
|
return "link";
|
||||||
|
else if ( S_ISSOCK(mode) )
|
||||||
|
return "socket";
|
||||||
|
else if ( S_ISFIFO(mode) )
|
||||||
|
return "named pipe";
|
||||||
|
else if ( S_ISCHR(mode) )
|
||||||
|
return "char device";
|
||||||
|
else if ( S_ISBLK(mode) )
|
||||||
|
return "block device";
|
||||||
|
else
|
||||||
|
return "other";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Convert a struct timespec to a Lua table.
|
||||||
|
*/
|
||||||
|
static lua_Number time2number (struct timespec t) {
|
||||||
|
return (lua_Number)t.tv_sec + (lua_Number)t.tv_nsec / 1000000000.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Get file information
|
||||||
|
*/
|
||||||
|
static int file_info (lua_State *L) {
|
||||||
|
struct stat info;
|
||||||
|
const char *file = luaL_checkstring (L, 1);
|
||||||
|
|
||||||
|
if (stat(file, &info)) {
|
||||||
|
lua_pushnil (L);
|
||||||
|
lua_pushfstring (L, "cannot obtain information from file `%s'", file);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
lua_newtable (L);
|
||||||
|
/* device inode resides on */
|
||||||
|
lua_pushliteral (L, "dev");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_dev);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* inode's number */
|
||||||
|
lua_pushliteral (L, "ino");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_ino);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* inode protection mode */
|
||||||
|
lua_pushliteral (L, "mode");
|
||||||
|
lua_pushstring (L, mode2string (info.st_mode));
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* number or hard links to the file */
|
||||||
|
lua_pushliteral (L, "nlink");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_nlink);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* user-id of owner */
|
||||||
|
lua_pushliteral (L, "uid");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_uid);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* group-id of owner */
|
||||||
|
lua_pushliteral (L, "gid");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_gid);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* device type, for special file inode */
|
||||||
|
lua_pushliteral (L, "rdev");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_rdev);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* time of last access */
|
||||||
|
lua_pushliteral (L, "access");
|
||||||
|
lua_pushnumber (L, time2number (info.st_atimespec));
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* time of last data modification */
|
||||||
|
lua_pushliteral (L, "modification");
|
||||||
|
lua_pushnumber (L, time2number (info.st_mtimespec));
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* time of last file status change */
|
||||||
|
lua_pushliteral (L, "change");
|
||||||
|
lua_pushnumber (L, time2number (info.st_ctimespec));
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* file size, in bytes */
|
||||||
|
lua_pushliteral (L, "size");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_size);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* blocks allocated for file */
|
||||||
|
lua_pushliteral (L, "blocks");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_blocks);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* optimal file system I/O blocksize */
|
||||||
|
lua_pushliteral (L, "blksize");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_blksize);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* user defined flags for file */
|
||||||
|
lua_pushliteral (L, "flags");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_flags);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
/* file generation number */
|
||||||
|
lua_pushliteral (L, "gen");
|
||||||
|
lua_pushnumber (L, (lua_Number)info.st_gen);
|
||||||
|
lua_rawset (L, -3);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const struct luaL_reg fslib[] = {
|
static const struct luaL_reg fslib[] = {
|
||||||
|
{"attributes", file_info},
|
||||||
{"chdir", change_dir},
|
{"chdir", change_dir},
|
||||||
{"currentdir", get_dir},
|
{"currentdir", get_dir},
|
||||||
{"dir", dir_iter_factory},
|
{"dir", dir_iter_factory},
|
||||||
|
|||||||
Reference in New Issue
Block a user