summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/getenv.c
diff options
context:
space:
mode:
authorJordan K. Hubbard <jkh@FreeBSD.org>1996-06-05 02:59:00 +0000
committerJordan K. Hubbard <jkh@FreeBSD.org>1996-06-05 02:59:00 +0000
commit78e55a1f29558e8be54566ead1e7be8ab9d45273 (patch)
tree65fd45fa55d0cd3888b40a4f41dd3383616dfd74 /lib/libc/stdlib/getenv.c
parent885f2f31b4599f4bc7468278c783c1c30f1f86ed (diff)
Notes
Diffstat (limited to 'lib/libc/stdlib/getenv.c')
-rw-r--r--lib/libc/stdlib/getenv.c44
1 files changed, 20 insertions, 24 deletions
diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c
index a6bbd355d93f..7407e0b81749 100644
--- a/lib/libc/stdlib/getenv.c
+++ b/lib/libc/stdlib/getenv.c
@@ -39,7 +39,20 @@ static char sccsid[] = "@(#)getenv.c 8.1 (Berkeley) 6/4/93";
#include <stddef.h>
#include <string.h>
-inline char *__findenv __P((const char *, int *));
+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));
+}
/*
* __findenv --
@@ -50,42 +63,25 @@ inline char *__findenv __P((const char *, int *));
*
* This routine *should* be a static; don't use it.
*/
-inline char *
+char *
__findenv(name, offset)
register const char *name;
int *offset;
{
extern char **environ;
- register int len, i;
+ register int len;
register const char *np;
- register char **p, *cp;
+ register char **p, *c;
if (name == NULL || environ == NULL)
return (NULL);
for (np = name; *np && *np != '='; ++np)
continue;
len = np - name;
- for (p = environ; (cp = *p) != NULL; ++p) {
- for (np = name, i = len; i && *cp; i--)
- if (*cp++ != *np++)
- break;
- if (i == 0 && *cp++ == '=') {
+ for (p = environ; (c = *p) != NULL; ++p)
+ if (strncmp(c, name, len) == 0 && c[len] == '=') {
*offset = p - environ;
- return (cp);
+ return (c + len + 1);
}
- }
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));
-}