summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>1998-07-16 18:02:33 +0000
committerderaadt <>1998-07-16 18:02:33 +0000
commitb811c9ad609b90ad8a28b3d5e9044db773f24841 (patch)
tree5cc93e4f177a467faca15e244b073b9c8c6274ae /src
parent434631ffba69d4617274ef90816eddb0e6a7e0d4 (diff)
downloadopenbsd-b811c9ad609b90ad8a28b3d5e9044db773f24841.tar.gz
openbsd-b811c9ad609b90ad8a28b3d5e9044db773f24841.tar.bz2
openbsd-b811c9ad609b90ad8a28b3d5e9044db773f24841.zip
change to lite2 getenv(); getenv(NULL) now returns NULL
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/getenv.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/lib/libc/stdlib/getenv.c b/src/lib/libc/stdlib/getenv.c
index e944c287bc..4db86df915 100644
--- a/src/lib/libc/stdlib/getenv.c
+++ b/src/lib/libc/stdlib/getenv.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 1987 Regents of the University of California. 2 * Copyright (c) 1987, 1993
3 * All rights reserved. 3 * The Regents of the University of California. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: getenv.c,v 1.3 1996/08/19 08:33:31 tholo Exp $"; 35static char *rcsid = "$OpenBSD: getenv.c,v 1.4 1998/07/16 18:02:33 deraadt Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <stdlib.h> 38#include <stdlib.h>
@@ -53,18 +53,25 @@ __findenv(name, offset)
53 int *offset; 53 int *offset;
54{ 54{
55 extern char **environ; 55 extern char **environ;
56 register int len; 56 register int len, i;
57 register char **P, *C; 57 register const char *np;
58 register const char *cp; 58 register char **p, *cp;
59 59
60 for (cp = name, len = 0; *cp != '\0' && *cp != '='; ++cp, ++len); 60 if (name == NULL || environ == NULL)
61 for (P = environ; *P; ++P) 61 return (NULL);
62 if (!strncmp(*P, name, len)) 62 for (np = name; *np && *np != '='; ++np)
63 if (*(C = *P + len) == '=') { 63 ;
64 *offset = P - environ; 64 len = np - name;
65 return(++C); 65 for (p = environ; (cp = *p) != NULL; ++p) {
66 } 66 for (np = name, i = len; i && *cp; i--)
67 return(NULL); 67 if (*cp++ != *np++)
68 break;
69 if (i == 0 && *cp++ == '=') {
70 *offset = p - environ;
71 return (cp);
72 }
73 }
74 return (NULL);
68} 75}
69 76
70/* 77/*