Leaked source code of windows server 2003
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.

113 lines
3.5 KiB

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