src/stdlib/SDL_getenv.c
changeset 1472 4aac8563c296
parent 1456 84de7511f79f
child 1662 782fd950bd46
child 1895 c121d94672cb
child 3975 e85e65aec22f
equal deleted inserted replaced
1471:9fb0eee04dd9 1472:4aac8563c296
    67 /* Retrieve a variable named "name" from the environment */
    67 /* Retrieve a variable named "name" from the environment */
    68 char *SDL_getenv(const char *name)
    68 char *SDL_getenv(const char *name)
    69 {
    69 {
    70 	size_t bufferlen;
    70 	size_t bufferlen;
    71 
    71 
    72 	bufferlen = GetEnvironmentVariable(name, SDL_envmem, SDL_envmemlen);
    72 	bufferlen = GetEnvironmentVariable(name, SDL_envmem, (DWORD)SDL_envmemlen);
    73 	if ( bufferlen == 0 ) {
    73 	if ( bufferlen == 0 ) {
    74 		return NULL;
    74 		return NULL;
    75 	}
    75 	}
    76 	if ( bufferlen > SDL_envmemlen ) {
    76 	if ( bufferlen > SDL_envmemlen ) {
    77 		char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
    77 		char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
    78 		if ( newmem == NULL ) {
    78 		if ( newmem == NULL ) {
    79 			return NULL;
    79 			return NULL;
    80 		}
    80 		}
    81 		SDL_envmem = newmem;
    81 		SDL_envmem = newmem;
    82 		SDL_envmemlen = bufferlen;
    82 		SDL_envmemlen = bufferlen;
    83 		GetEnvironmentVariable(name, SDL_envmem, SDL_envmemlen);
    83 		GetEnvironmentVariable(name, SDL_envmem, (DWORD)SDL_envmemlen);
    84 	}
    84 	}
    85 	return SDL_envmem;
    85 	return SDL_envmem;
    86 }
    86 }
    87 
    87 
    88 #else /* roll our own */
    88 #else /* roll our own */