From: Keith Bostic Date: Fri, 26 Jun 1992 00:15:11 +0000 (-0800) Subject: general cleanup, KNF; no bug fixes X-Git-Tag: BSD-4_4-Snapshot-Development~6411 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/18b22690efc593de786d7c3dcf4fa57ad7035511 general cleanup, KNF; no bug fixes SCCS-vsn: lib/libc/stdlib/getenv.c 5.10 SCCS-vsn: lib/libc/stdlib/setenv.c 5.7 --- diff --git a/usr/src/lib/libc/stdlib/getenv.c b/usr/src/lib/libc/stdlib/getenv.c index 509c65c6ef..4bd5309304 100644 --- a/usr/src/lib/libc/stdlib/getenv.c +++ b/usr/src/lib/libc/stdlib/getenv.c @@ -6,13 +6,15 @@ */ #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 #include #include +char *__findenv __P((const char *, int *)); + /* * getenv -- * Returns ptr to value associated with name, if any, else NULL. @@ -22,13 +24,12 @@ getenv(name) 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). @@ -37,20 +38,24 @@ getenv(name) * 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; - 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); } diff --git a/usr/src/lib/libc/stdlib/setenv.c b/usr/src/lib/libc/stdlib/setenv.c index 8fa33f252f..b7c6158ef0 100644 --- a/usr/src/lib/libc/stdlib/setenv.c +++ b/usr/src/lib/libc/stdlib/setenv.c @@ -6,13 +6,15 @@ */ #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 #include #include +char *__findenv __P((const char *, int *)); + /* * 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 */ - register char *C; + register char *c; int l_value, offset; - char *_findenv(); 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 (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 */ - 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))); @@ -52,24 +53,21 @@ setenv(name, value, rewrite) } 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); - bcopy(environ, P, cnt * sizeof(char *)); - environ = P; + bcopy(environ, p, cnt * sizeof(char *)); + environ = p; } 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 */ - malloc((size_t)((int)(C - name) + l_value + 2)))) + malloc((size_t)((int)(c - name) + l_value + 2)))) 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); } @@ -79,14 +77,14 @@ setenv(name, value, rewrite) */ void unsetenv(name) - const char *name; + const char *name; { extern char **environ; - register char **P; + register char **p; 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; }