22 #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS) 23 #define SDL_DISABLE_ANALYZE_MACROS 1 26 #include "../SDL_internal.h" 28 #if defined(__WIN32__) 29 #include "../core/windows/SDL_windows.h" 34 #if defined(__WIN32__) && (!defined(HAVE_SETENV) || !defined(HAVE_GETENV)) 36 static char *SDL_envmem =
NULL;
37 static size_t SDL_envmemlen = 0;
42 #if defined(HAVE_SETENV) 51 return setenv(name, value, overwrite);
53 #elif defined(__WIN32__) 55 SDL_setenv(
const char *name,
const char *value,
int overwrite)
63 if (GetEnvironmentVariableA(name,
NULL, 0) > 0) {
67 if (!SetEnvironmentVariableA(name, *value ? value :
NULL)) {
73 #elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) 75 SDL_setenv(
const char *name,
const char *value,
int overwrite)
85 if (getenv(name) !=
NULL) {
101 return putenv(new_variable);
106 SDL_setenv(
const char *name,
const char *value,
int overwrite)
139 len = (value -
name);
140 for (; SDL_env[
i]; ++
i) {
148 SDL_env[
i] = new_variable;
155 new_env =
SDL_realloc(SDL_env, (i + 2) *
sizeof(
char *));
158 SDL_env[i++] = new_variable;
159 SDL_env[i++] = (
char *) 0;
165 return (added ? 0 : -1);
170 #if defined(HAVE_GETENV) 181 #elif defined(__WIN32__) 193 GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
194 if (bufferlen == 0) {
197 if (bufferlen > SDL_envmemlen) {
198 char *newmem = (
char *)
SDL_realloc(SDL_envmem, bufferlen);
199 if (newmem ==
NULL) {
203 SDL_envmemlen = bufferlen;
204 GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
223 for (i = 0; SDL_env[
i] && !
value; ++
i) {
225 (SDL_env[i][len] ==
'=')) {
226 value = &SDL_env[
i][len + 1];
239 main(
int argc,
char *argv[])
243 printf(
"Checking for non-existent variable... ");
250 printf(
"Setting FIRST=VALUE1 in the environment... ");
257 printf(
"Getting FIRST from the environment... ");
260 if (value && (
SDL_strcmp(value,
"VALUE1") == 0)) {
265 printf(
"Setting SECOND=VALUE2 in the environment... ");
272 printf(
"Getting SECOND from the environment... ");
275 if (value && (
SDL_strcmp(value,
"VALUE2") == 0)) {
280 printf(
"Setting FIRST=NOVALUE in the environment... ");
287 printf(
"Getting FIRST from the environment... ");
290 if (value && (
SDL_strcmp(value,
"NOVALUE") == 0)) {
295 printf(
"Checking for non-existent variable... ");
char * SDL_getenv(const char *name)
GLuint const GLchar * name
int SDL_setenv(const char *name, const char *value, int overwrite)
GLsizei const GLfloat * value
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)