mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-03 17:24:29 +00:00 
			
		
		
		
	Moved mch_get_host_name and renamed it to os_get_hostanme
This commit is contained in:
		
				
					committed by
					
						
						Thiago de Arruda
					
				
			
			
				
	
			
			
			
						parent
						
							a8013f2bb1
						
					
				
				
					commit
					e76249c813
				
			@@ -10530,11 +10530,11 @@ static void f_hlexists(typval_T *argvars, typval_T *rettv)
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
static void f_hostname(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->v_type = VAR_STRING;
 | 
				
			||||||
  rettv->vval.v_string = vim_strsave(hostname);
 | 
					  rettv->vval.v_string = vim_strsave((char_u *)hostname);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -345,7 +345,7 @@ int ml_open(buf_T *buf)
 | 
				
			|||||||
    set_b0_fname(b0p, buf);
 | 
					    set_b0_fname(b0p, buf);
 | 
				
			||||||
    (void)os_get_user_name((char *)b0p->b0_uname, B0_UNAME_SIZE);
 | 
					    (void)os_get_user_name((char *)b0p->b0_uname, B0_UNAME_SIZE);
 | 
				
			||||||
    b0p->b0_uname[B0_UNAME_SIZE - 1] = NUL;
 | 
					    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;
 | 
					    b0p->b0_hname[B0_HNAME_SIZE - 1] = NUL;
 | 
				
			||||||
    long_to_char(os_get_pid(), b0p->b0_pid);
 | 
					    long_to_char(os_get_pid(), b0p->b0_pid);
 | 
				
			||||||
    if (*buf->b_p_key != NUL)
 | 
					    if (*buf->b_p_key != NUL)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								src/os/env.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/os/env.c
									
									
									
									
									
								
							@@ -9,6 +9,10 @@
 | 
				
			|||||||
#include <crt_externs.h>
 | 
					#include <crt_externs.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef HAVE_SYS_UTSNAME_H
 | 
				
			||||||
 | 
					#include <sys/utsname.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char *os_getenv(const char *name)
 | 
					const char *os_getenv(const char *name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  return getenv(name);
 | 
					  return getenv(name);
 | 
				
			||||||
@@ -60,3 +64,21 @@ long os_get_pid()
 | 
				
			|||||||
#endif
 | 
					#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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -87,6 +87,13 @@ char *os_getenvname_at_index(size_t index);
 | 
				
			|||||||
///
 | 
					///
 | 
				
			||||||
/// @return the process ID.
 | 
					/// @return the process ID.
 | 
				
			||||||
long os_get_pid(void);
 | 
					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_usernames(garray_T *usernames);
 | 
				
			||||||
int os_get_user_name(char *s, size_t len);
 | 
					int os_get_user_name(char *s, size_t len);
 | 
				
			||||||
int os_get_uname(uid_t uid, char *s, size_t len);
 | 
					int os_get_uname(uid_t uid, char *s, size_t len);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -397,33 +397,6 @@ int vim_is_fastterm(char_u *name)
 | 
				
			|||||||
         || STRNICMP(name, "dtterm", 6) == 0;
 | 
					         || 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)
 | 
					#if defined(USE_FNAME_CASE) || defined(PROTO)
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Set the case of the file name, if it already exists.  This will cause the
 | 
					 * Set the case of the file name, if it already exists.  This will cause the
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,6 @@ int use_xterm_mouse(void);
 | 
				
			|||||||
int vim_is_iris(char_u *name);
 | 
					int vim_is_iris(char_u *name);
 | 
				
			||||||
int vim_is_vt300(char_u *name);
 | 
					int vim_is_vt300(char_u *name);
 | 
				
			||||||
int vim_is_fastterm(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 slash_adjust(char_u *p);
 | 
				
			||||||
void fname_case(char_u *name, int len);
 | 
					void fname_case(char_u *name, int len);
 | 
				
			||||||
void mch_copy_sec(char_u *from_file, char_u *to_file);
 | 
					void mch_copy_sec(char_u *from_file, char_u *to_file);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,10 +58,6 @@
 | 
				
			|||||||
# include <sys/stream.h>
 | 
					# include <sys/stream.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef HAVE_SYS_UTSNAME_H
 | 
					 | 
				
			||||||
# include <sys/utsname.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef HAVE_SYS_SYSTEMINFO_H
 | 
					#ifdef HAVE_SYS_SYSTEMINFO_H
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * foolish Sinix <sys/systeminfo.h> uses SYS_NMLN but doesn't include
 | 
					 * foolish Sinix <sys/systeminfo.h> uses SYS_NMLN but doesn't include
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ const char *os_getenv(const char *name);
 | 
				
			|||||||
int os_setenv(const char *name, const char *value, int override);
 | 
					int os_setenv(const char *name, const char *value, int override);
 | 
				
			||||||
char *os_getenvname_at_index(size_t index);
 | 
					char *os_getenvname_at_index(size_t index);
 | 
				
			||||||
long os_get_pid(void);
 | 
					long os_get_pid(void);
 | 
				
			||||||
 | 
					void os_get_hostname(char *hostname, size_t len);
 | 
				
			||||||
]]
 | 
					]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
NULL = ffi.cast 'void*', 0
 | 
					NULL = ffi.cast 'void*', 0
 | 
				
			||||||
@@ -104,3 +105,13 @@ describe 'env function', ->
 | 
				
			|||||||
        -- /proc is not avaliable on all systems, test if pid is nonzero.
 | 
					        -- /proc is not avaliable on all systems, test if pid is nonzero.
 | 
				
			||||||
        eq true, (env.os_get_pid! > 0)
 | 
					        eq true, (env.os_get_pid! > 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe 'os_get_hostname', ->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it 'returns the hostname', ->
 | 
				
			||||||
 | 
					      handle = io.popen 'hostname'
 | 
				
			||||||
 | 
					      hostname = handle\read '*l'
 | 
				
			||||||
 | 
					      handle\close!
 | 
				
			||||||
 | 
					      hostname_buf = cstr 255, ''
 | 
				
			||||||
 | 
					      env.os_get_hostname hostname_buf, 255
 | 
				
			||||||
 | 
					      eq hostname,  (ffi.string hostname_buf)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user