mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
Moved mch_get_pid and renamed it to os_get_pid
This commit is contained in:

committed by
Thiago de Arruda

parent
f545afaed0
commit
a8013f2bb1
@@ -9872,7 +9872,7 @@ static void f_getmatches(typval_T *argvars, typval_T *rettv)
|
|||||||
*/
|
*/
|
||||||
static void f_getpid(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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -5730,7 +5730,7 @@ vim_tempname (
|
|||||||
* unlikely that it already exists it will be faster,
|
* unlikely that it already exists it will be faster,
|
||||||
* otherwise it doesn't matter. The use of mkdir() avoids any
|
* otherwise it doesn't matter. The use of mkdir() avoids any
|
||||||
* security problems because of the predictable number. */
|
* 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);
|
itmplen = STRLEN(itmp);
|
||||||
|
|
||||||
/* Try up to 10000 different values until we find a name that
|
/* Try up to 10000 different values until we find a name that
|
||||||
|
@@ -347,7 +347,7 @@ int ml_open(buf_T *buf)
|
|||||||
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);
|
mch_get_host_name(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(mch_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)
|
||||||
ml_set_b0_crypt(buf, b0p);
|
ml_set_b0_crypt(buf, b0p);
|
||||||
}
|
}
|
||||||
|
10
src/os/env.c
10
src/os/env.c
@@ -50,3 +50,13 @@ char *os_getenvname_at_index(size_t index)
|
|||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long os_get_pid()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
return (long)GetCurrentProcessId();
|
||||||
|
#else
|
||||||
|
return (long)getpid();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -82,6 +82,11 @@ long_u os_total_mem(int special);
|
|||||||
const char *os_getenv(const char *name);
|
const char *os_getenv(const char *name);
|
||||||
int os_setenv(const char *name, const char *value, int overwrite);
|
int os_setenv(const char *name, const char *value, int overwrite);
|
||||||
char *os_getenvname_at_index(size_t index);
|
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_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);
|
||||||
|
@@ -424,14 +424,6 @@ void mch_get_host_name(char_u *s, int len)
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_SYS_UTSNAME_H */
|
#endif /* HAVE_SYS_UTSNAME_H */
|
||||||
|
|
||||||
/*
|
|
||||||
* return process ID
|
|
||||||
*/
|
|
||||||
long mch_get_pid()
|
|
||||||
{
|
|
||||||
return (long)getpid();
|
|
||||||
}
|
|
||||||
|
|
||||||
#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
|
||||||
|
@@ -20,7 +20,6 @@ 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 mch_get_host_name(char_u *s, int len);
|
||||||
long mch_get_pid(void);
|
|
||||||
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);
|
||||||
|
@@ -2605,7 +2605,7 @@ static char_u *get_mef_name(void)
|
|||||||
/* Keep trying until the name doesn't exist yet. */
|
/* Keep trying until the name doesn't exist yet. */
|
||||||
for (;; ) {
|
for (;; ) {
|
||||||
if (start == -1)
|
if (start == -1)
|
||||||
start = mch_get_pid();
|
start = os_get_pid();
|
||||||
else
|
else
|
||||||
off += 19;
|
off += 19;
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ ffi.cdef [[
|
|||||||
const char *os_getenv(const char *name);
|
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);
|
||||||
]]
|
]]
|
||||||
|
|
||||||
NULL = ffi.cast 'void*', 0
|
NULL = ffi.cast 'void*', 0
|
||||||
@@ -90,3 +91,16 @@ describe 'env function', ->
|
|||||||
maxuint64 = ffi.new 'size_t', 18446744073709000000
|
maxuint64 = ffi.new 'size_t', 18446744073709000000
|
||||||
eq NULL, env.os_getenvname_at_index maxuint64
|
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)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user