SDL_getenv.c File Reference
`#include "../SDL_internal.h"`
`#include "SDL_stdinc.h"`
Include dependency graph for SDL_getenv.c:

Go to the source code of this file.

## Functions

int | SDL_setenv (const char *name, const char *value, int overwrite)
char * | SDL_getenv (const char *name)

## Variables

static char ** | SDL_env = (char **) 0

## Function Documentation

## SDL_getenv()

char* SDL_getenv | ( | const char * | name | ) |

Definition at line 219 of file SDL_getenv.c.

References i, main, NULL, SDL_setenv(), SDL_strcmp, SDL_strlen, and SDL_strncmp.

Referenced by SDL_setenv().

{
int len, i;
char *value;
/* Input validation */
if (!name || SDL_strlen(name)==0) {
return NULL;
}
value = (char *) 0;
if (SDL_env) {
len = SDL_strlen(name);
for (i = 0; SDL_env[i] && !value; ++i) {
if ((SDL_strncmp(SDL_env[i], name, len) == 0) &&
(SDL_env[i][len] == '=')) {
value = &SDL_env[i][len + 1];
}
}
}
return value;
}
SDL_strncmp
#define SDL_strncmp
Definition: SDL_dynapi_overrides.h:418
SDL_env
static char ** SDL_env
Definition: SDL_getenv.c:108
len
GLenum GLsizei len
Definition: SDL_opengl_glext.h:2926
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
i
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)
Definition: SDL_x11sym.h:50
NULL
#define NULL
Definition: begin_code.h:164
SDL_strlen
#define SDL_strlen
Definition: SDL_dynapi_overrides.h:393

## SDL_setenv()

int SDL_setenv | ( | const char * | name,
|  | const char * | value,
|  | int | overwrite
| ) |  |

Definition at line 110 of file SDL_getenv.c.

References Android_JNI_GetManifestEnvironmentVariables(), i, NULL, SDL_free, SDL_getenv(), SDL_malloc, SDL_realloc, SDL_snprintf, SDL_strchr, SDL_strlen, and SDL_strncmp.

Referenced by SDL_getenv().

{
int added;
int len, i;
char **new_env;
char *new_variable;
/* Input validation */
if (!name || SDL_strlen(name) == 0 || SDL_strchr(name, '=') != NULL || !value) {
return (-1);
}
/* See if it already exists */
if (!overwrite && SDL_getenv(name)) {
return 0;
}
/* Allocate memory for the variable */
len = SDL_strlen(name) + SDL_strlen(value) + 2;
new_variable = (char *) SDL_malloc(len);
if (!new_variable) {
return (-1);
}
SDL_snprintf(new_variable, len, "%s=%s", name, value);
value = new_variable + SDL_strlen(name) + 1;
name = new_variable;
/* Actually put it into the environment */
added = 0;
i = 0;
if (SDL_env) {
/* Check to see if it's already there... */
len = (value - name);
for (; SDL_env[i]; ++i) {
if (SDL_strncmp(SDL_env[i], name, len) == 0) {
break;
}
}
/* If we found it, just replace the entry */
if (SDL_env[i]) {
SDL_free(SDL_env[i]);
SDL_env[i] = new_variable;
added = 1;
}
}
/* Didn't find it in the environment, expand and add */
if (!added) {
new_env = SDL_realloc(SDL_env, (i + 2) * sizeof(char *));
if (new_env) {
SDL_env = new_env;
SDL_env[i++] = new_variable;
SDL_env[i++] = (char *) 0;
added = 1;
} else {
SDL_free(new_variable);
}
}
return (added ? 0 : -1);
}
SDL_getenv
char * SDL_getenv(const char *name)
Definition: SDL_getenv.c:219
SDL_realloc
#define SDL_realloc
Definition: SDL_dynapi_overrides.h:376
SDL_strncmp
#define SDL_strncmp
Definition: SDL_dynapi_overrides.h:418
SDL_env
static char ** SDL_env
Definition: SDL_getenv.c:108
len
GLenum GLsizei len
Definition: SDL_opengl_glext.h:2926
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_strchr
#define SDL_strchr
Definition: SDL_dynapi_overrides.h:401
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
i
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)
Definition: SDL_x11sym.h:50
NULL
#define NULL
Definition: begin_code.h:164
SDL_strlen
#define SDL_strlen
Definition: SDL_dynapi_overrides.h:393
SDL_snprintf
#define SDL_snprintf
Definition: SDL_dynapi_overrides.h:40
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:374

## Variable Documentation

## SDL_env

char** SDL_env = (char **) 0

static

Definition at line 108 of file SDL_getenv.c.