bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1 | /* gethostname.c: minimal substitute for missing gethostname() function |
| 2 | * created 2000-Mar-02 jmk |
| 3 | * requires SVR4 uname() and -lc |
| 4 | * |
| 5 | * by Jim Knoble <jmknoble@pobox.com> |
| 6 | * Copyright ? 2000 Jim Knoble |
| 7 | * |
| 8 | * Permission to use, copy, modify, distribute, and sell this software |
| 9 | * and its documentation for any purpose is hereby granted without fee, |
| 10 | * provided that the above copyright notice appear in all copies and |
| 11 | * that both that copyright notice and this permission notice appear in |
| 12 | * supporting documentation. |
| 13 | * |
| 14 | * This software is provided "as is", without warranty of any kind, |
| 15 | * express or implied, including but not limited to the warranties of |
| 16 | * merchantability, fitness for a particular purpose and |
| 17 | * noninfringement. In no event shall the author(s) be liable for any |
| 18 | * claim, damages or other liability, whether in an action of contract, |
| 19 | * tort or otherwise, arising from, out of or in connection with the |
| 20 | * software or the use or other dealings in the software. |
| 21 | */ |
| 22 | |
| 23 | #include <string.h> |
| 24 | #include <sys/utsname.h> |
| 25 | |
| 26 | int gethostname(char *name, size_t len) |
| 27 | { |
| 28 | struct utsname u; |
| 29 | int status = uname(&u); |
| 30 | if (-1 != status) { |
| 31 | strncpy(name, u.nodename, len); |
| 32 | name[len - 1] = '\0'; |
| 33 | } |
| 34 | return(status); |
| 35 | } |
| 36 | |