summaryrefslogtreecommitdiffstats
path: root/usr/klibc/getenv.c
blob: 3a4ae5e1943165d2e8b338e1aaa763aa5a6e37a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * getenv.c
 */

#include <stdlib.h>
#include <string.h>
#include <unistd.h>

char *getenv(const char *name)
{
	char **p, *q;
	int len = strlen(name);

	if (!environ)
		return NULL;

	for (p = environ; (q = *p); p++) {
		if (!strncmp(name, q, len) && q[len] == '=') {
			return q + (len + 1);
		}
	}

	return NULL;
}