Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
614 serge 1
/****************************************************************************
2
*
3
*                            Open Watcom Project
4
*
5
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
6
*
7
*  ========================================================================
8
*
9
*    This file contains Original Code and/or Modifications of Original
10
*    Code as defined in and that are subject to the Sybase Open Watcom
11
*    Public License version 1.0 (the 'License'). You may not use this file
12
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
13
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
14
*    provided with the Original Code and Modifications, and is also
15
*    available at www.sybase.com/developer/opensource.
16
*
17
*    The Original Code and all software distributed under the License are
18
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
20
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
21
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
22
*    NON-INFRINGEMENT. Please see the License for the specific language
23
*    governing rights and limitations under the License.
24
*
25
*  ========================================================================
26
*
27
* Description:  Implementation of getenv().
28
*
29
****************************************************************************/
30
 
31
 
32
#include "variety.h"
33
#include "widechar.h"
34
#include 
35
#include 
36
#include 
37
#include "rtdata.h"
38
#ifdef __WIDECHAR__
39
    #include "wenviron.h"
40
#endif
41
 
42
#if defined(__UNIX__)
43
    #ifdef __WIDECHAR__
44
        #define CMP_FUNC        wcsncmp
45
    #else
46
        #define CMP_FUNC        strncmp
47
    #endif
48
#else
49
    #define CMP_FUNC        _wcsnicmp
50
#endif
51
 
52
#if !defined(__UNIX__) && !defined(__WIDECHAR__) && !defined(__NETWARE__)
53
 
54
_WCRTLINK char *getenv( const char *name )
55
{
56
    char        **envp;
57
    char        *p;
58
 
59
    /*** Find the environment string ***/
60
    __ptr_check( name, 0 );
61
    envp = _RWD_environ;
62
    if( (envp != NULL) && (name != NULL) ) {
63
        for( ; p = *envp; ++envp ) {
64
            const char  *s = name;
65
 
66
            while( *p != '\0' ) {   /* simple check is sufficient for p, not s */
67
                if ( _mbterm( s ) ) {
68
                    if( *p == '=' )  return( p + 1 );
69
                    break;
70
                }
71
                if ( _mbctoupper( _mbsnextc( p ) ) != _mbctoupper( _mbsnextc( s ) ) )
72
                    break;
73
                p = _mbsinc( p );   /* skip over character */
74
                s = _mbsinc( s );   /* skip over character */
75
            }
76
        }
77
    }
78
    return( NULL );                 /* not found */
79
}
80
 
81
#else
82
 
83
_WCRTLINK CHAR_TYPE *__F_NAME(getenv,_wgetenv)( const CHAR_TYPE *name )
84
{
85
#ifdef __NETWARE__
86
    name = name;
87
#else
88
    CHAR_TYPE       **envp;
89
    CHAR_TYPE       *p;
90
    int             len;
91
 
92
    #ifdef __WIDECHAR__
93
        if( _RWD_wenviron == NULL )  __create_wide_environment();
94
    #endif
95
 
96
    /*** Find the environment string ***/
97
    __ptr_check( name, 0 );
98
    envp = __F_NAME(_RWD_environ,_RWD_wenviron);
99
    if( (envp != NULL) && (name != NULL) ) {
100
        len = __F_NAME(strlen,wcslen)( name );
101
        for( ; p = *envp; ++envp ) {
102
            if( CMP_FUNC( p, name, len ) == 0 ) {
103
                if( p[len] == __F_NAME('=',L'=') )  return( &p[len+1] );
104
            }
105
        }
106
    }
107
#endif
108
    return( NULL );                 /* not found */
109
}
110
 
111
#endif