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