23 #include "SDL_stdinc.h"
25 #if !defined(SDL_setenv) && defined(__WIN32__)
26 #include "../core/windows/SDL_windows.h"
28 static char *SDL_envmem =
NULL;
29 static size_t SDL_envmemlen = 0;
34 #if defined(HAVE_SETENV)
38 return setenv(name, value, overwrite);
40 #elif defined(__WIN32__)
46 const size_t len = GetEnvironmentVariableA(name, &ch,
sizeof (ch));
51 if (!SetEnvironmentVariableA(name, *value ? value :
NULL)) {
57 #elif (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
59 SDL_setenv(
const char *name,
const char *value,
int overwrite)
64 if (getenv(name) !=
NULL) {
80 return putenv(new_variable);
85 SDL_setenv(
const char *name,
const char *value,
int overwrite)
93 if (!name || !value) {
118 len = (value -
name);
119 for (; SDL_env[
i]; ++
i) {
127 SDL_env[
i] = new_variable;
134 new_env =
SDL_realloc(SDL_env, (i + 2) *
sizeof(
char *));
137 SDL_env[i++] = new_variable;
138 SDL_env[i++] = (
char *) 0;
144 return (added ? 0 : -1);
149 #if defined(HAVE_GETENV)
155 #elif defined(__WIN32__)
162 GetEnvironmentVariableA(name, SDL_envmem, (
DWORD) SDL_envmemlen);
163 if (bufferlen == 0) {
166 if (bufferlen > SDL_envmemlen) {
167 char *newmem = (
char *)
SDL_realloc(SDL_envmem, bufferlen);
168 if (newmem ==
NULL) {
172 SDL_envmemlen = bufferlen;
173 GetEnvironmentVariableA(name, SDL_envmem, (
DWORD) SDL_envmemlen);
187 for (i = 0; SDL_env[
i] && !
value; ++
i) {
189 (SDL_env[i][len] ==
'=')) {
190 value = &SDL_env[
i][len + 1];
203 main(
int argc,
char *argv[])
207 printf(
"Checking for non-existent variable... ");
214 printf(
"Setting FIRST=VALUE1 in the environment... ");
221 printf(
"Getting FIRST from the environment... ");
224 if (value && (
SDL_strcmp(value,
"VALUE1") == 0)) {
229 printf(
"Setting SECOND=VALUE2 in the environment... ");
236 printf(
"Getting SECOND from the environment... ");
239 if (value && (
SDL_strcmp(value,
"VALUE2") == 0)) {
244 printf(
"Setting FIRST=NOVALUE in the environment... ");
251 printf(
"Getting FIRST from the environment... ");
254 if (value && (
SDL_strcmp(value,
"NOVALUE") == 0)) {
259 printf(
"Checking for non-existent variable... ");
int main(int argc, char **argv)
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size)
DECLSPEC void SDLCALL SDL_free(void *mem)
EGLImageKHR EGLint * name
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2)
DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen)
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
EGLSurface EGLint void ** value
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
DECLSPEC char *SDLCALL SDL_getenv(const char *name)
DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite)