Moved mch_get_pid and renamed it to os_get_pid

This commit is contained in:
Stefan Hoffmann
2014-04-04 19:53:43 +02:00
committed by Thiago de Arruda
parent f545afaed0
commit a8013f2bb1
9 changed files with 33 additions and 13 deletions

View File

@@ -9872,7 +9872,7 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv)
*/
static void f_getpid(typval_T *argvars, typval_T *rettv)
{
rettv->vval.v_number = mch_get_pid();
rettv->vval.v_number = os_get_pid();
}
/*

View File

@@ -5730,7 +5730,7 @@ vim_tempname (
* unlikely that it already exists it will be faster,
* otherwise it doesn't matter. The use of mkdir() avoids any
* security problems because of the predictable number. */
nr = (mch_get_pid() + (long)time(NULL)) % 1000000L;
nr = (os_get_pid() + (long)time(NULL)) % 1000000L;
itmplen = STRLEN(itmp);
/* Try up to 10000 different values until we find a name that

View File

@@ -347,7 +347,7 @@ int ml_open(buf_T *buf)
b0p->b0_uname[B0_UNAME_SIZE - 1] = NUL;
mch_get_host_name(b0p->b0_hname, B0_HNAME_SIZE);
b0p->b0_hname[B0_HNAME_SIZE - 1] = NUL;
long_to_char(mch_get_pid(), b0p->b0_pid);
long_to_char(os_get_pid(), b0p->b0_pid);
if (*buf->b_p_key != NUL)
ml_set_b0_crypt(buf, b0p);
}

View File

@@ -50,3 +50,13 @@ char *os_getenvname_at_index(size_t index)
# endif
}
long os_get_pid()
{
#ifdef _WIN32
return (long)GetCurrentProcessId();
#else
return (long)getpid();
#endif
}

View File

@@ -82,6 +82,11 @@ long_u os_total_mem(int special);
const char *os_getenv(const char *name);
int os_setenv(const char *name, const char *value, int overwrite);
char *os_getenvname_at_index(size_t index);
/// Get the process ID of the Neovim process.
///
/// @return the process ID.
long os_get_pid(void);
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);

View File

@@ -424,14 +424,6 @@ void mch_get_host_name(char_u *s, int len)
}
#endif /* HAVE_SYS_UTSNAME_H */
/*
* return process ID
*/
long mch_get_pid()
{
return (long)getpid();
}
#if defined(USE_FNAME_CASE) || defined(PROTO)
/*
* Set the case of the file name, if it already exists. This will cause the

View File

@@ -20,7 +20,6 @@ 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);
long mch_get_pid(void);
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);

View File

@@ -2605,7 +2605,7 @@ static char_u *get_mef_name(void)
/* Keep trying until the name doesn't exist yet. */
for (;; ) {
if (start == -1)
start = mch_get_pid();
start = os_get_pid();
else
off += 19;

View File

@@ -8,6 +8,7 @@ ffi.cdef [[
const char *os_getenv(const char *name);
int os_setenv(const char *name, const char *value, int override);
char *os_getenvname_at_index(size_t index);
long os_get_pid(void);
]]
NULL = ffi.cast 'void*', 0
@@ -90,3 +91,16 @@ describe 'env function', ->
maxuint64 = ffi.new 'size_t', 18446744073709000000
eq NULL, env.os_getenvname_at_index maxuint64
describe 'os_get_pid', ->
it 'returns the process ID', ->
stat_file = io.open '/proc/self/stat'
if stat_file
stat_str = stat_file\read '*l'
stat_file\close!
pid = tonumber (stat_str\match '%d+')
eq pid, tonumber env.os_get_pid!
else
-- /proc is not avaliable on all systems, test if pid is nonzero.
eq true, (env.os_get_pid! > 0)