blob: 3b59e56714fab20571568831e87ab419730dcc06 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
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
14int
15gethostname(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}
33libc_hidden_def(gethostname)