src/stdlib/SDL_getenv.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
--- a/src/stdlib/SDL_getenv.c	Mon May 29 03:53:21 2006 +0000
+++ b/src/stdlib/SDL_getenv.c	Mon May 29 04:04:35 2006 +0000
@@ -37,29 +37,29 @@
 
 /* Put a variable of the form "name=value" into the environment */
 int
-SDL_putenv (const char *variable)
+SDL_putenv(const char *variable)
 {
     size_t bufferlen;
     char *value;
     const char *sep;
 
-    sep = SDL_strchr (variable, '=');
+    sep = SDL_strchr(variable, '=');
     if (sep == NULL) {
         return -1;
     }
-    bufferlen = SDL_strlen (variable) + 1;
+    bufferlen = SDL_strlen(variable) + 1;
     if (bufferlen > SDL_envmemlen) {
-        char *newmem = (char *) SDL_realloc (SDL_envmem, bufferlen);
+        char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
         if (newmem == NULL) {
             return -1;
         }
         SDL_envmem = newmem;
         SDL_envmemlen = bufferlen;
     }
-    SDL_strlcpy (SDL_envmem, variable, bufferlen);
+    SDL_strlcpy(SDL_envmem, variable, bufferlen);
     value = SDL_envmem + (sep - variable);
     *value++ = '\0';
-    if (!SetEnvironmentVariable (SDL_envmem, *value ? value : NULL)) {
+    if (!SetEnvironmentVariable(SDL_envmem, *value ? value : NULL)) {
         return -1;
     }
     return 0;
@@ -67,23 +67,23 @@
 
 /* Retrieve a variable named "name" from the environment */
 char *
-SDL_getenv (const char *name)
+SDL_getenv(const char *name)
 {
     size_t bufferlen;
 
     bufferlen =
-        GetEnvironmentVariable (name, SDL_envmem, (DWORD) SDL_envmemlen);
+        GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen);
     if (bufferlen == 0) {
         return NULL;
     }
     if (bufferlen > SDL_envmemlen) {
-        char *newmem = (char *) SDL_realloc (SDL_envmem, bufferlen);
+        char *newmem = (char *) SDL_realloc(SDL_envmem, bufferlen);
         if (newmem == NULL) {
             return NULL;
         }
         SDL_envmem = newmem;
         SDL_envmemlen = bufferlen;
-        GetEnvironmentVariable (name, SDL_envmem, (DWORD) SDL_envmemlen);
+        GetEnvironmentVariable(name, SDL_envmem, (DWORD) SDL_envmemlen);
     }
     return SDL_envmem;
 }
@@ -94,7 +94,7 @@
 
 /* Put a variable of the form "name=value" into the environment */
 int
-SDL_putenv (const char *variable)
+SDL_putenv(const char *variable)
 {
     const char *name, *value;
     int added;
@@ -117,7 +117,7 @@
     }
 
     /* Allocate memory for the variable */
-    new_variable = SDL_strdup (variable);
+    new_variable = SDL_strdup(variable);
     if (!new_variable) {
         return (-1);
     }
@@ -129,13 +129,13 @@
         /* 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) {
+            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_free(SDL_env[i]);
             SDL_env[i] = new_variable;
             added = 1;
         }
@@ -143,14 +143,14 @@
 
     /* Didn't find it in the environment, expand and add */
     if (!added) {
-        new_env = SDL_realloc (SDL_env, (i + 2) * sizeof (char *));
+        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);
+            SDL_free(new_variable);
         }
     }
     return (added ? 0 : -1);
@@ -158,16 +158,16 @@
 
 /* Retrieve a variable named "name" from the environment */
 char *
-SDL_getenv (const char *name)
+SDL_getenv(const char *name)
 {
     int len, i;
     char *value;
 
     value = (char *) 0;
     if (SDL_env) {
-        len = SDL_strlen (name);
+        len = SDL_strlen(name);
         for (i = 0; SDL_env[i] && !value; ++i) {
-            if ((SDL_strncmp (SDL_env[i], name, len) == 0) &&
+            if ((SDL_strncmp(SDL_env[i], name, len) == 0) &&
                 (SDL_env[i][len] == '=')) {
                 value = &SDL_env[i][len + 1];
             }
@@ -184,68 +184,68 @@
 #include <stdio.h>
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
     char *value;
 
-    printf ("Checking for non-existent variable... ");
-    fflush (stdout);
-    if (!SDL_getenv ("EXISTS")) {
-        printf ("okay\n");
+    printf("Checking for non-existent variable... ");
+    fflush(stdout);
+    if (!SDL_getenv("EXISTS")) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
-    printf ("Setting FIRST=VALUE1 in the environment... ");
-    fflush (stdout);
-    if (SDL_putenv ("FIRST=VALUE1") == 0) {
-        printf ("okay\n");
+    printf("Setting FIRST=VALUE1 in the environment... ");
+    fflush(stdout);
+    if (SDL_putenv("FIRST=VALUE1") == 0) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
-    printf ("Getting FIRST from the environment... ");
-    fflush (stdout);
-    value = SDL_getenv ("FIRST");
-    if (value && (SDL_strcmp (value, "VALUE1") == 0)) {
-        printf ("okay\n");
+    printf("Getting FIRST from the environment... ");
+    fflush(stdout);
+    value = SDL_getenv("FIRST");
+    if (value && (SDL_strcmp(value, "VALUE1") == 0)) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
-    printf ("Setting SECOND=VALUE2 in the environment... ");
-    fflush (stdout);
-    if (SDL_putenv ("SECOND=VALUE2") == 0) {
-        printf ("okay\n");
+    printf("Setting SECOND=VALUE2 in the environment... ");
+    fflush(stdout);
+    if (SDL_putenv("SECOND=VALUE2") == 0) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
-    printf ("Getting SECOND from the environment... ");
-    fflush (stdout);
-    value = SDL_getenv ("SECOND");
-    if (value && (SDL_strcmp (value, "VALUE2") == 0)) {
-        printf ("okay\n");
+    printf("Getting SECOND from the environment... ");
+    fflush(stdout);
+    value = SDL_getenv("SECOND");
+    if (value && (SDL_strcmp(value, "VALUE2") == 0)) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
-    printf ("Setting FIRST=NOVALUE in the environment... ");
-    fflush (stdout);
-    if (SDL_putenv ("FIRST=NOVALUE") == 0) {
-        printf ("okay\n");
+    printf("Setting FIRST=NOVALUE in the environment... ");
+    fflush(stdout);
+    if (SDL_putenv("FIRST=NOVALUE") == 0) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
-    printf ("Getting FIRST from the environment... ");
-    fflush (stdout);
-    value = SDL_getenv ("FIRST");
-    if (value && (SDL_strcmp (value, "NOVALUE") == 0)) {
-        printf ("okay\n");
+    printf("Getting FIRST from the environment... ");
+    fflush(stdout);
+    value = SDL_getenv("FIRST");
+    if (value && (SDL_strcmp(value, "NOVALUE") == 0)) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
-    printf ("Checking for non-existent variable... ");
-    fflush (stdout);
-    if (!SDL_getenv ("EXISTS")) {
-        printf ("okay\n");
+    printf("Checking for non-existent variable... ");
+    fflush(stdout);
+    if (!SDL_getenv("EXISTS")) {
+        printf("okay\n");
     } else {
-        printf ("failed\n");
+        printf("failed\n");
     }
     return (0);
 }