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)
64 const size_t len = GetEnvironmentVariableA(name, &ch,
sizeof (ch));
69 if (!SetEnvironmentVariableA(name, *value ? value :
NULL)) {
75 #elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV)) 77 SDL_setenv(
const char *name,
const char *value,
int overwrite)
87 if (getenv(name) !=
NULL) {
103 return putenv(new_variable);
108 SDL_setenv(
const char *name,
const char *value,
int overwrite)
141 len = (value -
name);
142 for (; SDL_env[
i]; ++
i) {
150 SDL_env[
i] = new_variable;
157 new_env =
SDL_realloc(SDL_env, (i + 2) *
sizeof(
char *));
160 SDL_env[i++] = new_variable;
161 SDL_env[i++] = (
char *) 0;
167 return (added ? 0 : -1);
172 #if defined(HAVE_GETENV) 183 #elif defined(__WIN32__) 195 GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
196 if (bufferlen == 0) {
199 if (bufferlen > SDL_envmemlen) {
200 char *newmem = (
char *)
SDL_realloc(SDL_envmem, bufferlen);
201 if (newmem ==
NULL) {
205 SDL_envmemlen = bufferlen;
206 GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
225 for (i = 0; SDL_env[
i] && !
value; ++
i) {
227 (SDL_env[i][len] ==
'=')) {
228 value = &SDL_env[
i][len + 1];
241 main(
int argc,
char *argv[])
245 printf(
"Checking for non-existent variable... ");
252 printf(
"Setting FIRST=VALUE1 in the environment... ");
259 printf(
"Getting FIRST from the environment... ");
262 if (value && (
SDL_strcmp(value,
"VALUE1") == 0)) {
267 printf(
"Setting SECOND=VALUE2 in the environment... ");
274 printf(
"Getting SECOND from the environment... ");
277 if (value && (
SDL_strcmp(value,
"VALUE2") == 0)) {
282 printf(
"Setting FIRST=NOVALUE in the environment... ");
289 printf(
"Getting FIRST from the environment... ");
292 if (value && (
SDL_strcmp(value,
"NOVALUE") == 0)) {
297 printf(
"Checking for non-existent variable... ");
char * SDL_getenv(const char *name)
GLuint const GLchar * name
GLsizei const GLfloat * value
int SDL_setenv(const char *name, const char *value, int overwrite)
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)