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

  1. /***
  2. *spawnlp.c - spawn a file; search along PATH
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _spawnlp() - spawn a file with search along PATH
  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. *_spawnlp(modeflag, filename, arglist) - spawn file and search along PATH
  22. *
  23. *Purpose:
  24. *       Spawns a child process.
  25. *       formats the parameters and calls _spawnvp 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   - mode of spawn (WAIT, NOWAIT, OVERLAY)
  34. *                        only WAIT, OVERLAY currently implemented
  35. *       _TSCHAR *pathname - file to spawn
  36. *       _TSCHAR *arglist  - argument list
  37. *       call as _spawnlp(modeflag, path, arg0, arg1, ..., argn, NULL);
  38. *
  39. *Exit:
  40. *       returns exit code of child process
  41. *       returns -1 if fails
  42. *
  43. *Exceptions:
  44. *
  45. *******************************************************************************/
  46.  
  47. int __cdecl _tspawnlp (
  48.         int modeflag,
  49.         const _TSCHAR *filename,
  50.         const _TSCHAR *arglist,
  51.         ...
  52.         )
  53. {
  54. #ifdef _M_IX86
  55.  
  56.         _ASSERTE(filename != NULL);
  57.         _ASSERTE(*filename != _T('\0'));
  58.         _ASSERTE(arglist != NULL);
  59.         _ASSERTE(*arglist != _T('\0'));
  60.  
  61.         return(_tspawnvp(modeflag,filename,&arglist));
  62.  
  63. #else  /* _M_IX86 */
  64.  
  65.         va_list vargs;
  66.         _TSCHAR * argbuf[64];
  67.         _TSCHAR ** argv;
  68.         int result;
  69.  
  70.         _ASSERTE(filename != NULL);
  71.         _ASSERTE(*filename != _T('\0'));
  72.         _ASSERTE(arglist != NULL);
  73.         _ASSERTE(*arglist != _T('\0'));
  74.  
  75.         va_start(vargs, arglist);
  76. #ifdef WPRFLAG
  77.         argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  78. #else  /* WPRFLAG */
  79.         argv = _capture_argv(&vargs, arglist, argbuf, 64);
  80. #endif  /* WPRFLAG */
  81.         va_end(vargs);
  82.  
  83.         result = _tspawnvp(modeflag,filename,argv);
  84.         if (argv && argv != argbuf)
  85.             _free_crt(argv);
  86.         return result;
  87.  
  88. #endif  /* _M_IX86 */
  89. }
  90.