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