diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2015-12-12 22:57:02 -0500 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-12-12 22:57:02 -0500 |
commit | ebdb802bf55a45eb7e4fa59cdb0689e7a3323f86 (patch) | |
tree | 90ca7f70057a79e5bf5370dc29954262c4f35eff | |
parent | f183cc14de40542899f1bad44943695b0ccf0e5c (diff) | |
parent | 810d31a43001e0955a0a3194998afcc9a0ed33ec (diff) | |
download | rneovim-ebdb802bf55a45eb7e4fa59cdb0689e7a3323f86.tar.gz rneovim-ebdb802bf55a45eb7e4fa59cdb0689e7a3323f86.tar.bz2 rneovim-ebdb802bf55a45eb7e4fa59cdb0689e7a3323f86.zip |
Merge pull request #3816 from sethjackson/win-setenv
Windows: Implement os_setenv()
-rw-r--r-- | config/CMakeLists.txt | 5 | ||||
-rw-r--r-- | config/config.h.in | 2 | ||||
-rw-r--r-- | src/nvim/os/env.c | 12 |
3 files changed, 17 insertions, 2 deletions
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index b780291264..3d7660ed58 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -51,7 +51,10 @@ if(JEMALLOC_FOUND) set(HAVE_JEMALLOC 1) endif() -check_function_exists(putenv HAVE_PUTENV) +check_function_exists(_putenv_s HAVE_PUTENV_S) +if(WIN32 AND NOT HAVE_PUTENV_S) + message(SEND_ERROR "_putenv_s() function not found on your system.") +endif() check_function_exists(opendir HAVE_OPENDIR) check_function_exists(readlink HAVE_READLINK) check_function_exists(setenv HAVE_SETENV) diff --git a/config/config.h.in b/config/config.h.in index 7d901180b4..017cb80f2f 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -29,7 +29,7 @@ #cmakedefine HAVE_LOCALE_H #cmakedefine HAVE_NL_LANGINFO_CODESET #cmakedefine HAVE_NL_MSG_CAT_CNTR -#cmakedefine HAVE_PUTENV +#cmakedefine HAVE_PUTENV_S #cmakedefine HAVE_PWD_H #cmakedefine HAVE_READLINK // TODO: add proper cmake check diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 0e052ced55..a791dca39c 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -46,7 +46,19 @@ bool os_env_exists(const char *name) int os_setenv(const char *name, const char *value, int overwrite) FUNC_ATTR_NONNULL_ALL { +#ifdef HAVE_SETENV return setenv(name, value, overwrite); +#elif defined(HAVE_PUTENV_S) + if (!overwrite && os_getenv(name) != NULL) { + return 0; + } + if (_putenv_s(name, value) == 0) { + return 0; + } + return -1; +#else +# error "This system has no implementation available for os_setenv()" +#endif } /// Unset environment variable |