rsc | d72054a | 2004-04-23 03:50:19 +0000 | [diff] [blame] | 1 | #include <u.h> |
| 2 | #include <libc.h> |
| 3 | |
| 4 | char* |
| 5 | sysname(void) |
| 6 | { |
rsc | 70723aa | 2005-01-04 22:19:25 +0000 | [diff] [blame] | 7 | static char buf[512]; |
| 8 | char *p, *q; |
rsc | d72054a | 2004-04-23 03:50:19 +0000 | [diff] [blame] | 9 | |
rsc | 70723aa | 2005-01-04 22:19:25 +0000 | [diff] [blame] | 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; |
rsc | d72054a | 2004-04-23 03:50:19 +0000 | [diff] [blame] | 17 | } |
rsc | 70723aa | 2005-01-04 22:19:25 +0000 | [diff] [blame] | 18 | if(q) |
| 19 | free(q); |
rsc | d72054a | 2004-04-23 03:50:19 +0000 | [diff] [blame] | 20 | |
rsc | 70723aa | 2005-01-04 22:19:25 +0000 | [diff] [blame] | 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; |
rsc | d72054a | 2004-04-23 03:50:19 +0000 | [diff] [blame] | 30 | } |