aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/os')
-rw-r--r--src/os/env.c22
-rw-r--r--src/os/os.h7
2 files changed, 29 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
+}
+
diff --git a/src/os/os.h b/src/os/os.h
index 1e874c29a5..8456f87473 100644
--- a/src/os/os.h
+++ b/src/os/os.h
@@ -87,6 +87,13 @@ char *os_getenvname_at_index(size_t index);
///
/// @return the process ID.
long os_get_pid(void);
+
+/// Get the hostname of the machine runing Neovim.
+///
+/// @param hostname Buffer to store the hostname.
+/// @param len Length of `hostname`.
+void os_get_hostname(char *hostname, size_t len);
+
int os_get_usernames(garray_T *usernames);
int os_get_user_name(char *s, size_t len);
int os_get_uname(uid_t uid, char *s, size_t len);