summaryrefslogtreecommitdiffstats
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
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.
-rwxr-xr-xconfigure45
-rw-r--r--sysif.c50
-rw-r--r--txr.138
3 files changed, 133 insertions, 0 deletions
diff --git a/configure b/configure
index e6d402ee..e9d2a192 100755
--- a/configure
+++ b/configure
@@ -2632,6 +2632,51 @@ else
printf "no\n"
fi
+printf "Checking for uname ... "
+
+cat > conftest.c <<!
+#include <sys/utsname.h>
+#include <stdio.h>
+
+int main(void)
+{
+ struct utsname utn;
+ if (uname(&utn) == 0)
+ printf("%s:%s:%s:%s:%s\n", utn.sysname,
+ utn.nodename, utn.release, utn.version,
+ utn.machine);
+ return 0;
+}
+!
+
+if conftest ; then
+ printf "yes\n"
+ printf "#define HAVE_UNAME 1\n" >> $config_h
+else
+ printf "no\n"
+fi
+
+printf "Checking for domainname in struct utsname ... "
+
+cat > conftest.c <<!
+#include <sys/utsname.h>
+#include <stdio.h>
+
+int main(void)
+{
+ struct utsname utn;
+ if (uname(&utn) == 0)
+ printf("%s\n", utn.domainname);
+ return 0;
+}
+!
+
+if conftest ; then
+ printf "yes\n"
+ printf "#define HAVE_UTSNAME_DOMAINNAME 1\n" >> $config_h
+else
+ printf "no\n"
+fi
#
# Dependent variables
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
}
diff --git a/txr.1 b/txr.1
index df6c642d..7c6cbac8 100644
--- a/txr.1
+++ b/txr.1
@@ -40822,6 +40822,44 @@ and the output of
may be used as an argument to
.codn stty .
+.SS* Unix System Identification
+
+.coNP Structure @ utsname
+.synb
+.mets (defstruct utsname nil
+.mets \ \ sysname nodename release
+.mets \ \ version machine domainname)
+.syne
+.desc
+The
+.code utsname
+structure corresponds to the POSIX structure of the same name.
+An instance of this structure is returned by the
+.code uname
+function.
+
+.coNP Function @ uname
+.synb
+.mets (uname)
+.syne
+.desc
+The
+.code uname
+function corresponds to the POSIX
+function of the same name. It returns an instance of the
+.code utsname
+structure. Each slot of the returned structure is
+initialized with a character string that identifies the corresponding attribute
+of the host system.
+
+The host system might not support the reporting of the
+NIS domain name. In this case, the
+.code domainname
+slot of the returned
+.code utsname
+structure will have the value
+.codn nil .
+
.SS* Web Programming Support
.coNP Functions @ url-encode and @ url-decode