home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / spawnlpe.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  98 lines

  1. /***
  2. *spawnlpe.c - spawn a child process with environ and search along PATH
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _spawnlpe() - spawn a child process with environ/PATH search
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <stddef.h>
  13. #include <process.h>
  14. #include <stdarg.h>
  15. #include <internal.h>
  16. #include <malloc.h>
  17. #include <tchar.h>
  18. #include <dbgint.h>
  19.  
  20. /***
  21. *int _spawnlpe(modeflag, filename, arglist) - spawn a child process
  22. *
  23. *Purpose:
  24. *       Spawns a child process.
  25. *       formats the parameters and calls _spawnvpe to do the work of searching
  26. *       the PATH environment variable and calling _spawnve.  The NULL
  27. *       environment pointer indicates that the new process will inherit the
  28. *       parents process's environment.  NOTE - at least one argument must be
  29. *       present.  This argument is always, by convention, the name of the file
  30. *       being spawned.
  31. *
  32. *Entry:
  33. *       int modeflag   - defines what mode of spawn (WAIT, NOWAIT, OVERLAY)
  34. *                        only WAIT and OVERLAY currently supported
  35. *       _TSCHAR *pathname - file to spawn
  36. *       _TSCHAR *arglist  - list of arguments (environ at end)
  37. *       call as _spawnlpe(modeflag, path, arg0, arg1, ..., argn, NULL, envp);
  38. *
  39. *Exit:
  40. *       returns exit code of spawned process
  41. *       returns -1 if fails
  42. *
  43. *Exceptions:
  44. *
  45. *******************************************************************************/
  46.  
  47. int __cdecl _tspawnlpe (
  48.         int modeflag,
  49.         const _TSCHAR *filename,
  50.         const _TSCHAR *arglist,
  51.         ...
  52.         )
  53. {
  54. #ifdef _M_IX86
  55.  
  56.         REG1 const _TSCHAR **argp;
  57.  
  58.         _ASSERTE(filename != NULL);
  59.         _ASSERTE(*filename != _T('\0'));
  60.         _ASSERTE(arglist != NULL);
  61.         _ASSERTE(*arglist != _T('\0'));
  62.  
  63.         argp = &arglist;
  64.         while (*argp++)
  65.                 ;
  66.  
  67.         return(_tspawnvpe(modeflag,filename,&arglist,(_TSCHAR **)*argp));
  68.  
  69. #else  /* _M_IX86 */
  70.  
  71.         va_list vargs;
  72.         _TSCHAR * argbuf[64];
  73.         _TSCHAR ** argv;
  74.         _TSCHAR ** envp;
  75.         int result;
  76.  
  77.         _ASSERTE(filename != NULL);
  78.         _ASSERTE(*filename != _T('\0'));
  79.         _ASSERTE(arglist != NULL);
  80.         _ASSERTE(*arglist != _T('\0'));
  81.  
  82.         va_start(vargs, arglist);
  83. #ifdef WPRFLAG
  84.         argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  85. #else  /* WPRFLAG */
  86.         argv = _capture_argv(&vargs, arglist, argbuf, 64);
  87. #endif  /* WPRFLAG */
  88.         envp = va_arg(vargs, _TSCHAR **);
  89.         va_end(vargs);
  90.  
  91.         result = _tspawnvpe(modeflag,filename,argv,envp);
  92.         if (argv && argv != argbuf)
  93.             _free_crt(argv);
  94.         return result;
  95.  
  96. #endif  /* _M_IX86 */
  97. }
  98.