mariadb/windows/env.c
Yoni Fogel 049c7625a3 Addresses #1765 Merge [12079] into main (pthreads-win32 for windows)
git-svn-id: file:///svn/toku/tokudb@12081 c7de825b-a66e-492c-adef-691d508d4ae1
2013-04-16 23:57:53 -04:00

33 lines
752 B
C

#include <toku_portability.h>
#include <windows.h>
#include <toku_stdlib.h>
#include <assert.h>
int
setenv(const char *name, const char *value, int overwrite) {
char * current = getenv(name);
BOOL exists = current!=NULL;
int r;
if (overwrite || !exists) {
char setstring[sizeof("=") + strlen(name) + strlen(value)];
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();
goto cleanup;
}
}
r = 0;
cleanup:
return r;
}
int
unsetenv(const char *name) {
int r = setenv(name, "", 1);
return r;
}