yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org> |
| 3 | * |
| 4 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. |
| 5 | */ |
| 6 | |
| 7 | #include <string.h> |
| 8 | #include <unistd.h> |
| 9 | #include <sys/utsname.h> |
| 10 | #include <errno.h> |
| 11 | |
| 12 | |
| 13 | |
| 14 | int |
| 15 | gethostname(char *name, size_t len) |
| 16 | { |
| 17 | struct utsname uts; |
| 18 | |
| 19 | if (name == NULL) { |
| 20 | __set_errno(EINVAL); |
| 21 | return -1; |
| 22 | } |
| 23 | |
| 24 | if (uname(&uts) == -1) return -1; |
| 25 | |
| 26 | if (strlen(uts.nodename)+1 > len) { |
| 27 | __set_errno(EINVAL); |
| 28 | return -1; |
| 29 | } |
| 30 | strcpy(name, uts.nodename); |
| 31 | return 0; |
| 32 | } |
| 33 | libc_hidden_def(gethostname) |