From d72054aa270d6f3d539e830ef9892138a255872a Mon Sep 17 00:00:00 2001 From: rsc Date: Fri, 23 Apr 2004 03:50:19 +0000 Subject: add this --- src/lib9/mkfile | 1 + src/lib9/sysname.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/lib9/sysname.c diff --git a/src/lib9/mkfile b/src/lib9/mkfile index bdc8841f..6a3b1fca 100644 --- a/src/lib9/mkfile +++ b/src/lib9/mkfile @@ -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 new file mode 100644 index 00000000..775b6094 --- /dev/null +++ b/src/lib9/sysname.c @@ -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"; +} -- cgit v1.2.3