diff options
| author | David Greenman <dg@FreeBSD.org> | 1995-10-17 21:37:41 +0000 | 
|---|---|---|
| committer | David Greenman <dg@FreeBSD.org> | 1995-10-17 21:37:41 +0000 | 
| commit | 283e0c0eb74236dc10d0ee0baac0e01b9181756d (patch) | |
| tree | 7185dfa7bcb362d68b172d02199ec3c21aa3e246 /lib/libc | |
| parent | 030fc198113ac4dde6b37c6302694e403e11fe26 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/stdlib/getenv.c | 44 | 
1 files changed, 24 insertions, 20 deletions
| diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c index 7407e0b81749..a6bbd355d93f 100644 --- a/lib/libc/stdlib/getenv.c +++ b/lib/libc/stdlib/getenv.c @@ -39,20 +39,7 @@ static char sccsid[] = "@(#)getenv.c	8.1 (Berkeley) 6/4/93";  #include <stddef.h>  #include <string.h> -char *__findenv __P((const char *, int *)); - -/* - * getenv -- - *	Returns ptr to value associated with name, if any, else NULL. - */ -char * -getenv(name) -	const char *name; -{ -	int offset; - -	return (__findenv(name, &offset)); -} +inline char *__findenv __P((const char *, int *));  /*   * __findenv -- @@ -63,25 +50,42 @@ getenv(name)   *   *	This routine *should* be a static; don't use it.   */ -char * +inline char *  __findenv(name, offset)  	register const char *name;  	int *offset;  {  	extern char **environ; -	register int len; +	register int len, i;  	register const char *np; -	register char **p, *c; +	register char **p, *cp;  	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] == '=') { +	for (p = environ; (cp = *p) != NULL; ++p) { +		for (np = name, i = len; i && *cp; i--) +			if (*cp++ != *np++) +				break; +		if (i == 0 && *cp++ == '=') {  			*offset = p - environ; -			return (c + len + 1); +			return (cp);  		} +	}  	return (NULL);  } + +/* + * getenv -- + *	Returns ptr to value associated with name, if any, else NULL. + */ +char * +getenv(name) +	const char *name; +{ +	int offset; + +	return (__findenv(name, &offset)); +} | 
