diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib9/mkfile | 1 | ||||
-rw-r--r-- | src/lib9/sysname.c | 23 |
2 files changed, 24 insertions, 0 deletions
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 <u.h> +#include <libc.h> + +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"; +} |