Exemple #1
0
/***
File state record.
@table PosixStat
@int st_dev device id
@int st_ino inode number
@int st_mode mode of file
@int st_nlink number of hardlinks to file
@int st_uid user id of file owner
@int st_gid group id of file owner
@int st_rdev additional device specific id for special files
@int st_size file size in bytes
@int st_atime time of last access
@int st_mtime time of last data modification
@int st_ctime time of last state change
@int st_blksize preferred block size
@int st_blocks number of blocks allocated
*/
static int
pushstat(lua_State *L, struct stat *st)
{
	if (!st)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 13);

	setintegerfield(st, st_dev);
	setintegerfield(st, st_ino);
	setintegerfield(st, st_mode);
	setintegerfield(st, st_nlink);
	setintegerfield(st, st_uid);
	setintegerfield(st, st_gid);
	setintegerfield(st, st_rdev);
	setintegerfield(st, st_size);
	setintegerfield(st, st_blksize);
	setintegerfield(st, st_blocks);

	/* st_[amc]time is a macro on at least Mac OS, so we have to
	   assign field name strings manually. */
        pushintegerfield("st_atime", st->st_atime);
        pushintegerfield("st_mtime", st->st_mtime);
        pushintegerfield("st_ctime", st->st_ctime);

	settypemetatable("PosixStat");
	return 1;
}
Exemple #2
0
/***
Timespec record.
@table PosixTimespec
@int tv_sec seconds
@int tv_nsec nanoseconds
@see posix.sys.time.PosixTimeval
*/
static int
pushtimespec(lua_State *L, struct timespec *ts)
{
	if (!ts)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 2);
	setintegerfield(ts, tv_sec);
	setintegerfield(ts, tv_nsec);

	settypemetatable("PosixTimespec");
	return 1;
}
Exemple #3
0
static int
pushpasswd(lua_State *L, struct passwd *p)
{
	if (!p)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 6);
	setintegerfield(p, pw_uid);
	setintegerfield(p, pw_gid);
	setstringfield(p, pw_name);
	setstringfield(p, pw_dir);
	setstringfield(p, pw_shell);
	setstringfield(p, pw_passwd);

	settypemetatable("PosixPasswd");
	return 1;
}
Exemple #4
0
/***
Datetime record.
@table PosixTm
@int tm_sec second [0,60]
@int tm_min minute [0,59]
@int tm_hour hour [0,23]
@int tm_mday day of month [1, 31]
@int tm_mon month of year [0,11]
@int tm_year years since 1900
@int tm_wday day of week [0=Sunday,6]
@int tm_yday day of year [0,365[
@int tm_isdst 0 if daylight savings time is not in effect
*/
static int
pushtm(lua_State *L, struct tm *t)
{
	if (!t)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 9);
	setintegerfield(t, tm_sec);
	setintegerfield(t, tm_min);
	setintegerfield(t, tm_hour);
	setintegerfield(t, tm_mday);
	setintegerfield(t, tm_mday);
	setintegerfield(t, tm_mon);
	setintegerfield(t, tm_year);
	setintegerfield(t, tm_wday);
	setintegerfield(t, tm_yday);
	setintegerfield(t, tm_isdst);

	settypemetatable("PosixTm");
	return 1;
}
Exemple #5
0
static int
pushgroup(lua_State *L, struct group *g)
{
	if (!g)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 3);
	setintegerfield(g, gr_gid);
	setstringfield(g, gr_name);
	if (g->gr_mem)
	{
		int i;
		lua_newtable(L);
		for (i = 0; g->gr_mem[i] != NULL; i++)
		{
			lua_pushstring(L, g->gr_mem[i]);
			lua_rawseti(L, -2, i + 1);
		}
		lua_setfield(L, -2, "gr_mem");
	}

	settypemetatable("PosixGroup");
	return 1;
}
Exemple #6
0
/***
Files system information record.
@table PosixStatvfs
@int f_bsize file system block size
@int f_frsize fundamental file system block size
@int f_blocks number of *f_frsize* sized blocks in file system
@int f_bfree number of free blocks
@int f_bavail number of free blocks available to non-privileged process
@int f_files number of file serial numbers
@int f_ffree number of free file serial numbers
@int f_favail number of free file serial numbers available
@int f_fsid file system id
@int f_flag flag bits
@int f_namemax maximum filename length
*/
static int
pushstatvfs(lua_State *L, struct statvfs *sv)
{
	if (!sv)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 11);

	setintegerfield(sv, f_bsize);
	setintegerfield(sv, f_frsize);
	setintegerfield(sv, f_blocks);
	setintegerfield(sv, f_bfree);
	setintegerfield(sv, f_bavail);
	setintegerfield(sv, f_files);
	setintegerfield(sv, f_ffree);
	setintegerfield(sv, f_favail);
	setintegerfield(sv, f_fsid);
	setintegerfield(sv, f_flag);
	setintegerfield(sv, f_namemax);

	settypemetatable("PosixStatvfs");
	return 1;
}