home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / SETENVP2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.0 KB  |  55 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - setenvp2.c   Prepare Program arguments vectors
  3.  *
  4.  *-----------------------------------------------------------------------*/
  5.  
  6. /*[]------------------------------------------------------------[]*/
  7. /*|                                                              |*/
  8. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  9. /*|                                                              |*/
  10. /*|                                                              |*/
  11. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  12. /*|     All Rights Reserved.                                     |*/
  13. /*|                                                              |*/
  14. /*[]------------------------------------------------------------[]*/
  15.  
  16. #ifdef   __OS2__
  17. #include <mem.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <dos.h>
  21.  
  22. extern int _envLng;        /* Environment length (in startup) */
  23. extern int _envseg;        /* Environment segment(in startup) */
  24. extern int _envSize;        /* # of strings in Environment       */
  25.  
  26. #define    EXTRA    4        /* # of extra envp slots to include*/
  27.  
  28. void _setenvp(void)
  29. {
  30.     int    i;
  31.     char    *evBlock;
  32.  
  33.     /*
  34.       Get block to hold strings, copy the strings to the local block.
  35.       Get a block to hold the envp array pointers.    We'll get a 
  36.       block large enough to hold 4 more pointers than there currently
  37.       are.  This way minor additions can be made to the environment
  38.       without having to realloc the pointer array each time.
  39.       Fill in array of pointers with the addresses of the strings.
  40.       Make _envSize reflect how many slots there are now.
  41.     */
  42.     if ((evBlock = malloc(_envLng)) == NULL)
  43.         abort();
  44.     movedata(_envseg, 0, 
  45.         FP_SEG((char far *)evBlock), FP_OFF((char far *)evBlock),
  46.         _envLng
  47.         );
  48.     if ((environ = (char **)calloc(_envSize+EXTRA,sizeof(char *))) == NULL)
  49.         abort();
  50.     for (i=0; i<_envSize; i++, evBlock+=(strlen(evBlock)+1))
  51.         environ[i] = evBlock;
  52.     _envSize += EXTRA;
  53. }
  54. #endif
  55.