aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Hoffmann <stefan991@gmail.com>2014-04-05 13:51:48 +0200
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-05 20:19:38 -0300
commite76249c813192aa082060d024b66f11d95d09b51 (patch)
treeb85521e6135f487f4dd7b7df9d3f4965e37f0246 /src
parenta8013f2bb1b7e62c273f7a7da58653aa82e9c5ca (diff)
downloadrneovim-e76249c813192aa082060d024b66f11d95d09b51.tar.gz
rneovim-e76249c813192aa082060d024b66f11d95d09b51.tar.bz2
rneovim-e76249c813192aa082060d024b66f11d95d09b51.zip
Moved mch_get_host_name and renamed it to os_get_hostanme
Diffstat (limited to 'src')
-rw-r--r--src/eval.c6
-rw-r--r--src/memline.c2
-rw-r--r--src/os/env.c22
-rw-r--r--src/os/os.h7
-rw-r--r--src/os_unix.c27
-rw-r--r--src/os_unix.h1
-rw-r--r--src/os_unixx.h4
7 files changed, 33 insertions, 36 deletions
diff --git a/src/eval.c b/src/eval.c
index 7dd578762c..978e3899ad 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -10530,11 +10530,11 @@ static void f_hlexists(typval_T *argvars, typval_T *rettv)
*/
static void f_hostname(typval_T *argvars, typval_T *rettv)
{
- char_u hostname[256];
+ char hostname[256];
- mch_get_host_name(hostname, 256);
+ os_get_hostname(hostname, 256);
rettv->v_type = VAR_STRING;
- rettv->vval.v_string = vim_strsave(hostname);
+ rettv->vval.v_string = vim_strsave((char_u *)hostname);
}
/*
diff --git a/src/memline.c b/src/memline.c
index b9de707f60..05bc24e277 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -345,7 +345,7 @@ int ml_open(buf_T *buf)
set_b0_fname(b0p, buf);
(void)os_get_user_name((char *)b0p->b0_uname, B0_UNAME_SIZE);
b0p->b0_uname[B0_UNAME_SIZE - 1] = NUL;
- mch_get_host_name(b0p->b0_hname, B0_HNAME_SIZE);
+ os_get_hostname((char *)b0p->b0_hname, B0_HNAME_SIZE);
b0p->b0_hname[B0_HNAME_SIZE - 1] = NUL;
long_to_char(os_get_pid(), b0p->b0_pid);
if (*buf->b_p_key != NUL)
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);
diff --git a/src/os_unix.c b/src/os_unix.c
index f5bd1006b1..e90d52afa5 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -397,33 +397,6 @@ int vim_is_fastterm(char_u *name)
|| STRNICMP(name, "dtterm", 6) == 0;
}
-/*
- * Insert host name is s[len].
- */
-
-#ifdef HAVE_SYS_UTSNAME_H
-void mch_get_host_name(char_u *s, int len)
-{
- struct utsname vutsname;
-
- if (uname(&vutsname) < 0)
- *s = NUL;
- else
- vim_strncpy(s, (char_u *)vutsname.nodename, len - 1);
-}
-#else /* HAVE_SYS_UTSNAME_H */
-
-# ifdef HAVE_SYS_SYSTEMINFO_H
-# define gethostname(nam, len) sysinfo(SI_HOSTNAME, nam, len)
-# endif
-
-void mch_get_host_name(char_u *s, int len)
-{
- gethostname((char *)s, len);
- s[len - 1] = NUL; /* make sure it's terminated */
-}
-#endif /* HAVE_SYS_UTSNAME_H */
-
#if defined(USE_FNAME_CASE) || defined(PROTO)
/*
* Set the case of the file name, if it already exists. This will cause the
diff --git a/src/os_unix.h b/src/os_unix.h
index eaa38706ac..2f592c50af 100644
--- a/src/os_unix.h
+++ b/src/os_unix.h
@@ -19,7 +19,6 @@ int use_xterm_mouse(void);
int vim_is_iris(char_u *name);
int vim_is_vt300(char_u *name);
int vim_is_fastterm(char_u *name);
-void mch_get_host_name(char_u *s, int len);
void slash_adjust(char_u *p);
void fname_case(char_u *name, int len);
void mch_copy_sec(char_u *from_file, char_u *to_file);
diff --git a/src/os_unixx.h b/src/os_unixx.h
index 1c9c8d8bae..576847761b 100644
--- a/src/os_unixx.h
+++ b/src/os_unixx.h
@@ -58,10 +58,6 @@
# include <sys/stream.h>
#endif
-#ifdef HAVE_SYS_UTSNAME_H
-# include <sys/utsname.h>
-#endif
-
#ifdef HAVE_SYS_SYSTEMINFO_H
/*
* foolish Sinix <sys/systeminfo.h> uses SYS_NMLN but doesn't include