summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-07-16 18:02:34 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-07-16 18:02:34 +0000
commit0e77c4a98e4ee411bdadc1afad2aa07c9ef8f137 (patch)
treea5bc44d9e04bdae70eb77987706892fd5f3a1158 /lib/libc/stdlib
parent87a25a106b6185d73e60bb8e3cb596adfd369c8f (diff)
change to lite2 getenv(); getenv(NULL) now returns NULL
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/getenv.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c
index e944c287bcf..4db86df915f 100644
--- a/lib/libc/stdlib/getenv.c
+++ b/lib/libc/stdlib/getenv.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1987, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: getenv.c,v 1.3 1996/08/19 08:33:31 tholo Exp $";
+static char *rcsid = "$OpenBSD: getenv.c,v 1.4 1998/07/16 18:02:33 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
@@ -53,18 +53,25 @@ __findenv(name, offset)
int *offset;
{
extern char **environ;
- register int len;
- register char **P, *C;
- register const char *cp;
+ register int len, i;
+ register const char *np;
+ register char **p, *cp;
- for (cp = name, len = 0; *cp != '\0' && *cp != '='; ++cp, ++len);
- for (P = environ; *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)
+ ;
+ 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++ == '=') {
+ *offset = p - environ;
+ return (cp);
+ }
+ }
+ return (NULL);
}
/*