home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / WINLBSRC.ZIP / SETENV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.5 KB  |  58 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - setenv.c
  3.  *
  4.  * function(s)
  5.  *        _setenv - initializes global RTL environment variables
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16. #include <windows.h>
  17. #include <dos.h>
  18.  
  19. #pragma warn -use
  20.  
  21. unsigned _envseg = 0;   /* Environment length               */
  22. unsigned _envLng = 0;   /* Environment segment              */
  23. unsigned _envSize= 0;   /* # of strings in Environment * sizeof(char *) */
  24.  
  25. /*----------------------------------------------------------------------*
  26.  
  27. Name            _setenv - Initializes global RTL environment variables.
  28.  
  29. Usage           Is executed when any reference to these variables causes
  30.                 this module to be linked in.
  31.  
  32. Description     Initializes the global variables _envseg, _envLng,
  33.                 and _envSize.
  34.  
  35. *-----------------------------------------------------------------------*/
  36. static void _setenv(void)
  37. {
  38.     char far *envptr;
  39.     int count;
  40.  
  41.     envptr = GetDOSEnvironment();
  42.  
  43.     count = 0;
  44.     while (1)
  45.         {
  46.         _envSize++;
  47.         while(envptr[count++])
  48.             ;
  49.         if (!envptr[count])
  50.             break;
  51.         }
  52.     _envSize*= sizeof(char *);
  53.     _envLng = count+1;   /* length includes both NULL bytes */
  54.     _envseg = FP_SEG(envptr);
  55. }
  56.  
  57. #pragma startup _setenv 8
  58.