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

  1. /***
  2. *spawnl.c - spawn a child process
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _spawnl() - spawn a child process
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <stdlib.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 _spawnl(modeflag, pathname, arglist) - spawn a child process
  22. *
  23. *Purpose:
  24. *       Spawns a child process.
  25. *       formats the parameters and calls spawnve to do the actual work. The
  26. *       new process will inherit the parent's environment. NOTE - at least
  27. *       one argument must be present.  This argument is always, by convention,
  28. *       the name of the file being spawned.
  29. *
  30. *Entry:
  31. *       int modeflag   - defines which mode of spawn (WAIT, NOWAIT, or OVERLAY)
  32. *                        only WAIT and OVERLAY are currently implemented
  33. *       _TSCHAR *pathname - file to be spawned
  34. *       _TSCHAR *arglist  - list of argument
  35. *       call as _spawnl(modeflag, path, arg0, arg1, ..., argn, NULL);
  36. *
  37. *Exit:
  38. *       returns exit code of child process
  39. *       returns -1 if fails
  40. *
  41. *Exceptions:
  42. *
  43. *******************************************************************************/
  44.  
  45. int __cdecl _tspawnl (
  46.         int modeflag,
  47.         const _TSCHAR *pathname,
  48.         const _TSCHAR *arglist,
  49.         ...
  50.         )
  51. {
  52. #ifdef _M_IX86
  53.  
  54.         _ASSERTE(pathname != NULL);
  55.         _ASSERTE(*pathname != _T('\0'));
  56.         _ASSERTE(arglist != NULL);
  57.         _ASSERTE(*arglist != _T('\0'));
  58.  
  59.         return(_tspawnve(modeflag,pathname,&arglist,NULL));
  60.  
  61. #else  /* _M_IX86 */
  62.  
  63.         va_list vargs;
  64.         _TSCHAR * argbuf[64];
  65.         _TSCHAR ** argv;
  66.         int result;
  67.  
  68.         _ASSERTE(pathname != NULL);
  69.         _ASSERTE(*pathname != _T('\0'));
  70.         _ASSERTE(arglist != NULL);
  71.         _ASSERTE(*arglist != _T('\0'));
  72.  
  73.         va_start(vargs, arglist);
  74. #ifdef WPRFLAG
  75.         argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  76. #else  /* WPRFLAG */
  77.         argv = _capture_argv(&vargs, arglist, argbuf, 64);
  78. #endif  /* WPRFLAG */
  79.         va_end(vargs);
  80.  
  81.         result = _tspawnve(modeflag,pathname,argv,NULL);
  82.         if (argv && argv != argbuf)
  83.             _free_crt(argv);
  84.         return result;
  85.  
  86. #endif  /* _M_IX86 */
  87. }
  88.