summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/gethstnm.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/sysdeps/linux/common/gethstnm.c')
-rw-r--r--libc/sysdeps/linux/common/gethstnm.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/common/gethstnm.c b/libc/sysdeps/linux/common/gethstnm.c
new file mode 100644
index 000000000..0728f65a4
--- /dev/null
+++ b/libc/sysdeps/linux/common/gethstnm.c
@@ -0,0 +1,24 @@
+#include <string.h>
+#include <unistd.h>
+#include <sys/utsname.h>
+#include <errno.h>
+
+int
+gethostname(char *name, size_t len)
+{
+ struct utsname uts;
+
+ if (name == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (uname(&uts) == -1) return -1;
+
+ if (strlen(uts.nodename)+1 > len) {
+ errno = EINVAL;
+ return -1;
+ }
+ strcpy(name, uts.nodename);
+ return 0;
+}