diff options
author | Stefan Hoffmann <stefan991@gmail.com> | 2014-04-04 19:53:43 +0200 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-05 20:19:38 -0300 |
commit | a8013f2bb1b7e62c273f7a7da58653aa82e9c5ca (patch) | |
tree | 11807ea29c41ed7b6ed2769185e5283969e7fe8b | |
parent | f545afaed0304838881930c6a5944f2c6523322e (diff) | |
download | rneovim-a8013f2bb1b7e62c273f7a7da58653aa82e9c5ca.tar.gz rneovim-a8013f2bb1b7e62c273f7a7da58653aa82e9c5ca.tar.bz2 rneovim-a8013f2bb1b7e62c273f7a7da58653aa82e9c5ca.zip |
Moved mch_get_pid and renamed it to os_get_pid
-rw-r--r-- | src/eval.c | 2 | ||||
-rw-r--r-- | src/fileio.c | 2 | ||||
-rw-r--r-- | src/memline.c | 2 | ||||
-rw-r--r-- | src/os/env.c | 10 | ||||
-rw-r--r-- | src/os/os.h | 5 | ||||
-rw-r--r-- | src/os_unix.c | 8 | ||||
-rw-r--r-- | src/os_unix.h | 1 | ||||
-rw-r--r-- | src/quickfix.c | 2 | ||||
-rw-r--r-- | test/unit/os/env.moon | 14 |
9 files changed, 33 insertions, 13 deletions
diff --git a/src/eval.c b/src/eval.c index 59bdfd45cd..7dd578762c 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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(); } /* diff --git a/src/fileio.c b/src/fileio.c index 4de33243b9..b13b7e5517 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -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 diff --git a/src/memline.c b/src/memline.c index 01fa71a985..b9de707f60 100644 --- a/src/memline.c +++ b/src/memline.c @@ -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); } diff --git a/src/os/env.c b/src/os/env.c index 9415b19573..034a4ff3a0 100644 --- a/src/os/env.c +++ b/src/os/env.c @@ -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 +} + diff --git a/src/os/os.h b/src/os/os.h index bc3da1c8ff..1e874c29a5 100644 --- a/src/os/os.h +++ b/src/os/os.h @@ -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); diff --git a/src/os_unix.c b/src/os_unix.c index 7df61f012f..f5bd1006b1 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -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 diff --git a/src/os_unix.h b/src/os_unix.h index ca9d21f0fb..eaa38706ac 100644 --- a/src/os_unix.h +++ b/src/os_unix.h @@ -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); diff --git a/src/quickfix.c b/src/quickfix.c index 05ea75b16f..954f81e72e 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -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; diff --git a/test/unit/os/env.moon b/test/unit/os/env.moon index 1f1692859b..b8405947d9 100644 --- a/test/unit/os/env.moon +++ b/test/unit/os/env.moon @@ -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) + |