cache answer
This commit is contained in:
parent
a1d42887d6
commit
70723aae3c
1 changed files with 20 additions and 13 deletions
|
|
@ -4,20 +4,27 @@
|
||||||
char*
|
char*
|
||||||
sysname(void)
|
sysname(void)
|
||||||
{
|
{
|
||||||
char buf[300], *p, *q;
|
static char buf[512];
|
||||||
|
char *p, *q;
|
||||||
|
|
||||||
if((q = getenv("sysname")) == nil){
|
if(buf[0])
|
||||||
if(gethostname(buf, sizeof buf) < 0)
|
return buf;
|
||||||
goto err;
|
|
||||||
buf[sizeof buf-1] = 0;
|
if((q = getenv("sysname")) != nil && q[0] != 0){
|
||||||
q = strdup(buf);
|
utfecpy(buf, buf+sizeof buf, q);
|
||||||
if(q == nil)
|
free(q);
|
||||||
goto err;
|
return buf;
|
||||||
}
|
}
|
||||||
if((p = strchr(q, '.')) != nil)
|
if(q)
|
||||||
*p = 0;
|
free(q);
|
||||||
return q;
|
|
||||||
|
|
||||||
err:
|
if(gethostname(buf, sizeof buf) >= 0){
|
||||||
return "gnot";
|
buf[sizeof buf-1] = 0;
|
||||||
|
if((p = strchr(buf, '.')) != nil)
|
||||||
|
*p = 0;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(buf, "gnot");
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue