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

  1. /***
  2. *execlp.c - execute a file (search along PATH)
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _execlp() - execute a file and 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. *int _execlp(filename, arglist) - execute a file, search along PATH
  22. *
  23. *Purpose:
  24. *       Execute the given file with the given arguments; search along PATH
  25. *       for the file. We pass the arguments to execvp where several paths
  26. *       will be tried until one works.
  27. *
  28. *Entry:
  29. *       _TSCHAR *filename - file to execute
  30. *       _TSCHAR *arglist  - argument list
  31. *       call as _execlp(path, arg0, arg1, ..., argn, NULL);
  32. *
  33. *Exit:
  34. *       destroys calling process (hopefully)
  35. *       returns -1 if fails.
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40.  
  41. int __cdecl _texeclp (
  42.         const _TSCHAR *filename,
  43.         const _TSCHAR *arglist,
  44.         ...
  45.         )
  46. {
  47. #ifdef _M_IX86
  48.  
  49.         _ASSERTE(filename != NULL);
  50.         _ASSERTE(*filename != _T('\0'));
  51.         _ASSERTE(arglist != NULL);
  52.         _ASSERTE(*arglist != _T('\0'));
  53.  
  54.         return(_texecvp(filename,&arglist));
  55.  
  56. #else  /* _M_IX86 */
  57.  
  58.         va_list vargs;
  59.         _TSCHAR * argbuf[64];
  60.         _TSCHAR ** argv;
  61.         int result;
  62.  
  63.         _ASSERTE(filename != NULL);
  64.         _ASSERTE(*filename != _T('\0'));
  65.         _ASSERTE(arglist != NULL);
  66.         _ASSERTE(*arglist != _T('\0'));
  67.  
  68.         va_start(vargs, arglist);
  69. #ifdef WPRFLAG
  70.         argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  71. #else  /* WPRFLAG */
  72.         argv = _capture_argv(&vargs, arglist, argbuf, 64);
  73. #endif  /* WPRFLAG */
  74.         va_end(vargs);
  75.  
  76.         result = _texecvp(filename,argbuf);
  77.         if (argv && argv != argbuf)
  78.             _free_crt(argv);
  79.         return result;
  80.  
  81. #endif  /* _M_IX86 */
  82. }
  83.