mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
Addresses #1531 Reimplemented setenv, unsetenv correctly
git-svn-id: file:///svn/toku/tokudb@9974 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
04fe238cc4
commit
a8fd238d7e
1 changed files with 13 additions and 21 deletions
|
@ -1,25 +1,22 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <toku_stdlib.h>
|
#include <toku_stdlib.h>
|
||||||
|
#include "toku_portability.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
setenv(const char *name, const char *value, int overwrite) {
|
setenv(const char *name, const char *value, int overwrite) {
|
||||||
char buf[2]; //Need a dummy buffer
|
char * current = getenv(name);
|
||||||
BOOL exists = TRUE;
|
BOOL exists = current!=NULL;
|
||||||
int r = GetEnvironmentVariable(name, buf, sizeof(buf));
|
|
||||||
if (r==0) {
|
int r;
|
||||||
r = GetLastError();
|
|
||||||
if (r==ERROR_ENVVAR_NOT_FOUND) exists = FALSE;
|
|
||||||
else {
|
|
||||||
errno = r;
|
|
||||||
r = -1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (overwrite || !exists) {
|
if (overwrite || !exists) {
|
||||||
r = SetEnvironmentVariable(name, value);
|
char setstring[sizeof("=") + strlen(name) + strlen(value)];
|
||||||
if (r==0) {
|
int bytes = snprintf(setstring, sizeof(setstring), "%s=%s", name, value);
|
||||||
|
assert(bytes>=0);
|
||||||
|
assert((size_t)bytes < sizeof(setstring));
|
||||||
|
r = _putenv(setstring);
|
||||||
|
if (r==-1) {
|
||||||
errno = GetLastError();
|
errno = GetLastError();
|
||||||
r = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +27,7 @@ cleanup:
|
||||||
|
|
||||||
int
|
int
|
||||||
unsetenv(const char *name) {
|
unsetenv(const char *name) {
|
||||||
int r = SetEnvironmentVariable(name, NULL);
|
int r = setenv(name, "", 1);
|
||||||
if (r==0) { //0 is failure
|
|
||||||
r = -1;
|
|
||||||
errno = GetLastError();
|
|
||||||
}
|
|
||||||
else r = 0;
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue