src/stdlib/SDL_getenv.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
     1.1 --- a/src/stdlib/SDL_getenv.c	Mon May 29 03:53:21 2006 +0000
     1.2 +++ b/src/stdlib/SDL_getenv.c	Mon May 29 04:04:35 2006 +0000
     1.3 @@ -37,29 +37,29 @@
     1.4  
     1.5  /* Put a variable of the form "name=value" into the environment */
     1.6  int
     1.7 -SDL_putenv (const char *variable)
     1.8 +SDL_putenv(const char *variable)
     1.9  {
    1.10      size_t bufferlen;
    1.11      char *value;
    1.12      const char *sep;
    1.13  
    1.14 -    sep = SDL_strchr (variable, '=');
    1.15 +    sep = SDL_strchr(variable, '=');
    1.16      if (sep == NULL) {
    1.17          return -1;
    1.18      }
    1.19 -    bufferlen = SDL_strlen (variable) + 1;
    1.20 +    bufferlen = SDL_strlen(variable) + 1;
    1.21      if (bufferlen > SDL_envmemlen) {
    1.22 -        char *newmem = (char *) SDL_realloc (SDL_envmem, bufferlen);
    1.23 +        char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
    1.24          if (newmem == NULL) {
    1.25              return -1;
    1.26          }
    1.27          SDL_envmem = newmem;
    1.28          SDL_envmemlen = bufferlen;
    1.29      }
    1.30 -    SDL_strlcpy (SDL_envmem, variable, bufferlen);
    1.31 +    SDL_strlcpy(SDL_envmem, variable, bufferlen);
    1.32      value = SDL_envmem + (sep - variable);
    1.33      *value++ = '\0';
    1.34 -    if (!SetEnvironmentVariable (SDL_envmem, *value ? value : NULL)) {
    1.35 +    if (!SetEnvironmentVariable(SDL_envmem, *value ? value : NULL)) {
    1.36          return -1;
    1.37      }
    1.38      return 0;
    1.39 @@ -67,23 +67,23 @@
    1.40  
    1.41  /* Retrieve a variable named "name" from the environment */
    1.42  char *
    1.43 -SDL_getenv (const char *name)
    1.44 +SDL_getenv(const char *name)
    1.45  {
    1.46      size_t bufferlen;
    1.47  
    1.48      bufferlen =
    1.49 -        GetEnvironmentVariable (name, SDL_envmem, (DWORD) SDL_envmemlen);
    1.50 +        GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen);
    1.51      if (bufferlen == 0) {
    1.52          return NULL;
    1.53      }
    1.54      if (bufferlen > SDL_envmemlen) {
    1.55 -        char *newmem = (char *) SDL_realloc (SDL_envmem, bufferlen);
    1.56 +        char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
    1.57          if (newmem == NULL) {
    1.58              return NULL;
    1.59          }
    1.60          SDL_envmem = newmem;
    1.61          SDL_envmemlen = bufferlen;
    1.62 -        GetEnvironmentVariable (name, SDL_envmem, (DWORD) SDL_envmemlen);
    1.63 +        GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen);
    1.64      }
    1.65      return SDL_envmem;
    1.66  }
    1.67 @@ -94,7 +94,7 @@
    1.68  
    1.69  /* Put a variable of the form "name=value" into the environment */
    1.70  int
    1.71 -SDL_putenv (const char *variable)
    1.72 +SDL_putenv(const char *variable)
    1.73  {
    1.74      const char *name, *value;
    1.75      int added;
    1.76 @@ -117,7 +117,7 @@
    1.77      }
    1.78  
    1.79      /* Allocate memory for the variable */
    1.80 -    new_variable = SDL_strdup (variable);
    1.81 +    new_variable = SDL_strdup(variable);
    1.82      if (!new_variable) {
    1.83          return (-1);
    1.84      }
    1.85 @@ -129,13 +129,13 @@
    1.86          /* Check to see if it's already there... */
    1.87          len = (value - name);
    1.88          for (; SDL_env[i]; ++i) {
    1.89 -            if (SDL_strncmp (SDL_env[i], name, len) == 0) {
    1.90 +            if (SDL_strncmp(SDL_env[i], name, len) == 0) {
    1.91                  break;
    1.92              }
    1.93          }
    1.94          /* If we found it, just replace the entry */
    1.95          if (SDL_env[i]) {
    1.96 -            SDL_free (SDL_env[i]);
    1.97 +            SDL_free(SDL_env[i]);
    1.98              SDL_env[i] = new_variable;
    1.99              added = 1;
   1.100          }
   1.101 @@ -143,14 +143,14 @@
   1.102  
   1.103      /* Didn't find it in the environment, expand and add */
   1.104      if (!added) {
   1.105 -        new_env = SDL_realloc (SDL_env, (i + 2) * sizeof (char *));
   1.106 +        new_env = SDL_realloc(SDL_env, (i + 2) * sizeof(char *));
   1.107          if (new_env) {
   1.108              SDL_env = new_env;
   1.109              SDL_env[i++] = new_variable;
   1.110              SDL_env[i++] = (char *) 0;
   1.111              added = 1;
   1.112          } else {
   1.113 -            SDL_free (new_variable);
   1.114 +            SDL_free(new_variable);
   1.115          }
   1.116      }
   1.117      return (added ? 0 : -1);
   1.118 @@ -158,16 +158,16 @@
   1.119  
   1.120  /* Retrieve a variable named "name" from the environment */
   1.121  char *
   1.122 -SDL_getenv (const char *name)
   1.123 +SDL_getenv(const char *name)
   1.124  {
   1.125      int len, i;
   1.126      char *value;
   1.127  
   1.128      value = (char *) 0;
   1.129      if (SDL_env) {
   1.130 -        len = SDL_strlen (name);
   1.131 +        len = SDL_strlen(name);
   1.132          for (i = 0; SDL_env[i] && !value; ++i) {
   1.133 -            if ((SDL_strncmp (SDL_env[i], name, len) == 0) &&
   1.134 +            if ((SDL_strncmp(SDL_env[i], name, len) == 0) &&
   1.135                  (SDL_env[i][len] == '=')) {
   1.136                  value = &SDL_env[i][len + 1];
   1.137              }
   1.138 @@ -184,68 +184,68 @@
   1.139  #include <stdio.h>
   1.140  
   1.141  int
   1.142 -main (int argc, char *argv[])
   1.143 +main(int argc, char *argv[])
   1.144  {
   1.145      char *value;
   1.146  
   1.147 -    printf ("Checking for non-existent variable... ");
   1.148 -    fflush (stdout);
   1.149 -    if (!SDL_getenv ("EXISTS")) {
   1.150 -        printf ("okay\n");
   1.151 +    printf("Checking for non-existent variable... ");
   1.152 +    fflush(stdout);
   1.153 +    if (!SDL_getenv("EXISTS")) {
   1.154 +        printf("okay\n");
   1.155      } else {
   1.156 -        printf ("failed\n");
   1.157 +        printf("failed\n");
   1.158      }
   1.159 -    printf ("Setting FIRST=VALUE1 in the environment... ");
   1.160 -    fflush (stdout);
   1.161 -    if (SDL_putenv ("FIRST=VALUE1") == 0) {
   1.162 -        printf ("okay\n");
   1.163 +    printf("Setting FIRST=VALUE1 in the environment... ");
   1.164 +    fflush(stdout);
   1.165 +    if (SDL_putenv("FIRST=VALUE1") == 0) {
   1.166 +        printf("okay\n");
   1.167      } else {
   1.168 -        printf ("failed\n");
   1.169 +        printf("failed\n");
   1.170      }
   1.171 -    printf ("Getting FIRST from the environment... ");
   1.172 -    fflush (stdout);
   1.173 -    value = SDL_getenv ("FIRST");
   1.174 -    if (value && (SDL_strcmp (value, "VALUE1") == 0)) {
   1.175 -        printf ("okay\n");
   1.176 +    printf("Getting FIRST from the environment... ");
   1.177 +    fflush(stdout);
   1.178 +    value = SDL_getenv("FIRST");
   1.179 +    if (value && (SDL_strcmp(value, "VALUE1") == 0)) {
   1.180 +        printf("okay\n");
   1.181      } else {
   1.182 -        printf ("failed\n");
   1.183 +        printf("failed\n");
   1.184      }
   1.185 -    printf ("Setting SECOND=VALUE2 in the environment... ");
   1.186 -    fflush (stdout);
   1.187 -    if (SDL_putenv ("SECOND=VALUE2") == 0) {
   1.188 -        printf ("okay\n");
   1.189 +    printf("Setting SECOND=VALUE2 in the environment... ");
   1.190 +    fflush(stdout);
   1.191 +    if (SDL_putenv("SECOND=VALUE2") == 0) {
   1.192 +        printf("okay\n");
   1.193      } else {
   1.194 -        printf ("failed\n");
   1.195 +        printf("failed\n");
   1.196      }
   1.197 -    printf ("Getting SECOND from the environment... ");
   1.198 -    fflush (stdout);
   1.199 -    value = SDL_getenv ("SECOND");
   1.200 -    if (value && (SDL_strcmp (value, "VALUE2") == 0)) {
   1.201 -        printf ("okay\n");
   1.202 +    printf("Getting SECOND from the environment... ");
   1.203 +    fflush(stdout);
   1.204 +    value = SDL_getenv("SECOND");
   1.205 +    if (value && (SDL_strcmp(value, "VALUE2") == 0)) {
   1.206 +        printf("okay\n");
   1.207      } else {
   1.208 -        printf ("failed\n");
   1.209 +        printf("failed\n");
   1.210      }
   1.211 -    printf ("Setting FIRST=NOVALUE in the environment... ");
   1.212 -    fflush (stdout);
   1.213 -    if (SDL_putenv ("FIRST=NOVALUE") == 0) {
   1.214 -        printf ("okay\n");
   1.215 +    printf("Setting FIRST=NOVALUE in the environment... ");
   1.216 +    fflush(stdout);
   1.217 +    if (SDL_putenv("FIRST=NOVALUE") == 0) {
   1.218 +        printf("okay\n");
   1.219      } else {
   1.220 -        printf ("failed\n");
   1.221 +        printf("failed\n");
   1.222      }
   1.223 -    printf ("Getting FIRST from the environment... ");
   1.224 -    fflush (stdout);
   1.225 -    value = SDL_getenv ("FIRST");
   1.226 -    if (value && (SDL_strcmp (value, "NOVALUE") == 0)) {
   1.227 -        printf ("okay\n");
   1.228 +    printf("Getting FIRST from the environment... ");
   1.229 +    fflush(stdout);
   1.230 +    value = SDL_getenv("FIRST");
   1.231 +    if (value && (SDL_strcmp(value, "NOVALUE") == 0)) {
   1.232 +        printf("okay\n");
   1.233      } else {
   1.234 -        printf ("failed\n");
   1.235 +        printf("failed\n");
   1.236      }
   1.237 -    printf ("Checking for non-existent variable... ");
   1.238 -    fflush (stdout);
   1.239 -    if (!SDL_getenv ("EXISTS")) {
   1.240 -        printf ("okay\n");
   1.241 +    printf("Checking for non-existent variable... ");
   1.242 +    fflush(stdout);
   1.243 +    if (!SDL_getenv("EXISTS")) {
   1.244 +        printf("okay\n");
   1.245      } else {
   1.246 -        printf ("failed\n");
   1.247 +        printf("failed\n");
   1.248      }
   1.249      return (0);
   1.250  }