Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.0 KiB

  1. /***
  2. *execlp.c - execute a file (search along PATH)
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _execlp() - execute a file and search along PATH
  8. *
  9. *Revision History:
  10. * 10-17-83 RN written
  11. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  12. * 11-20-89 GJF Fixed copyright, indents. Added const attribute to
  13. * types of filename and arglist. #include-d PROCESS.H
  14. * and added ellipsis to match prototype.
  15. * 03-08-90 GJF Replaced _LOAD_DS with _CALLTYPE2, added #include
  16. * <cruntime.h> and removed #include <register.h>.
  17. * 07-24-90 SBM Removed redundant includes, replaced <assertm.h> by
  18. * <assert.h>
  19. * 09-27-90 GJF New-style function declarator.
  20. * 01-17-91 GJF ANSI naming.
  21. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  22. * 07-16-93 SRW ALPHA Merge
  23. * 08-31-93 GJF Merged NT SDK and Cuda versions
  24. * 12-07-93 CFW Wide char enable.
  25. * 01-10-95 CFW Debug CRT allocs.
  26. * 02-06-95 CFW assert -> _ASSERTE.
  27. * 02-06-98 GJF Changes for Win64: changed return type to intptr_t.
  28. *
  29. *******************************************************************************/
  30. #include <cruntime.h>
  31. #include <stddef.h>
  32. #include <process.h>
  33. #include <stdarg.h>
  34. #include <internal.h>
  35. #include <malloc.h>
  36. #include <tchar.h>
  37. #include <dbgint.h>
  38. /***
  39. *int _execlp(filename, arglist) - execute a file, search along PATH
  40. *
  41. *Purpose:
  42. * Execute the given file with the given arguments; search along PATH
  43. * for the file. We pass the arguments to execvp where several paths
  44. * will be tried until one works.
  45. *
  46. *Entry:
  47. * _TSCHAR *filename - file to execute
  48. * _TSCHAR *arglist - argument list
  49. * call as _execlp(path, arg0, arg1, ..., argn, NULL);
  50. *
  51. *Exit:
  52. * destroys calling process (hopefully)
  53. * returns -1 if fails.
  54. *
  55. *Exceptions:
  56. *
  57. *******************************************************************************/
  58. intptr_t __cdecl _texeclp (
  59. const _TSCHAR *filename,
  60. const _TSCHAR *arglist,
  61. ...
  62. )
  63. {
  64. #ifdef _M_IX86
  65. _ASSERTE(filename != NULL);
  66. _ASSERTE(*filename != _T('\0'));
  67. _ASSERTE(arglist != NULL);
  68. _ASSERTE(*arglist != _T('\0'));
  69. return(_texecvp(filename,&arglist));
  70. #else /* ndef_M_IX86 */
  71. va_list vargs;
  72. _TSCHAR * argbuf[64];
  73. _TSCHAR ** argv;
  74. intptr_t result;
  75. _ASSERTE(filename != NULL);
  76. _ASSERTE(*filename != _T('\0'));
  77. _ASSERTE(arglist != NULL);
  78. _ASSERTE(*arglist != _T('\0'));
  79. va_start(vargs, arglist);
  80. #ifdef WPRFLAG
  81. argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  82. #else
  83. argv = _capture_argv(&vargs, arglist, argbuf, 64);
  84. #endif
  85. va_end(vargs);
  86. result = _texecvp(filename,argbuf);
  87. if (argv && argv != argbuf)
  88. _free_crt(argv);
  89. return result;
  90. #endif /* _M_IX86 */
  91. }