]> pd.if.org Git - pdclib/blob - platform/example/functions/stdlib/getenv.c
Moving files to new dir structure.
[pdclib] / platform / example / functions / stdlib / getenv.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* getenv( const char * )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 /* This is an example implementation of getenv() fit for use with POSIX kernels.
12 */
13
14 #include <string.h>
15 #include <stdlib.h>
16
17 #ifndef REGTEST
18
19 extern char * * environ;
20
21 char * getenv( const char * name )
22 {
23     size_t len = strlen( name );
24     size_t index = 0;
25     while ( environ[ index ] != NULL )
26     {
27         if ( strncmp( environ[ index ], name, len ) == 0 )
28         {
29             return environ[ index ] + len + 1;
30         }
31         index++;
32     }
33     return NULL;
34 }
35
36 #endif
37
38 #ifdef TEST
39 #include <_PDCLIB_test.h>
40
41 int main()
42 {
43     BEGIN_TESTS;
44     TESTCASE( strcmp( getenv( "SHELL" ), "/bin/sh" ) == 0 );
45     return TEST_RESULTS;
46 }
47
48 #endif