Page MenuHomeFreeBSD

D42017.1794291523.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D42017.1794291523.diff

diff --git a/libexec/flua/linit_flua.c b/libexec/flua/linit_flua.c
--- a/libexec/flua/linit_flua.c
+++ b/libexec/flua/linit_flua.c
@@ -59,6 +59,7 @@
/* FreeBSD Extensions */
{"lfs", luaopen_lfs},
{"posix.sys.stat", luaopen_posix_sys_stat},
+ {"posix.sys.utsname", luaopen_posix_sys_utsname},
{"posix.unistd", luaopen_posix_unistd},
{"ucl", luaopen_ucl},
{"fbsd", luaopen_fbsd},
diff --git a/libexec/flua/modules/lposix.h b/libexec/flua/modules/lposix.h
--- a/libexec/flua/modules/lposix.h
+++ b/libexec/flua/modules/lposix.h
@@ -8,4 +8,5 @@
#include <lua.h>
int luaopen_posix_sys_stat(lua_State *L);
+int luaopen_posix_sys_utsname(lua_State *L);
int luaopen_posix_unistd(lua_State *L);
diff --git a/libexec/flua/modules/lposix.c b/libexec/flua/modules/lposix.c
--- a/libexec/flua/modules/lposix.c
+++ b/libexec/flua/modules/lposix.c
@@ -24,8 +24,8 @@
*
*/
-#include <sys/cdefs.h>
#include <sys/stat.h>
+#include <sys/utsname.h>
#include <errno.h>
#include <grp.h>
@@ -130,12 +130,50 @@
return 1;
}
+static int
+lua_uname(lua_State *L)
+{
+ struct utsname name;
+ int error, n;
+
+ n = lua_gettop(L);
+ luaL_argcheck(L, n == 0, 1, "too many arguments");
+
+ error = uname(&name);
+ if (error != 0) {
+ error = errno;
+ lua_pushnil(L);
+ lua_pushstring(L, strerror(error));
+ lua_pushinteger(L, error);
+ return (3);
+ }
+
+ lua_newtable(L);
+#define setkv(f) do { \
+ lua_pushstring(L, name.f); \
+ lua_setfield(L, -2, #f); \
+} while (0)
+ setkv(sysname);
+ setkv(nodename);
+ setkv(release);
+ setkv(version);
+ setkv(machine);
+#undef setkv
+
+ return (1);
+}
+
#define REG_SIMPLE(n) { #n, lua_ ## n }
static const struct luaL_Reg sys_statlib[] = {
REG_SIMPLE(chmod),
{ NULL, NULL },
};
+static const struct luaL_Reg sys_utsnamelib[] = {
+ REG_SIMPLE(uname),
+ { NULL, NULL },
+};
+
static const struct luaL_Reg unistdlib[] = {
REG_SIMPLE(getpid),
REG_SIMPLE(chown),
@@ -150,6 +188,13 @@
return 1;
}
+int
+luaopen_posix_sys_utsname(lua_State *L)
+{
+ luaL_newlib(L, sys_utsnamelib);
+ return 1;
+}
+
int
luaopen_posix_unistd(lua_State *L)
{

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 10, 6:18 AM (16 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41630302
Default Alt Text
D42017.1794291523.diff (2 KB)

Event Timeline