diff options
author | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-05-12 02:25:17 +0200 |
---|---|---|
committer | Eliseo Martínez <eliseomarmol@gmail.com> | 2014-05-15 20:46:01 +0200 |
commit | da51dc9cf202772f60bd2da975dbef257bd9237c (patch) | |
tree | 5c16b93238a153f55634e9323077f30c8133970c /src/nvim/os/env.c | |
parent | ffe61e5ba1721340ca51d56bae3ddaca415fb5bc (diff) | |
download | rneovim-da51dc9cf202772f60bd2da975dbef257bd9237c.tar.gz rneovim-da51dc9cf202772f60bd2da975dbef257bd9237c.tar.bz2 rneovim-da51dc9cf202772f60bd2da975dbef257bd9237c.zip |
Introduce nvim namespace: Move files.
Move files from src/ to src/nvim/.
- src/nvim/ becomes the new root dir for nvim executable sources.
- src/libnvim/ is planned to become root dir of the neovim library.
Diffstat (limited to 'src/nvim/os/env.c')
-rw-r--r-- | src/nvim/os/env.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c new file mode 100644 index 0000000000..e6cdb92ea8 --- /dev/null +++ b/src/nvim/os/env.c @@ -0,0 +1,80 @@ +// env.c -- environment variable access + +#include <uv.h> + +#include "os/os.h" +#include "misc2.h" + +#ifdef HAVE__NSGETENVIRON +#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); +} + +int os_setenv(const char *name, const char *value, int overwrite) +{ + return setenv(name, value, overwrite); +} + +char *os_getenvname_at_index(size_t index) +{ +# if defined(HAVE__NSGETENVIRON) + char **environ = *_NSGetEnviron(); +# elif !defined(__WIN32__) + // Borland C++ 5.2 has this in a header file. + extern char **environ; +# endif + // check if index is inside the environ array + for (size_t i = 0; i < index; i++) { + if (environ[i] == NULL) { + return NULL; + } + } + char *str = environ[index]; + if (str == NULL) { + return NULL; + } + int namesize = 0; + while (str[namesize] != '=' && str[namesize] != NUL) { + namesize++; + } + char *name = (char *)vim_strnsave((char_u *)str, namesize); + return name; +} + + +int64_t os_get_pid() +{ +#ifdef _WIN32 + return (int64_t)GetCurrentProcessId(); +#else + return (int64_t)getpid(); +#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(unknown): 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 +} + |