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.

109 lines
3.2 KiB

  1. /***
  2. *execle.c - execute a file with arg list and environment
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _execle() - execute a file
  8. *
  9. *Revision History:
  10. * 10-14-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 _execle(filename, arglist) - execute a file
  40. *
  41. *Purpose:
  42. * Execute the given file (overlays the calling process).
  43. * We must dig the environment vector out of the stack and pass it
  44. * and address of argument vector to execve.
  45. *
  46. *Entry:
  47. * _TSCHAR *filename - file to execute
  48. * _TSCHAR *arglist - argument list followed by environment
  49. * should be called like _execle(path, arg0, arg1, ..., argn, NULL, envp);
  50. *
  51. *Exit:
  52. * destroys calling process (hopefully)
  53. * if fails, returns -1.
  54. *
  55. *Exceptions:
  56. *
  57. *******************************************************************************/
  58. intptr_t __cdecl _texecle (
  59. const _TSCHAR *filename,
  60. const _TSCHAR *arglist,
  61. ...
  62. )
  63. {
  64. #ifdef _M_IX86
  65. REG1 const _TSCHAR **e_search = &arglist;
  66. _ASSERTE(filename != NULL);
  67. _ASSERTE(*filename != _T('\0'));
  68. _ASSERTE(arglist != NULL);
  69. _ASSERTE(*arglist != _T('\0'));
  70. while (*e_search++)
  71. ;
  72. return(_texecve(filename,&arglist,(_TSCHAR **)*e_search));
  73. #else /* ndef _M_IX86 */
  74. va_list vargs;
  75. _TSCHAR * argbuf[64];
  76. _TSCHAR ** argv;
  77. _TSCHAR ** envp;
  78. intptr_t result;
  79. _ASSERTE(filename != NULL);
  80. _ASSERTE(*filename != _T('\0'));
  81. _ASSERTE(arglist != NULL);
  82. _ASSERTE(*arglist != _T('\0'));
  83. va_start(vargs, arglist);
  84. #ifdef WPRFLAG
  85. argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  86. #else
  87. argv = _capture_argv(&vargs, arglist, argbuf, 64);
  88. #endif
  89. envp = va_arg(vargs, _TSCHAR **);
  90. va_end(vargs);
  91. result = _texecve(filename,argv,envp);
  92. if (argv && argv != argbuf)
  93. _free_crt(argv);
  94. return result;
  95. #endif /* _M_IX86 */
  96. }