tadd this - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit d72054aa270d6f3d539e830ef9892138a255872a
parent 49fda441d2d22ec646d02a5159e7f52ab457b314
Author: rsc 
Date:   Fri, 23 Apr 2004 03:50:19 +0000

add this

Diffstat:
  M src/lib9/mkfile                     |       1 +
  A src/lib9/sysname.c                  |      23 +++++++++++++++++++++++

2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/lib9/mkfile b/src/lib9/mkfile
t@@ -139,6 +139,7 @@ LIB9OFILES=\
         sleep.$O\
         strecpy.$O\
         sysfatal.$O\
+        sysname.$O\
         tas-$OBJTYPE.$O\
         time.$O\
         tokenize.$O\
diff --git a/src/lib9/sysname.c b/src/lib9/sysname.c
t@@ -0,0 +1,23 @@
+#include 
+#include 
+
+char*
+sysname(void)
+{
+        char buf[300], *p, *q;
+
+        if((q = getenv("sysname")) == nil){
+                if(gethostname(buf, sizeof buf) < 0)
+                        goto err;
+                buf[sizeof buf-1] = 0;
+                q = strdup(buf);
+                if(q == nil)
+                        goto err;
+        }
+        if((p = strchr(q, '.')) != nil)
+                *p = 0;
+        return q;
+
+err:
+        return "gnot";
+}