plan9port/src/lib9/sysname.c

31 lines
420 B
C
Raw Normal View History

2004-04-23 03:50:19 +00:00
#include <u.h>
#include <libc.h>
char*
sysname(void)
{
2005-01-04 22:19:25 +00:00
static char buf[512];
char *p, *q;
2004-04-23 03:50:19 +00:00
2005-01-04 22:19:25 +00:00
if(buf[0])
return buf;
if((q = getenv("sysname")) != nil && q[0] != 0){
utfecpy(buf, buf+sizeof buf, q);
free(q);
return buf;
}
if(q)
free(q);
if(gethostname(buf, sizeof buf) >= 0){
2004-04-23 03:50:19 +00:00
buf[sizeof buf-1] = 0;
2005-01-04 22:19:25 +00:00
if((p = strchr(buf, '.')) != nil)
*p = 0;
return buf;
2004-04-23 03:50:19 +00:00
}
2005-01-04 22:19:25 +00:00
strcpy(buf, "gnot");
return buf;
2004-04-23 03:50:19 +00:00
}