Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 613 → Rev 614

/programs/develop/open watcom/trunk/clib/environ/clearenv.c
0,0 → 1,69
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of clearenv() - clear the environment.
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdlib.h>
#include <env.h>
#include "liballoc.h"
#include "rtdata.h"
 
/* Note - clearenv() is always called at library exit */
 
_WCRTLINK int (clearenv)( void )
{
#ifndef __NETWARE__
char **envp;
char *env_str;
int index;
 
if( _RWD_environ != NULL ) {
for( envp = _RWD_environ; env_str = *envp; ++envp ) {
if( _RWD_env_mask != NULL ) {
index = envp - _RWD_environ;
if( _RWD_env_mask[ index ] != 0 ) {
lib_free( (void *)env_str );
}
*envp = NULL;
}
}
if( _RWD_env_mask != NULL ) {
lib_free( _RWD_environ );
}
envp = lib_malloc( sizeof(char *) + sizeof(char) );
if( envp == NULL ) return( -1 );
_RWD_environ = envp;
*_RWD_environ = NULL;
_RWD_env_mask = ((char *)envp) + sizeof(char *);
*_RWD_env_mask = 0;
}
#endif
return( 0 ); /* success */
}
/programs/develop/open watcom/trunk/clib/environ/environ.c
0,0 → 1,51
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Environment pointers.
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdlib.h>
#include "rtdata.h"
#include "rtinit.h"
 
_WCRTLINKD char ** _WCNEAR environ; /* pointer to environment table */
_WCRTLINKD wchar_t ** _WCNEAR _wenviron; /* pointer to wide char environment */
char * _WCNEAR __env_mask; /* ptr to char array of flags */
 
extern void __setenvp( void );
 
AXI( __setenvp, INIT_PRIORITY_LIBRARY )
 
#if !defined(__NETWARE__) && !defined(__LINUX__)
/* Environment needs to be freed after files are shut down; __MkTmpFile()
* is used to delete temp files and needs access to environment.
*/
extern void __freeenvp( void );
AYI( __freeenvp, INIT_PRIORITY_LIBRARY - 1 )
#endif
/programs/develop/open watcom/trunk/clib/environ/filestr.h
0,0 → 1,54
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
 
 
#ifndef _FILNMTYP_H_INCLUDED
#define _FILNMTYP_H_INCLUDED
 
#include "variety.h"
#include <stddef.h>
 
 
_WCRTLINK extern char * __FormPosixHandleStr( void );
_WCRTLINK extern void __ParsePosixHandleStr( void );
 
_WCRTLINK extern wchar_t * __wFormPosixHandleStr( void );
_WCRTLINK extern void __wParsePosixHandleStr( void );
 
 
#ifdef __NT__
#define __USE_POSIX_HANDLE_STRINGS
#else
#undef __USE_POSIX_HANDLE_STRINGS
#endif
 
 
#endif
/programs/develop/open watcom/trunk/clib/environ/getenv.c
0,0 → 1,111
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Implementation of getenv().
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#include <mbstring.h>
#include <stdlib.h>
#include <string.h>
#include "rtdata.h"
#ifdef __WIDECHAR__
#include "wenviron.h"
#endif
 
#if defined(__UNIX__)
#ifdef __WIDECHAR__
#define CMP_FUNC wcsncmp
#else
#define CMP_FUNC strncmp
#endif
#else
#define CMP_FUNC _wcsnicmp
#endif
 
#if !defined(__UNIX__) && !defined(__WIDECHAR__) && !defined(__NETWARE__)
 
_WCRTLINK char *getenv( const char *name )
{
char **envp;
char *p;
 
/*** Find the environment string ***/
__ptr_check( name, 0 );
envp = _RWD_environ;
if( (envp != NULL) && (name != NULL) ) {
for( ; p = *envp; ++envp ) {
const char *s = name;
 
while( *p != '\0' ) { /* simple check is sufficient for p, not s */
if ( _mbterm( s ) ) {
if( *p == '=' ) return( p + 1 );
break;
}
if ( _mbctoupper( _mbsnextc( p ) ) != _mbctoupper( _mbsnextc( s ) ) )
break;
p = _mbsinc( p ); /* skip over character */
s = _mbsinc( s ); /* skip over character */
}
}
}
return( NULL ); /* not found */
}
 
#else
 
_WCRTLINK CHAR_TYPE *__F_NAME(getenv,_wgetenv)( const CHAR_TYPE *name )
{
#ifdef __NETWARE__
name = name;
#else
CHAR_TYPE **envp;
CHAR_TYPE *p;
int len;
 
#ifdef __WIDECHAR__
if( _RWD_wenviron == NULL ) __create_wide_environment();
#endif
 
/*** Find the environment string ***/
__ptr_check( name, 0 );
envp = __F_NAME(_RWD_environ,_RWD_wenviron);
if( (envp != NULL) && (name != NULL) ) {
len = __F_NAME(strlen,wcslen)( name );
for( ; p = *envp; ++envp ) {
if( CMP_FUNC( p, name, len ) == 0 ) {
if( p[len] == __F_NAME('=',L'=') ) return( &p[len+1] );
}
}
}
#endif
return( NULL ); /* not found */
}
 
#endif
/programs/develop/open watcom/trunk/clib/environ/gtcmd.c
0,0 → 1,85
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Multi-platform implementation of getcmd() and _bgetcmd().
*
****************************************************************************/
 
 
#include "variety.h"
#include <limits.h>
#include <ctype.h>
#include <string.h>
#if defined(__NT__)
#elif defined(__OS2__)
#endif
 
#if !defined( __NETWARE__ ) || defined( _NETWARE_LIBC )
#include <process.h>
#endif
 
extern char *_LpCmdLine;
 
_WCRTLINK int _bgetcmd( char *buffer, int len )
{
int cmdlen;
char *cmd;
char *tmp;
 
if( buffer && (len > 0) )
*buffer = '\0';
 
cmd = _LpCmdLine;
if( !cmd )
return( 0 );
 
while( *cmd == ' ' || *cmd == '\t' )
++cmd;
 
for( cmdlen = 0, tmp = cmd; *tmp; ++tmp, ++cmdlen )
;
 
if( !buffer || (len <= 0) )
return( cmdlen );
 
len--;
len = (len < cmdlen) ? len : cmdlen;
 
while( len ) {
*buffer++ = *cmd++;
--len;
}
buffer[len] = '\0';
 
return( cmdlen );
} /* _bgetcmd() */
 
 
_WCRTLINK char *getcmd( char *buffer )
{
_bgetcmd( buffer, INT_MAX );
return( buffer );
} /* getcmd() */
/programs/develop/open watcom/trunk/clib/environ/searchen.c
0,0 → 1,151
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: This function searches for the specified file in the
* 1) current directory or, failing that,
* 2) the paths listed in the specified environment variable
* until it finds the first occurrence of the file.
*
****************************************************************************/
 
 
#include "variety.h"
#include "widechar.h"
#undef __INLINE_FUNCTIONS__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef __UNIX__
#include <direct.h>
#endif
#include <string.h>
#include "rtdata.h"
#include "seterrno.h"
#ifdef __WIDECHAR__
#include "wenviron.h"
#endif
 
#if defined(__UNIX__)
#ifdef __WIDECHAR__
#define PATH_SEPARATOR L'/'
#define LIST_SEPARATOR L':'
#else
#define PATH_SEPARATOR '/'
#define LIST_SEPARATOR ':'
#endif
#else
#ifdef __WIDECHAR__
#define PATH_SEPARATOR L'\\'
#define LIST_SEPARATOR L';'
#else
#define PATH_SEPARATOR '\\'
#define LIST_SEPARATOR ';'
#endif
#endif
 
 
_WCRTLINK void __F_NAME(_searchenv,_wsearchenv)( const CHAR_TYPE *name, const CHAR_TYPE *env_var, CHAR_TYPE *buffer )
{
CHAR_TYPE *p, *p2;
int prev_errno;
size_t len;
 
#ifdef __WIDECHAR__
if( _RWD_wenviron == NULL ) __create_wide_environment();
#endif
 
prev_errno = _RWD_errno;
if( __F_NAME(access,_waccess)( name, F_OK ) == 0 ) {
p = buffer; /* JBS 90/3/30 */
len = 0; /* JBS 04/1/06 */
for( ;; ) {
if( name[0] == PATH_SEPARATOR ) break;
if( name[0] == __F_NAME('.',L'.') ) break;
#ifndef __UNIX__
if( name[0] == __F_NAME('/',L'/') ) break;
if( (name[0] != __F_NAME('\0',L'\0')) && (name[1] == __F_NAME(':',L':')) ) break;
#endif
__F_NAME(getcwd,_wgetcwd)( buffer, _MAX_PATH );
len = __F_NAME(strlen,wcslen)( buffer );
p = &buffer[ len ];
if( p[-1] != PATH_SEPARATOR ) {
if( len < (_MAX_PATH - 1) ) {
*p++ = PATH_SEPARATOR;
len++;
}
}
break;
}
*p = __F_NAME('\0',L'\0');
__F_NAME(strncat,wcsncat)( p, name, (_MAX_PATH - 1) - len );
return;
}
p = __F_NAME(getenv,_wgetenv)( env_var );
if( p != NULL ) {
for( ;; ) {
if( *p == __F_NAME('\0',L'\0') ) break;
p2 = buffer;
len = 0; /* JBS 04/1/06 */
while( *p ) {
if( *p == LIST_SEPARATOR ) break;
if( *p != __F_NAME('"',L'"') ) {
if( len < (_MAX_PATH-1) ) {
*p2++ = *p; /* JBS 00/9/29 */
len++;
}
}
p++;
}
/* check for zero-length prefix which represents CWD */
if( p2 != buffer ) { /* JBS 90/3/30 */
if( p2[-1] != PATH_SEPARATOR
#ifndef __UNIX__
&& p2[-1] != __F_NAME('/','/')
&& p2[-1] != __F_NAME(':',':')
#endif
) {
if( len < (_MAX_PATH - 1) ) {
*p2++ = PATH_SEPARATOR;
len++;
}
}
*p2 = __F_NAME('\0',L'\0');
len += __F_NAME(strlen,wcslen)( name );/* JBS 04/12/23 */
if( len < _MAX_PATH ) {
__F_NAME(strcat,wcscat)( p2, name );
/* check to see if file exists */
if( __F_NAME(access,_waccess)( buffer, 0 ) == 0 ) {
__set_errno( prev_errno );
return;
}
}
}
if( *p == '\0' ) break;
++p;
}
}
buffer[0] = __F_NAME( '\0',L'\0' );
}
/programs/develop/open watcom/trunk/clib/environ/setenvp.c
0,0 → 1,127
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: Routines to create/destroy clib copy of OS environment.
*
****************************************************************************/
 
 
#include "variety.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <env.h>
#include "liballoc.h"
#include <string.h>
#include "filestr.h"
#include "rtdata.h"
 
extern char _WCI86FAR *_Envptr;
 
static char *_free_ep;
 
#define allocate lib_malloc
 
void __setenvp( void )
{
#if defined(__NETWARE__)
// no environment support
#elif defined(__LINUX__)
#else
char _WCI86FAR *startp;
char _WCI86FAR *p;
char *ep;
char *my_env_mask;
char **my_environ;
int count;
size_t ep_size;
size_t env_size;
 
/* if we are already initialized, then return */
if( _RWD_environ != NULL ) return; /* 10-jun-90 */
 
// env_size = sys_get_environ(0,0)+1;
// _Envptr = lib_malloc(env_size);
// sys_get_environ(_Envptr, env_size)
startp = _Envptr;
count = 0;
p = startp;
while( *p ) {
while( *++p );
++count;
++p;
}
ep_size = p - startp;
if( ep_size == 0 ) {
ep_size = 1;
}
ep = (char *)allocate( ep_size );
if( ep ) {
env_size = (count + 1) * sizeof(char *) + count * sizeof(char);
my_environ = (char **)allocate( env_size );
if( my_environ ) {
_RWD_environ = my_environ;
p = startp;
_free_ep = ep;
while( *p ) {
*my_environ++ = ep;
while( *ep++ = *p++ )
;
}
*my_environ++ = NULL;
_RWD_env_mask = my_env_mask = (char *) my_environ;
for( ; count; count-- )
*my_env_mask++ = 0;
} else {
lib_free( ep );
}
}
 
/*** Handle the C_FILE_INFO entry ***/
#ifdef __USE_POSIX_HANDLE_STRINGS
// __ParsePosixHandleStr();
#endif
#endif
}
 
#if !defined(__NETWARE__) && !defined(__LINUX__)
 
void __freeenvp( void )
{
clearenv();
if( _RWD_environ ) {
lib_free( _RWD_environ );
_RWD_environ = NULL;
}
if( _free_ep ) {
lib_free( _free_ep );
_free_ep = NULL;
}
}
 
#endif