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.

101 lines
3.0 KiB

  1. /***
  2. *execl.c - execute a file with a list of arguments
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _execl() - execute a file with a list of arguments
  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. * 02-14-90 SRW Use NULL instead of _environ to get default.
  22. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  23. * 07-16-93 SRW ALPHA Merge
  24. * 08-31-93 GJF Merged NT SDK and Cuda versions
  25. * 12-07-93 CFW Wide char enable.
  26. * 01-10-95 CFW Debug CRT allocs.
  27. * 02-06-95 CFW assert -> _ASSERTE.
  28. * 02-06-98 GJF Changes for Win64: changed return type to intptr_t.
  29. *
  30. *******************************************************************************/
  31. #include <cruntime.h>
  32. #include <stdlib.h>
  33. #include <process.h>
  34. #include <stdarg.h>
  35. #include <internal.h>
  36. #include <tchar.h>
  37. #include <dbgint.h>
  38. /***
  39. *int _execl(filename, arglist) - execute a file with arg list
  40. *
  41. *Purpose:
  42. * Transform the argument list so it is a vector, then pass its address
  43. * to execve. Use a pointer to the default environment vector.
  44. *
  45. *Entry:
  46. * _TSCHAR *filename - file to execute
  47. * _TSCHAR *arglist - list of arguments
  48. * call as _execl(path, arg0, arg1, ..., argn, NULL);
  49. *
  50. *Exit:
  51. * destroys the calling process, hopefully
  52. * returns -1 if fails
  53. *
  54. *Exceptions:
  55. *
  56. *******************************************************************************/
  57. intptr_t __cdecl _texecl (
  58. const _TSCHAR *filename,
  59. const _TSCHAR *arglist,
  60. ...
  61. )
  62. {
  63. #ifdef _M_IX86
  64. _ASSERTE(filename != NULL);
  65. _ASSERTE(*filename != _T('\0'));
  66. _ASSERTE(arglist != NULL);
  67. _ASSERTE(*arglist != _T('\0'));
  68. return(_texecve(filename,&arglist,NULL));
  69. #else /* ndef _M_IX86 */
  70. va_list vargs;
  71. _TSCHAR * argbuf[64];
  72. _TSCHAR ** argv;
  73. intptr_t result;
  74. _ASSERTE(filename != NULL);
  75. _ASSERTE(*filename != _T('\0'));
  76. _ASSERTE(arglist != NULL);
  77. _ASSERTE(*arglist != _T('\0'));
  78. va_start(vargs, arglist);
  79. #ifdef WPRFLAG
  80. argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  81. #else
  82. argv = _capture_argv(&vargs, arglist, argbuf, 64);
  83. #endif
  84. va_end(vargs);
  85. result = _texecve(filename,argv,NULL);
  86. if (argv && argv != argbuf)
  87. _free_crt(argv);
  88. return result;
  89. #endif /* _M_IX86 */
  90. }