lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 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 | |
| 12 | /* IEEE Std 1003.1-2001 says getenv need not be thread safe, so |
| 13 | * don't bother locking access to __environ */ |
| 14 | char *getenv(const char *var) |
| 15 | { |
| 16 | int len; |
| 17 | char **ep; |
| 18 | |
| 19 | if (!(ep=__environ)) |
| 20 | return NULL; |
| 21 | len = strlen(var); |
| 22 | while(*ep) { |
| 23 | if (memcmp(var, *ep, len) == 0 && (*ep)[len] == '=') { |
| 24 | return *ep + len + 1; |
| 25 | } |
| 26 | ep++; |
| 27 | } |
| 28 | return NULL; |
| 29 | } |
| 30 | libc_hidden_def(getenv) |