Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  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:  Routines to create/destroy clib copy of OS environment.
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include <stdio.h>
  34. #include <stddef.h>
  35. #include <stdlib.h>
  36. #include <env.h>
  37. #include "liballoc.h"
  38. #include <string.h>
  39. #include "filestr.h"
  40. #include "rtdata.h"
  41.  
  42. extern char _WCI86FAR *_Envptr;
  43.  
  44. static char *_free_ep;
  45.  
  46. #define allocate lib_malloc
  47.  
  48. void __setenvp( void )
  49. {
  50. #if defined(__NETWARE__)
  51.     // no environment support
  52. #elif defined(__LINUX__)
  53. #else
  54.     char        _WCI86FAR *startp;
  55.     char        _WCI86FAR *p;
  56.     char    *ep;
  57.     char    *my_env_mask;
  58.     char    **my_environ;
  59.     int     count;
  60.     size_t  ep_size;
  61.     size_t  env_size;
  62.  
  63.     /* if we are already initialized, then return */
  64.     if( _RWD_environ != NULL ) return;           /* 10-jun-90 */
  65.  
  66.     // env_size = sys_get_environ(0,0)+1;
  67.     // _Envptr = lib_malloc(env_size);
  68.     // sys_get_environ(_Envptr, env_size)
  69.    
  70.     startp = _Envptr;
  71.    
  72.     count = 0;
  73.     p = startp;
  74.     while( *p ) {
  75.         while( *++p );
  76.         ++count;
  77.         ++p;
  78.     }
  79.     ep_size = p - startp;
  80.     if( ep_size == 0 ) {
  81.         ep_size = 1;
  82.     }
  83.     ep = (char *)allocate( ep_size );
  84.     if( ep ) {
  85.         env_size = (count + 1) * sizeof(char *) + count * sizeof(char);
  86.         my_environ = (char **)allocate( env_size );
  87.         if( my_environ ) {
  88.             _RWD_environ = my_environ;
  89.             p = startp;
  90.             _free_ep = ep;
  91.             while( *p ) {
  92.                 *my_environ++ = ep;
  93.                 while( *ep++ = *p++ )
  94.                     ;
  95.             }
  96.             *my_environ++ = NULL;
  97.             _RWD_env_mask = my_env_mask = (char *) my_environ;
  98.             for( ; count; count-- )
  99.                 *my_env_mask++ = 0;
  100.         } else {
  101.             lib_free( ep );
  102.         }
  103.     }
  104.  
  105.     /*** Handle the C_FILE_INFO entry ***/
  106.     #ifdef __USE_POSIX_HANDLE_STRINGS
  107.  //       __ParsePosixHandleStr();
  108.     #endif
  109. #endif
  110. }
  111.  
  112. #if !defined(__NETWARE__) && !defined(__LINUX__)
  113.  
  114. void __freeenvp( void )
  115. {
  116.     clearenv();
  117.     if( _RWD_environ ) {
  118.         lib_free( _RWD_environ );
  119.         _RWD_environ = NULL;
  120.     }
  121.     if( _free_ep ) {
  122.         lib_free( _free_ep );
  123.         _free_ep = NULL;
  124.     }
  125. }
  126.  
  127. #endif
  128.