diff options
author | rsc <devnull@localhost> | 2005-01-04 22:19:25 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-01-04 22:19:25 +0000 |
commit | 70723aae3c508956008f10d0e98a5bb0604c4975 (patch) | |
tree | f4944dfefaa775a4ee7f42b851b3797a18aaad06 /src | |
parent | a1d42887d63ed853e07242d76b38614ad4eb2c76 (diff) | |
download | plan9port-70723aae3c508956008f10d0e98a5bb0604c4975.tar.gz plan9port-70723aae3c508956008f10d0e98a5bb0604c4975.tar.bz2 plan9port-70723aae3c508956008f10d0e98a5bb0604c4975.zip |
cache answer
Diffstat (limited to 'src')
-rw-r--r-- | src/lib9/sysname.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/lib9/sysname.c b/src/lib9/sysname.c index 775b6094..2060b986 100644 --- a/src/lib9/sysname.c +++ b/src/lib9/sysname.c @@ -4,20 +4,27 @@ char* sysname(void) { - char buf[300], *p, *q; + static char buf[512]; + char *p, *q; - if((q = getenv("sysname")) == nil){ - if(gethostname(buf, sizeof buf) < 0) - goto err; + 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){ buf[sizeof buf-1] = 0; - q = strdup(buf); - if(q == nil) - goto err; + if((p = strchr(buf, '.')) != nil) + *p = 0; + return buf; } - if((p = strchr(q, '.')) != nil) - *p = 0; - return q; -err: - return "gnot"; + strcpy(buf, "gnot"); + return buf; } |