home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / spawno.zip / SPAWNENV.C < prev    next >
C/C++ Source or Header  |  1990-09-13  |  1KB  |  37 lines

  1. /********************************************************************/
  2. /*   SPAWNO v2.0      XMS/disk swapping replacement for spawn...()  */
  3. /*   (c) Copyright 1990 Ralf Brown  All Rights Reserved         */
  4. /*                                    */
  5. /*   May be freely copied provided that this copyright notice is    */
  6. /*   not altered or removed.                        */
  7. /********************************************************************/
  8.  
  9. #include <dos.h>
  10. #include <alloc.h>
  11. #include <string.h>
  12.  
  13. char *__spawn_env ;
  14.  
  15. int pascal __spawn_buildenv(char **env)
  16. {
  17.    int seg, i ;
  18.    char far *mem ;
  19.    unsigned int length = 1 ;          /* take trailing NUL into account */
  20.    char *e ;
  21.  
  22.    for (i = 0 ; env[i] && *env[i] ; i++)  /* add up the lengths of the variables */
  23.       length += strlen(env[i]) + 1 ;
  24.    mem = (char far *)malloc(length+15) ;  /* get enough to ensure para alignment */
  25.    __spawn_env = (char *) mem ;
  26.    seg = FP_SEG(mem) + ((FP_OFF(mem)+15)>>4) ; /* normalize into paragraph alignment */
  27.    mem = MK_FP(seg,0) ;           /* and create a normalized pointer */
  28.    while (*env && **env)          /* for each environment variable */
  29.       {
  30.       e = *env++ ;              /* copy the variable */
  31.       do {} while ((*mem++ = *e++) != 0) ;/* including the terminating NUL */
  32.       }
  33.    *mem = '\0' ;                          /* final terminating NUL */
  34.    return seg ;
  35. }
  36.  
  37.