OSDN Git Service

- trim any trailing whitespace
[uclinux-h8/uClibc.git] / libc / stdlib / getenv.c
1 /* getenv.c for uClibc
2  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
3  *
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  */
6
7 #include <string.h>
8 #include <unistd.h>
9 #include <stdlib.h>
10
11 libc_hidden_proto(getenv)
12 /* Experimentally off - libc_hidden_proto(memcmp) */
13 /* Experimentally off - libc_hidden_proto(strlen) */
14
15 /* IEEE Std 1003.1-2001 says getenv need not be thread safe, so
16  * don't bother locking access to __environ */
17 char *getenv(const char *var)
18 {
19     int len;
20     char **ep;
21
22     if (!(ep=__environ))
23         return NULL;
24     len = strlen(var);
25     while(*ep) {
26         if (memcmp(var, *ep, len) == 0 && (*ep)[len] == '=') {
27             return *ep + len + 1;
28         }
29         ep++;
30     }
31     return NULL;
32 }
33 libc_hidden_def(getenv)