summaryrefslogtreecommitdiffstats
path: root/sysif.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-07-19 19:43:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-07-19 19:43:55 -0700
commitcf117291f8e2956c8156b170c1ed59e9520262c3 (patch)
treed5e5f5d615d80ac3e989cee74415cbdb80333816 /sysif.c
parent48fb45fc49128d64fc7b78e7359fc5753976632f (diff)
downloadtxr-cf117291f8e2956c8156b170c1ed59e9520262c3.tar.gz
txr-cf117291f8e2956c8156b170c1ed59e9520262c3.tar.bz2
txr-cf117291f8e2956c8156b170c1ed59e9520262c3.zip
Adding uname.
* configure: Detect utsname and uname. * sysif.c (utsname_s, sysname_s, nodename_s, release_s, version_s, machine_s): New symbol variables. (uname_wrap): New static function. (sysif_init): Initialize new symbol variables. Instantiate utsname struct type. Register uname_wrap as uname intrinsic function. * txr.1: Documented.
Diffstat (limited to 'sysif.c')
-rw-r--r--sysif.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/sysif.c b/sysif.c
index e22db64a..5c9f583b 100644
--- a/sysif.c
+++ b/sysif.c
@@ -67,6 +67,9 @@
#endif
#include <fnmatch.h>
#endif
+#if HAVE_UNAME
+#include <sys/utsname.h>
+#endif
#include ALLOCA_H
#include "lib.h"
#include "stream.h"
@@ -98,6 +101,11 @@ val passwd_s, gecos_s, dir_s, shell_s;
val group_s, mem_s;
#endif
+#if HAVE_UNAME
+val utsname_s, sysname_s, nodename_s, release_s, version_s, machine_s;
+val domainname_s;
+#endif
+
static val at_exit_list;
static val errno_wrap(val newval)
@@ -1410,6 +1418,29 @@ static val fnmatch_wrap(val pattern, val string, val flags)
}
#endif
+#if HAVE_UNAME
+static val uname_wrap(void)
+{
+ args_decl(args, ARGS_MIN);
+ struct utsname un;
+ int res;
+ if ((res = uname(&un)) >= 0) {
+ val out = make_struct(utsname_s, nil, args);
+ slotset(out, sysname_s, string_utf8(un.sysname));
+ slotset(out, nodename_s, string_utf8(un.nodename));
+ slotset(out, release_s, string_utf8(un.release));
+ slotset(out, version_s, string_utf8(un.version));
+ slotset(out, machine_s, string_utf8(un.machine));
+#if HAVE_UTSNAME_DOMAINNAME
+ slotset(out, domainname_s, string_utf8(un.domainname));
+#endif
+ return out;
+ }
+ uw_throwf(error_s, lit("uname failed: ~d/~s"), num(errno),
+ string_utf8(strerror(errno)), nao);
+}
+#endif
+
void sysif_init(void)
{
prot1(&at_exit_list);
@@ -1453,6 +1484,15 @@ void sysif_init(void)
group_s = intern(lit("group"), user_package);
mem_s = intern(lit("mem"), user_package);
#endif
+#if HAVE_UNAME
+ utsname_s = intern(lit("utsname"), user_package);
+ sysname_s = intern(lit("sysname"), user_package);
+ nodename_s = intern(lit("nodename"), user_package);
+ release_s = intern(lit("release"), user_package);
+ version_s = intern(lit("version"), user_package);
+ machine_s = intern(lit("machine"), user_package);
+ domainname_s = intern(lit("domainname"), user_package);
+#endif
make_struct_type(stat_s, nil, nil,
list(dev_s, ino_s, mode_s, nlink_s, uid_s, gid_s,
@@ -1468,6 +1508,12 @@ void sysif_init(void)
list(name_s, passwd_s, gid_s, mem_s, nao),
nil, nil, nil, nil);
#endif
+#if HAVE_UNAME
+ make_struct_type(utsname_s, nil, nil,
+ list(sysname_s, nodename_s, release_s,
+ version_s, machine_s, domainname_s, nao),
+ nil, nil, nil, nil);
+#endif
reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0));
reg_fun(intern(lit("exit"), user_package), func_n1(exit_wrap));
@@ -1731,4 +1777,8 @@ void sysif_init(void)
reg_varl(intern(lit("fnm-extmatch"), user_package), num_fast(FNM_EXTMATCH));
#endif
#endif
+
+#if HAVE_UNAME
+ reg_fun(intern(lit("uname"), user_package), func_n0(uname_wrap));
+#endif
}