Merge pull request #308 from AxisRay/master
Bugfix:function setenv() and unsetenv() are invalid on windows AND no variable prefix set for WIN32 in CMakeLists
This commit is contained in:
commit
be1b897617
2 changed files with 13 additions and 9 deletions
|
@ -177,6 +177,7 @@ IF(WIN32)
|
||||||
GET_CURRENT_YEAR(CURRENT_YEAR)
|
GET_CURRENT_YEAR(CURRENT_YEAR)
|
||||||
MESSAGE("Year for copyright is " ${CURRENT_YEAR})
|
MESSAGE("Year for copyright is " ${CURRENT_YEAR})
|
||||||
|
|
||||||
|
SET(prefix ${CMAKE_INSTALL_PREFIX})
|
||||||
SET(RC_COMMENT "${PACKAGE_NAME} library")
|
SET(RC_COMMENT "${PACKAGE_NAME} library")
|
||||||
SET(RC_INTERNAL_NAME "${PACKAGE_NAME} ${WIN32_MODE}")
|
SET(RC_INTERNAL_NAME "${PACKAGE_NAME} ${WIN32_MODE}")
|
||||||
SET(RC_ORIGINAL_NAME ${PACKAGE_NAME}.dll)
|
SET(RC_ORIGINAL_NAME ${PACKAGE_NAME}.dll)
|
||||||
|
|
|
@ -34,21 +34,24 @@
|
||||||
// Handle platform specific includes
|
// Handle platform specific includes
|
||||||
#include "contrib/windows.h"
|
#include "contrib/windows.h"
|
||||||
|
|
||||||
|
//There is no setenv()and unsetenv() in windows,but we can use putenv() instead.
|
||||||
int setenv(const char *name, const char *value, int overwrite)
|
int setenv(const char *name, const char *value, int overwrite)
|
||||||
{
|
{
|
||||||
int exists = GetEnvironmentVariableA(name, NULL, 0);
|
char* env = getenv(name);
|
||||||
if ((exists && overwrite) || (!exists)) {
|
if ((env && overwrite) || (!env)) {
|
||||||
if (!SetEnvironmentVariableA(name, value)) {
|
char* str[32];
|
||||||
// Set errno here correctly
|
strcpy(str,name);
|
||||||
return -1;
|
strcat(str,"=");
|
||||||
|
strcat(str,value);
|
||||||
|
return putenv(str);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// Exists and overwrite is 0.
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void unsetenv(const char *name)
|
void unsetenv(const char *name)
|
||||||
{
|
{
|
||||||
SetEnvironmentVariableA(name, NULL);
|
char* str[32];
|
||||||
|
strcpy(str,name);
|
||||||
|
strcat(str,"=");
|
||||||
|
putenv(str);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue