sysname.c (420B)
1 #include <u.h> 2 #include <libc.h> 3 4 char* 5 sysname(void) 6 { 7 static char buf[512]; 8 char *p, *q; 9 10 if(buf[0]) 11 return buf; 12 13 if((q = getenv("sysname")) != nil && q[0] != 0){ 14 utfecpy(buf, buf+sizeof buf, q); 15 free(q); 16 return buf; 17 } 18 if(q) 19 free(q); 20 21 if(gethostname(buf, sizeof buf) >= 0){ 22 buf[sizeof buf-1] = 0; 23 if((p = strchr(buf, '.')) != nil) 24 *p = 0; 25 return buf; 26 } 27 28 strcpy(buf, "gnot"); 29 return buf; 30 }