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

  1. /***
  2. *execl.c - execute a file with a list of arguments
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _execl() - execute a file with a list of arguments
  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 <tchar.h>
  17. #include <dbgint.h>
  18.  
  19. /***
  20. *int _execl(filename, arglist) - execute a file with arg list
  21. *
  22. *Purpose:
  23. *       Transform the argument list so it is a vector, then pass its address
  24. *       to execve.  Use a pointer to the default environment vector.
  25. *
  26. *Entry:
  27. *       _TSCHAR *filename - file to execute
  28. *       _TSCHAR *arglist  - list of arguments
  29. *       call as _execl(path, arg0, arg1, ..., argn, NULL);
  30. *
  31. *Exit:
  32. *       destroys the calling process, hopefully
  33. *       returns -1 if fails
  34. *
  35. *Exceptions:
  36. *
  37. *******************************************************************************/
  38.  
  39. int __cdecl _texecl (
  40.         const _TSCHAR *filename,
  41.         const _TSCHAR *arglist,
  42.         ...
  43.         )
  44. {
  45. #ifdef _M_IX86
  46.  
  47.         _ASSERTE(filename != NULL);
  48.         _ASSERTE(*filename != _T('\0'));
  49.         _ASSERTE(arglist != NULL);
  50.         _ASSERTE(*arglist != _T('\0'));
  51.  
  52.         return(_texecve(filename,&arglist,NULL));
  53.  
  54. #else  /* _M_IX86 */
  55.  
  56.         va_list vargs;
  57.         _TSCHAR * argbuf[64];
  58.         _TSCHAR ** argv;
  59.         int result;
  60.  
  61.         _ASSERTE(filename != NULL);
  62.         _ASSERTE(*filename != _T('\0'));
  63.         _ASSERTE(arglist != NULL);
  64.         _ASSERTE(*arglist != _T('\0'));
  65.  
  66.         va_start(vargs, arglist);
  67. #ifdef WPRFLAG
  68.         argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  69. #else  /* WPRFLAG */
  70.         argv = _capture_argv(&vargs, arglist, argbuf, 64);
  71. #endif  /* WPRFLAG */
  72.         va_end(vargs);
  73.  
  74.         result = _texecve(filename,argv,NULL);
  75.         if (argv && argv != argbuf)
  76.             _free_crt(argv);
  77.         return result;
  78.  
  79. #endif  /* _M_IX86 */
  80. }
  81.