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.

118 lines
3.8 KiB

  1. /***
  2. *spawnle.c - spawn a child process with given environment
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _spawnle() - spawn a child process with given environ
  8. *
  9. *Revision History:
  10. * 04-15-84 DFW written
  11. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  12. * 11-20-89 GJF Fixed copyright, alignment. Added const to arg types
  13. * for pathname and arglist. #include-d PROCESS.H and
  14. * 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 _spawnle(modeflag, pathname, arglist) - spawn a child process with env.
  40. *
  41. *Purpose:
  42. * Spawns a child process with given parameters and environment.
  43. * formats the parameters and calls _spawnve to do the actual work.
  44. * NOTE - at least one argument must be present. This argument is always,
  45. * by convention, the name of the file being spawned.
  46. *
  47. *Entry:
  48. * int modeflag - mode of spawn (WAIT, NOWAIT, OVERLAY)
  49. * only WAIT, and OVERLAY currently implemented
  50. * _TSCHAR *pathname - name of file to spawn
  51. * _TSCHAR *arglist - argument list, environment is at the end
  52. * call as _spawnle(modeflag, path, arg0, arg1, ..., argn, NULL, envp);
  53. *
  54. *Exit:
  55. * returns exit code of spawned process
  56. * if fails, return -1
  57. *
  58. *Exceptions:
  59. *
  60. *******************************************************************************/
  61. intptr_t __cdecl _tspawnle (
  62. int modeflag,
  63. const _TSCHAR *pathname,
  64. const _TSCHAR *arglist,
  65. ...
  66. )
  67. {
  68. #ifdef _M_IX86
  69. REG1 const _TSCHAR **argp;
  70. _ASSERTE(pathname != NULL);
  71. _ASSERTE(*pathname != _T('\0'));
  72. _ASSERTE(arglist != NULL);
  73. _ASSERTE(*arglist != _T('\0'));
  74. /* walk the arglist until the terminating NULL pointer is found. The
  75. * next location holds the environment table pointer.
  76. */
  77. argp = &arglist;
  78. while (*argp++)
  79. ;
  80. return(_tspawnve(modeflag,pathname,&arglist,(_TSCHAR **)*argp));
  81. #else /* ndef _M_IX86 */
  82. va_list vargs;
  83. _TSCHAR * argbuf[64];
  84. _TSCHAR ** argv;
  85. _TSCHAR ** envp;
  86. intptr_t result;
  87. _ASSERTE(pathname != NULL);
  88. _ASSERTE(*pathname != _T('\0'));
  89. _ASSERTE(arglist != NULL);
  90. _ASSERTE(*arglist != _T('\0'));
  91. va_start(vargs, arglist);
  92. #ifdef WPRFLAG
  93. argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  94. #else
  95. argv = _capture_argv(&vargs, arglist, argbuf, 64);
  96. #endif
  97. envp = va_arg(vargs, _TSCHAR **);
  98. va_end(vargs);
  99. result = _tspawnve(modeflag,pathname,argv,envp);
  100. if (argv && argv != argbuf)
  101. _free_crt(argv);
  102. return result;
  103. #endif /* _M_IX86 */
  104. }