aboutsummaryrefslogtreecommitdiff
path: root/src/os/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/env.c')
-rw-r--r--src/os/env.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/os/env.c b/src/os/env.c
index 034a4ff3a0..a3053e3350 100644
--- a/src/os/env.c
+++ b/src/os/env.c
@@ -9,6 +9,10 @@
#include <crt_externs.h>
#endif
+#ifdef HAVE_SYS_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+
const char *os_getenv(const char *name)
{
return getenv(name);
@@ -60,3 +64,21 @@ long os_get_pid()
#endif
}
+void os_get_hostname(char *hostname, size_t len)
+{
+#ifdef HAVE_SYS_UTSNAME_H
+ struct utsname vutsname;
+
+ if (uname(&vutsname) < 0) {
+ *hostname = '\0';
+ } else {
+ strncpy(hostname, vutsname.nodename, len - 1);
+ hostname[len - 1] = '\0';
+ }
+#else
+ // TODO: Implement this for windows. See the implementation used in vim:
+ // https://code.google.com/p/vim/source/browse/src/os_win32.c?r=6b69d8dde19e32909f4ee3a6337e6a2ecfbb6f72#2899
+ *hostname = '\0';
+#endif
+}
+