SCCS-vsn: lib/libc/stdlib/getenv.c 5.10
SCCS-vsn: lib/libc/stdlib/setenv.c 5.7
*/
#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.
const char *name;
{
int offset;
const char *name;
{
int offset;
- return(_findenv(name, &offset));
+ return (__findenv(name, &offset));
* 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).
* 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 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);
*/
#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
{
extern char **environ;
static int alloced; /* if allocated space before */
{
extern char **environ;
static int alloced; /* if allocated space before */
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)));
}
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)
- 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))))
- for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
- ;
- for (*C++ = '='; *C++ = *value++; )
- ;
+ for (c = environ[offset]; (*c = *name++) && *c != '='; ++c);
+ for (*c++ = '='; *c++ = *value++;);
- 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)))