19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_stdinc.h"
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifndef HAVE_GETENV
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__WIN32__) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define WIN32_LEAN_AND_MEAN
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <windows.h>
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Note this isn't thread-safe! */
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char *SDL_envmem = NULL;	/* Ugh, memory leak */
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic size_t SDL_envmemlen = 0;
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Put a variable of the form "name=value" into the environment */
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_putenv(const char *variable)
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	size_t bufferlen;
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char *value;
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	const char *sep;
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sep = SDL_strchr(variable, '=');
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( sep == NULL ) {
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return -1;
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bufferlen = SDL_strlen(variable)+1;
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( bufferlen > SDL_envmemlen ) {
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( newmem == NULL ) {
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			return -1;
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_envmem = newmem;
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_envmemlen = bufferlen;
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	SDL_strlcpy(SDL_envmem, variable, bufferlen);
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	value = SDL_envmem + (sep - variable);
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	*value++ = '\0';
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( !SetEnvironmentVariable(SDL_envmem, *value ? value : NULL) ) {
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return -1;
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return 0;
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Retrieve a variable named "name" from the environment */
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallchar *SDL_getenv(const char *name)
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	size_t bufferlen;
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bufferlen = GetEnvironmentVariable(name, SDL_envmem, (DWORD)SDL_envmemlen);
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( bufferlen == 0 ) {
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return NULL;
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( bufferlen > SDL_envmemlen ) {
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		char *newmem = (char *)SDL_realloc(SDL_envmem, bufferlen);
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( newmem == NULL ) {
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			return NULL;
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_envmem = newmem;
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		SDL_envmemlen = bufferlen;
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		GetEnvironmentVariable(name, SDL_envmem, (DWORD)SDL_envmemlen);
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return SDL_envmem;
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else /* roll our own */
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic char **SDL_env = (char **)0;
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Put a variable of the form "name=value" into the environment */
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_putenv(const char *variable)
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	const char *name, *value;
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int added;
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int len, i;
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char **new_env;
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char *new_variable;
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* A little error checking */
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ! variable ) {
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(-1);
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	name = variable;
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	for ( value=variable; *value && (*value != '='); ++value ) {
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Keep looking for '=' */ ;
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( *value ) {
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		++value;
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(-1);
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Allocate memory for the variable */
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	new_variable = SDL_strdup(variable);
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ! new_variable ) {
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		return(-1);
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Actually put it into the environment */
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	added = 0;
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	i = 0;
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_env ) {
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* Check to see if it's already there... */
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		len = (value - name);
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		for ( ; SDL_env[i]; ++i ) {
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( SDL_strncmp(SDL_env[i], name, len) == 0 ) {
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				break;
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		/* If we found it, just replace the entry */
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( SDL_env[i] ) {
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_free(SDL_env[i]);
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_env[i] = new_variable;
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			added = 1;
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	/* Didn't find it in the environment, expand and add */
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ! added ) {
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		new_env = SDL_realloc(SDL_env, (i+2)*sizeof(char *));
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		if ( new_env ) {
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_env = new_env;
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_env[i++] = new_variable;
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_env[i++] = (char *)0;
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			added = 1;
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		} else {
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			SDL_free(new_variable);
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return (added ? 0 : -1);
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Retrieve a variable named "name" from the environment */
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallchar *SDL_getenv(const char *name)
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	int len, i;
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char *value;
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	value = (char *)0;
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_env ) {
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		len = SDL_strlen(name);
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		for ( i=0; SDL_env[i] && !value; ++i ) {
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			if ( (SDL_strncmp(SDL_env[i], name, len) == 0) &&
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			     (SDL_env[i][len] == '=') ) {
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall				value = &SDL_env[i][len+1];
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			}
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		}
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return value;
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* __WIN32__ */
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* !HAVE_GETENV */
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#ifdef TEST_MAIN
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h>
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint main(int argc, char *argv[])
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	char *value;
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Checking for non-existent variable... ");
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ! SDL_getenv("EXISTS") ) {
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Setting FIRST=VALUE1 in the environment... ");
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_putenv("FIRST=VALUE1") == 0 ) {
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Getting FIRST from the environment... ");
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	value = SDL_getenv("FIRST");
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( value && (SDL_strcmp(value, "VALUE1") == 0) ) {
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Setting SECOND=VALUE2 in the environment... ");
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_putenv("SECOND=VALUE2") == 0 ) {
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Getting SECOND from the environment... ");
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	value = SDL_getenv("SECOND");
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( value && (SDL_strcmp(value, "VALUE2") == 0) ) {
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Setting FIRST=NOVALUE in the environment... ");
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( SDL_putenv("FIRST=NOVALUE") == 0 ) {
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Getting FIRST from the environment... ");
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	value = SDL_getenv("FIRST");
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( value && (SDL_strcmp(value, "NOVALUE") == 0) ) {
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	printf("Checking for non-existent variable... ");
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	fflush(stdout);
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	if ( ! SDL_getenv("EXISTS") ) {
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("okay\n");
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	} else {
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		printf("failed\n");
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	}
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	return(0);
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif /* TEST_MAIN */
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
248