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

  1. /***
  2. *execlpe.c - execute a file with environ, search along path
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _execlpe() - execute a file with environ and search along PATH
  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 _execlpe(filename, arglist) - execute a file with environ
  21. *
  22. *Purpose:
  23. *       Executes the given file with the parameters and the environment
  24. *       which is passed after the parameters.  Searches along the PATH
  25. *       for the file (done by execvp).
  26. *
  27. *Entry:
  28. *       _TSCHAR *filename - file to execute
  29. *       _TSCHAR *arglist  - argument list (environment is at the end)
  30. *       call as _execlpe(path, arg0, arg1, ..., argn, NULL, envp);
  31. *
  32. *Exit:
  33. *       destroys the calling process (hopefully)
  34. *       if fails, returns -1
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39.  
  40. int __cdecl _texeclpe (
  41.         const _TSCHAR *filename,
  42.         const _TSCHAR *arglist,
  43.         ...
  44.         )
  45. {
  46. #ifdef _M_IX86
  47.  
  48.         REG1 const _TSCHAR **argp;
  49.  
  50.         _ASSERTE(filename != NULL);
  51.         _ASSERTE(*filename != _T('\0'));
  52.         _ASSERTE(arglist != NULL);
  53.         _ASSERTE(*arglist != _T('\0'));
  54.  
  55.         argp = &arglist;
  56.         while (*argp++)
  57.                 ;
  58.  
  59.         return(_texecvpe(filename,&arglist,(_TSCHAR **)*argp));
  60.  
  61. #else  /* _M_IX86 */
  62.  
  63.         va_list vargs;
  64.         _TSCHAR * argbuf[64];
  65.         _TSCHAR ** argv;
  66.         _TSCHAR ** envp;
  67.         int result;
  68.  
  69.         _ASSERTE(filename != NULL);
  70.         _ASSERTE(*filename != _T('\0'));
  71.         _ASSERTE(arglist != NULL);
  72.         _ASSERTE(*arglist != _T('\0'));
  73.  
  74.         va_start(vargs, arglist);
  75. #ifdef WPRFLAG
  76.         argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  77. #else  /* WPRFLAG */
  78.         argv = _capture_argv(&vargs, arglist, argbuf, 64);
  79. #endif  /* WPRFLAG */
  80.         envp = va_arg(vargs, _TSCHAR **);
  81.         va_end(vargs);
  82.  
  83.         result = _texecvpe(filename,argv,envp);
  84.         if (argv && argv != argbuf)
  85.             _free_crt(argv);
  86.         return result;
  87.  
  88. #endif  /* _M_IX86 */
  89. }
  90.