lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


After hacking in support for lstat():

% ls -ld link linkee
lrwxrwxrwx 1 sroberts users    6 2007-05-22 18:04 link -> linkee/
drwxr-xr-x 2 sroberts users 4096 2007-05-22 18:04 linkee/

% ./LUA_bdb1_Test
stat(linkee)    stat(link)      lstat(link)
dev     769     769     769
change  1179882270      1179882270      1179882279
access  1179882608      1179882608      1179882974
rdev    0       0       0
nlink   2       2       1
blksize 4096    4096    4096
uid     2122    2122    2122
blocks  8       8       0
gid     100     100     100
ino     5183044 5183044 3823400
mode    directory       directory       link
modification    1179882270      1179882270      1179882279
size    4096    4096    6

Note that stating the linkee and the link are the same, but lstat isn't.

l0 = lfs.attributes("linkee")
l1 = lfs.attributes("link")
l2 = lfs.lattributes("link")

print("stat(linkee)", "stat(link)", "lstat(link)")
for k,v in l0 do
    print(k, v, l1[k], l2[k])
end


Cheers,
Sam


@@ -534,12 +534,12 @@
 /*
 ** Get file information
 */
-static int file_info (lua_State *L) {
+static int file_info_ (lua_State *L, int (*st)(const char*, struct stat*)) {
 	int i;
 	struct stat info;
 	const char *file = luaL_checkstring (L, 1);
 
-	if (stat(file, &info)) {
+	if (st(file, &info)) {
 		lua_pushnil (L);
 		lua_pushfstring (L, "cannot obtain information from file `%s'", file);
 		return 2;
@@ -570,6 +570,13 @@
 	return 1;
 }
 
+static int file_info (lua_State *L) {
+	return file_info_(L, stat);
+}
+
+static int file_linfo (lua_State *L) {
+	return file_info_(L, lstat);
+}
 
 /*
 ** Assumes the table is on top of the stack.
@@ -589,6 +596,7 @@
 
 static const struct luaL_reg fslib[] = {
 	{"attributes", file_info},
+	{"lattributes", file_linfo},
 	{"chdir", change_dir},
 	{"currentdir", get_dir},
 	{"dir", dir_iter_factory},