summaryrefslogtreecommitdiff
path: root/src/stdlib/getenv.c
blob: 4ba83edbf6cab51eb6477f91fa1bc465002dcf4a (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
25
26
27
28
29
30
31
32
33
#include <stdlib.h>
#include "string.h"
#include "_stdlib.h"

/** get an environment variable **/

char * getenv(const char * name)
{
	char **environ = __stdlib.environ;
	size_t len = strlen(name);
	size_t i = 0;

	for (i = 0; environ[i] != NULL; i++) {
		if (!strncmp(environ[i], name, len) && environ[i][len] == '=') {
			break;
		}
	}

	return environ[i];
}

/***
read the environment variable ARGUMENT(name) from the host environment.
***/

/*
UNDEFINED(Modifying the returned string)
IMPLEMENTATION(The set of environment variable names)
IMPLEMENTATION(The method of altering the environment)
RETURN_FAILURE(CONSTANT(NULL))
RETURN_SUCCESS(a pointer to the environment string)
STDC(1)
*/