mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Windows: Implement os_setenv() using _putenv_s()
Windows does not have setenv(), instead the _putenv_s() function is used - added a function check and fatal errors. Implemented os_setenv() for Windows. Vim supports the original putenv() function if no alternative is available. Neovim only supports systems where safer alternatives exist, so the check for putenv() was removed from config/CMakeLists.txt.
This commit is contained in:
parent
f183cc14de
commit
810d31a430
@ -51,7 +51,10 @@ if(JEMALLOC_FOUND)
|
|||||||
set(HAVE_JEMALLOC 1)
|
set(HAVE_JEMALLOC 1)
|
||||||
endif()
|
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(opendir HAVE_OPENDIR)
|
||||||
check_function_exists(readlink HAVE_READLINK)
|
check_function_exists(readlink HAVE_READLINK)
|
||||||
check_function_exists(setenv HAVE_SETENV)
|
check_function_exists(setenv HAVE_SETENV)
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#cmakedefine HAVE_LOCALE_H
|
#cmakedefine HAVE_LOCALE_H
|
||||||
#cmakedefine HAVE_NL_LANGINFO_CODESET
|
#cmakedefine HAVE_NL_LANGINFO_CODESET
|
||||||
#cmakedefine HAVE_NL_MSG_CAT_CNTR
|
#cmakedefine HAVE_NL_MSG_CAT_CNTR
|
||||||
#cmakedefine HAVE_PUTENV
|
#cmakedefine HAVE_PUTENV_S
|
||||||
#cmakedefine HAVE_PWD_H
|
#cmakedefine HAVE_PWD_H
|
||||||
#cmakedefine HAVE_READLINK
|
#cmakedefine HAVE_READLINK
|
||||||
// TODO: add proper cmake check
|
// TODO: add proper cmake check
|
||||||
|
@ -46,7 +46,19 @@ bool os_env_exists(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)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_SETENV
|
||||||
return setenv(name, value, overwrite);
|
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
|
/// Unset environment variable
|
||||||
|
Loading…
Reference in New Issue
Block a user