src/stdlib/SDL_getenv.c
author Edward Rudd <urkle@outoforder.cc>
Wed, 26 Sep 2012 14:08:46 -0400
changeset 6462 5e09ac1aba80
parent 6430 48d519500f7e
child 6885 700f1b25f77f
permissions -rwxr-xr-x
allocate *Hint structures per Xlib docs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
    21
#include "SDL_config.h"
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
1354
22f39393668a Fixed build problem with SDL_string.c
Sam Lantinga <slouken@libsdl.org>
parents: 1341
diff changeset
    23
#include "SDL_stdinc.h"
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
1331
1cbaeee565b1 A few fixes to get this building on Linux again
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
    25
#ifndef HAVE_GETENV
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
6430
48d519500f7e Removed Windows CE support from SDL 2.0.
Ryan C. Gordon <icculus@icculus.org>
parents: 6138
diff changeset
    27
#if defined(__WIN32__)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    29
#include "../core/windows/SDL_windows.h"
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
/* Note this isn't thread-safe! */
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    33
static char *SDL_envmem = NULL; /* Ugh, memory leak */
1456
84de7511f79f Fixed a bunch of 64-bit compatibility problems
Sam Lantinga <slouken@libsdl.org>
parents: 1433
diff changeset
    34
static size_t SDL_envmemlen = 0;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    36
/* Put a variable into the environment */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    37
int
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    38
SDL_setenv(const char *name, const char *value, int overwrite)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
{
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    40
    if (!overwrite) {
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    41
        char ch = 0;
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    42
        const size_t len = GetEnvironmentVariableA(name, &ch, sizeof (ch));
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    43
        if (len > 0) {
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    44
            return 0;  /* asked not to overwrite existing value. */
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    45
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    46
    }
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    47
    if (!SetEnvironmentVariableA(name, *value ? value : NULL)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    48
        return -1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    49
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    50
    return 0;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
/* Retrieve a variable named "name" from the environment */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    54
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    55
SDL_getenv(const char *name)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    57
    size_t bufferlen;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    59
    bufferlen =
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    60
        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    61
    if (bufferlen == 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    62
        return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    63
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    64
    if (bufferlen > SDL_envmemlen) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    65
        char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    66
        if (newmem == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    67
            return NULL;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    68
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    69
        SDL_envmem = newmem;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    70
        SDL_envmemlen = bufferlen;
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5086
diff changeset
    71
        GetEnvironmentVariableA(name, SDL_envmem, (DWORD) SDL_envmemlen);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    72
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    73
    return SDL_envmem;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
#else /* roll our own */
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    78
static char **SDL_env = (char **) 0;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    80
/* Put a variable into the environment */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    81
int
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    82
SDL_setenv(const char *name, const char *value, int overwrite)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    84
    int added;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    85
    int len, i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    86
    char **new_env;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    87
    char *new_variable;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    89
    /* A little error checking */
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
    90
    if (!name || !value) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    91
        return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    92
    }
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
3583
65f66674b7fb Allocate memory only if we're going to overwrite an environment variable
Sam Lantinga <slouken@libsdl.org>
parents: 3581
diff changeset
    94
    /* See if it already exists */
65f66674b7fb Allocate memory only if we're going to overwrite an environment variable
Sam Lantinga <slouken@libsdl.org>
parents: 3581
diff changeset
    95
    if (!overwrite && SDL_getenv(name)) {
65f66674b7fb Allocate memory only if we're going to overwrite an environment variable
Sam Lantinga <slouken@libsdl.org>
parents: 3581
diff changeset
    96
        return 0;
65f66674b7fb Allocate memory only if we're going to overwrite an environment variable
Sam Lantinga <slouken@libsdl.org>
parents: 3581
diff changeset
    97
    }
65f66674b7fb Allocate memory only if we're going to overwrite an environment variable
Sam Lantinga <slouken@libsdl.org>
parents: 3581
diff changeset
    98
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
    99
    /* Allocate memory for the variable */
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   100
    len = SDL_strlen(name) + SDL_strlen(value) + 2;
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   101
    new_variable = (char *) SDL_malloc(len);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   102
    if (!new_variable) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   103
        return (-1);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   104
    }
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   106
    SDL_snprintf(new_variable, len, "%s=%s", name, value);
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   107
    value = new_variable + SDL_strlen(name) + 1;
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   108
    name = new_variable;
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   109
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   110
    /* Actually put it into the environment */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   111
    added = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   112
    i = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   113
    if (SDL_env) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   114
        /* Check to see if it's already there... */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   115
        len = (value - name);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   116
        for (; SDL_env[i]; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   117
            if (SDL_strncmp(SDL_env[i], name, len) == 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   118
                break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   119
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   120
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   121
        /* If we found it, just replace the entry */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   122
        if (SDL_env[i]) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   123
            SDL_free(SDL_env[i]);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   124
            SDL_env[i] = new_variable;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   125
            added = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   126
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   127
    }
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   129
    /* Didn't find it in the environment, expand and add */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   130
    if (!added) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   131
        new_env = SDL_realloc(SDL_env, (i + 2) * sizeof(char *));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   132
        if (new_env) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   133
            SDL_env = new_env;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   134
            SDL_env[i++] = new_variable;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   135
            SDL_env[i++] = (char *) 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   136
            added = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   137
        } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   138
            SDL_free(new_variable);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   139
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   140
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   141
    return (added ? 0 : -1);
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
/* Retrieve a variable named "name" from the environment */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   145
char *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   146
SDL_getenv(const char *name)
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   148
    int len, i;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   149
    char *value;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   151
    value = (char *) 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   152
    if (SDL_env) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   153
        len = SDL_strlen(name);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   154
        for (i = 0; SDL_env[i] && !value; ++i) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   155
            if ((SDL_strncmp(SDL_env[i], name, len) == 0) &&
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   156
                (SDL_env[i][len] == '=')) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   157
                value = &SDL_env[i][len + 1];
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   158
            }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   159
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   160
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   161
    return value;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
5086
c2539ff054c8 Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents: 5062
diff changeset
   164
#endif /* __WIN32__ */
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
1331
1cbaeee565b1 A few fixes to get this building on Linux again
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   166
#endif /* !HAVE_GETENV */
1cbaeee565b1 A few fixes to get this building on Linux again
Sam Lantinga <slouken@libsdl.org>
parents: 1330
diff changeset
   167
3581
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   168
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   169
/* We have a real environment table, but no real setenv? Fake it w/ putenv. */
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   170
#if (defined(HAVE_GETENV) && defined(HAVE_PUTENV) && !defined(HAVE_SETENV))
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   171
int
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   172
SDL_setenv(const char *name, const char *value, int overwrite)
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   173
{
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   174
    size_t len;
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   175
    char *new_variable;
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   176
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   177
    if (getenv(name) != NULL) {
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   178
        if (overwrite) {
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   179
            unsetenv(name);
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   180
        } else {
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   181
            return 0;  /* leave the existing one there. */
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   182
        }
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   183
    }
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   184
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   185
    /* This leaks. Sorry. Get a better OS so we don't have to do this. */
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   186
    len = SDL_strlen(name) + SDL_strlen(value) + 2;
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   187
    new_variable = (char *) SDL_malloc(len);
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   188
    if (!new_variable) {
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   189
        return (-1);
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   190
    }
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   191
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   192
    SDL_snprintf(new_variable, len, "%s=%s", name, value);
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   193
    return putenv(new_variable);
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   194
}
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   195
#endif
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   196
15eea7a1fa97 Implemented SDL_setenv(), moved SDL_putenv() to compat.
Ryan C. Gordon <icculus@icculus.org>
parents: 2859
diff changeset
   197
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
#ifdef TEST_MAIN
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
#include <stdio.h>
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   201
int
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   202
main(int argc, char *argv[])
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   204
    char *value;
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   206
    printf("Checking for non-existent variable... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   207
    fflush(stdout);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   208
    if (!SDL_getenv("EXISTS")) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   209
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   210
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   211
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   212
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   213
    printf("Setting FIRST=VALUE1 in the environment... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   214
    fflush(stdout);
3591
db4af3cb938e Updated test code to use SDL_setenv()
Sam Lantinga <slouken@libsdl.org>
parents: 3583
diff changeset
   215
    if (SDL_setenv("FIRST", "VALUE1", 0) == 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   216
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   217
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   218
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   219
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   220
    printf("Getting FIRST from the environment... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   221
    fflush(stdout);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   222
    value = SDL_getenv("FIRST");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   223
    if (value && (SDL_strcmp(value, "VALUE1") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   224
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   225
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   226
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   227
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   228
    printf("Setting SECOND=VALUE2 in the environment... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   229
    fflush(stdout);
3591
db4af3cb938e Updated test code to use SDL_setenv()
Sam Lantinga <slouken@libsdl.org>
parents: 3583
diff changeset
   230
    if (SDL_setenv("SECOND", "VALUE2", 0) == 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   231
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   232
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   233
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   234
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   235
    printf("Getting SECOND from the environment... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   236
    fflush(stdout);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   237
    value = SDL_getenv("SECOND");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   238
    if (value && (SDL_strcmp(value, "VALUE2") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   239
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   240
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   241
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   242
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   243
    printf("Setting FIRST=NOVALUE in the environment... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   244
    fflush(stdout);
3591
db4af3cb938e Updated test code to use SDL_setenv()
Sam Lantinga <slouken@libsdl.org>
parents: 3583
diff changeset
   245
    if (SDL_setenv("FIRST", "NOVALUE", 1) == 0) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   246
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   247
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   248
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   249
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   250
    printf("Getting FIRST from the environment... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   251
    fflush(stdout);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   252
    value = SDL_getenv("FIRST");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   253
    if (value && (SDL_strcmp(value, "NOVALUE") == 0)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   254
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   255
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   256
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   257
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   258
    printf("Checking for non-existent variable... ");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   259
    fflush(stdout);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   260
    if (!SDL_getenv("EXISTS")) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   261
        printf("okay\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   262
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   263
        printf("failed\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   264
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   265
    return (0);
1330
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
}
450721ad5436 It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
#endif /* TEST_MAIN */
3591
db4af3cb938e Updated test code to use SDL_setenv()
Sam Lantinga <slouken@libsdl.org>
parents: 3583
diff changeset
   268
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1472
diff changeset
   269
/* vi: set ts=4 sw=4 expandtab: */