general cleanup, KNF; no bug fixes
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 26 Jun 1992 00:15:11 +0000 (16:15 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 26 Jun 1992 00:15:11 +0000 (16:15 -0800)
SCCS-vsn: lib/libc/stdlib/getenv.c 5.10
SCCS-vsn: lib/libc/stdlib/setenv.c 5.7

usr/src/lib/libc/stdlib/getenv.c
usr/src/lib/libc/stdlib/setenv.c

index 509c65c..4bd5309 100644 (file)
@@ -6,13 +6,15 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getenv.c   5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)getenv.c   5.10 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
 
 #endif /* LIBC_SCCS and not lint */
 
 #include <stdlib.h>
 #include <stddef.h>
 #include <string.h>
 
+char *__findenv __P((const char *, int *));
+
 /*
  * getenv --
  *     Returns ptr to value associated with name, if any, else NULL.
 /*
  * getenv --
  *     Returns ptr to value associated with name, if any, else NULL.
@@ -22,13 +24,12 @@ getenv(name)
        const char *name;
 {
        int offset;
        const char *name;
 {
        int offset;
-       char *_findenv();
 
 
-       return(_findenv(name, &offset));
+       return (__findenv(name, &offset));
 }
 
 /*
 }
 
 /*
- * _findenv --
+ * __findenv --
  *     Returns pointer to value associated with name, if any, else NULL.
  *     Sets offset to be the offset of the name/value combination in the
  *     environmental array, for use by setenv(3) and unsetenv(3).
  *     Returns pointer to value associated with name, if any, else NULL.
  *     Sets offset to be the offset of the name/value combination in the
  *     environmental array, for use by setenv(3) and unsetenv(3).
@@ -37,20 +38,24 @@ getenv(name)
  *     This routine *should* be a static; don't use it.
  */
 char *
  *     This routine *should* be a static; don't use it.
  */
 char *
-_findenv(name, offset)
-       register char *name;
+__findenv(name, offset)
+       register const char *name;
        int *offset;
 {
        extern char **environ;
        register int len;
        int *offset;
 {
        extern char **environ;
        register int len;
-       register char **P, *C;
+       register const char *np;
+       register char **p, *c;
 
 
-       for (C = name, len = 0; C && *C && *C != '='; ++C, ++len);
-       for (P = environ; P && *P; ++P)
-               if (!strncmp(*P, name, len))
-                       if (*(C = *P + len) == '=') {
-                               *offset = P - environ;
-                               return(++C);
-                       }
-       return(NULL);
+       if (name == NULL || environ == NULL)
+               return (NULL);
+       for (np = name; *np && *np != '='; ++np)
+               continue;
+       len = np - name;
+       for (p = environ; (c = *p) != NULL; ++p)
+               if (strncmp(c, name, len) == 0 && c[len] == '=') {
+                       *offset = p - environ;
+                       return (c + 1);
+               }
+       return (NULL);
 }
 }
index 8fa33f2..b7c6158 100644 (file)
@@ -6,13 +6,15 @@
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)setenv.c   5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)setenv.c   5.7 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
 #endif /* LIBC_SCCS and not lint */
 
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
+char *__findenv __P((const char *, int *)); 
+
 /*
  * setenv --
  *     Set the value of the environmental variable "name" to be
 /*
  * setenv --
  *     Set the value of the environmental variable "name" to be
@@ -25,25 +27,24 @@ setenv(name, value, rewrite)
 {
        extern char **environ;
        static int alloced;                     /* if allocated space before */
 {
        extern char **environ;
        static int alloced;                     /* if allocated space before */
-       register char *C;
+       register char *c;
        int l_value, offset;
        int l_value, offset;
-       char *_findenv();
 
        if (*value == '=')                      /* no `=' in value */
                ++value;
        l_value = strlen(value);
 
        if (*value == '=')                      /* no `=' in value */
                ++value;
        l_value = strlen(value);
-       if ((C = _findenv(name, &offset))) {    /* find if already exists */
+       if ((c = __findenv(name, &offset))) {   /* find if already exists */
                if (!rewrite)
                        return (0);
                if (!rewrite)
                        return (0);
-               if (strlen(C) >= l_value) {     /* old larger; copy over */
-                       while (*C++ = *value++);
+               if (strlen(c) >= l_value) {     /* old larger; copy over */
+                       while (*c++ = *value++);
                        return (0);
                }
        } else {                                        /* create new slot */
                        return (0);
                }
        } else {                                        /* create new slot */
-               register int    cnt;
-               register char   **P;
+               register int cnt;
+               register char **p;
 
 
-               for (P = environ, cnt = 0; *P; ++P, ++cnt);
+               for (p = environ, cnt = 0; *p; ++p, ++cnt);
                if (alloced) {                  /* just increase size */
                        environ = (char **)realloc((char *)environ,
                            (size_t)(sizeof(char *) * (cnt + 2)));
                if (alloced) {                  /* just increase size */
                        environ = (char **)realloc((char *)environ,
                            (size_t)(sizeof(char *) * (cnt + 2)));
@@ -52,24 +53,21 @@ setenv(name, value, rewrite)
                }
                else {                          /* get new space */
                        alloced = 1;            /* copy old entries into it */
                }
                else {                          /* get new space */
                        alloced = 1;            /* copy old entries into it */
-                       P = (char **)malloc((size_t)(sizeof(char *) *
-                           (cnt + 2)));
-                       if (!P)
+                       p = malloc((size_t)(sizeof(char *) * (cnt + 2)));
+                       if (!p)
                                return (-1);
                                return (-1);
-                       bcopy(environ, P, cnt * sizeof(char *));
-                       environ = P;
+                       bcopy(environ, p, cnt * sizeof(char *));
+                       environ = p;
                }
                environ[cnt + 1] = NULL;
                offset = cnt;
        }
                }
                environ[cnt + 1] = NULL;
                offset = cnt;
        }
-       for (C = (char *)name; *C && *C != '='; ++C);   /* no `=' in name */
+       for (c = (char *)name; *c && *c != '='; ++c);   /* no `=' in name */
        if (!(environ[offset] =                 /* name + `=' + value */
        if (!(environ[offset] =                 /* name + `=' + value */
-           malloc((size_t)((int)(C - name) + l_value + 2))))
+           malloc((size_t)((int)(c - name) + l_value + 2))))
                return (-1);
                return (-1);
-       for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
-               ;
-       for (*C++ = '='; *C++ = *value++; )
-               ;
+       for (c = environ[offset]; (*c = *name++) && *c != '='; ++c);
+       for (*c++ = '='; *c++ = *value++;);
        return (0);
 }
 
        return (0);
 }
 
@@ -79,14 +77,14 @@ setenv(name, value, rewrite)
  */
 void
 unsetenv(name)
  */
 void
 unsetenv(name)
-       const char      *name;
+       const char *name;
 {
        extern char **environ;
 {
        extern char **environ;
-       register char **P;
+       register char **p;
        int offset;
 
        int offset;
 
-       while (_findenv(name, &offset))         /* if set multiple times */
-               for (P = &environ[offset];; ++P)
-                       if (!(*P = *(P + 1)))
+       while (__findenv(name, &offset))        /* if set multiple times */
+               for (p = &environ[offset];; ++p)
+                       if (!(*p = *(p + 1)))
                                break;
 }
                                break;
 }