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. *spawnlpe.c - spawn a child process with environ and search along PATH
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _spawnlpe() - spawn a child process with environ/PATH search
  8. *
  9. *Revision History:
  10. * 04-15-84 DFW written
  11. * 10-29-85 TC added spawnlpe
  12. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  13. * 11-20-89 GJF Fixed copyright, alignment. Added const to arg types
  14. * for filename and arglist. #include-d PROCESS.H and
  15. * added ellipsis to match prototype.
  16. * 03-08-90 GJF Replaced _LOAD_DS with _CALLTYPE2, added #include
  17. * <cruntime.h> and removed #include <register.h>.
  18. * 07-24-90 SBM Removed redundant includes, replaced <assertm.h> by
  19. * <assert.h>
  20. * 09-27-90 GJF New-style function declarator.
  21. * 01-17-91 GJF ANSI naming.
  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 <stddef.h>
  33. #include <process.h>
  34. #include <stdarg.h>
  35. #include <internal.h>
  36. #include <malloc.h>
  37. #include <tchar.h>
  38. #include <dbgint.h>
  39. /***
  40. *int _spawnlpe(modeflag, filename, arglist) - spawn a child process
  41. *
  42. *Purpose:
  43. * Spawns a child process.
  44. * formats the parameters and calls _spawnvpe to do the work of searching
  45. * the PATH environment variable and calling _spawnve. The NULL
  46. * environment pointer indicates that the new process will inherit the
  47. * parents process's environment. NOTE - at least one argument must be
  48. * present. This argument is always, by convention, the name of the file
  49. * being spawned.
  50. *
  51. *Entry:
  52. * int modeflag - defines what mode of spawn (WAIT, NOWAIT, OVERLAY)
  53. * only WAIT and OVERLAY currently supported
  54. * _TSCHAR *pathname - file to spawn
  55. * _TSCHAR *arglist - list of arguments (environ at end)
  56. * call as _spawnlpe(modeflag, path, arg0, arg1, ..., argn, NULL, envp);
  57. *
  58. *Exit:
  59. * returns exit code of spawned process
  60. * returns -1 if fails
  61. *
  62. *Exceptions:
  63. *
  64. *******************************************************************************/
  65. intptr_t __cdecl _tspawnlpe (
  66. int modeflag,
  67. const _TSCHAR *filename,
  68. const _TSCHAR *arglist,
  69. ...
  70. )
  71. {
  72. #ifdef _M_IX86
  73. REG1 const _TSCHAR **argp;
  74. _ASSERTE(filename != NULL);
  75. _ASSERTE(*filename != _T('\0'));
  76. _ASSERTE(arglist != NULL);
  77. _ASSERTE(*arglist != _T('\0'));
  78. argp = &arglist;
  79. while (*argp++)
  80. ;
  81. return(_tspawnvpe(modeflag,filename,&arglist,(_TSCHAR **)*argp));
  82. #else /* ndef _M_IX86 */
  83. va_list vargs;
  84. _TSCHAR * argbuf[64];
  85. _TSCHAR ** argv;
  86. _TSCHAR ** envp;
  87. intptr_t result;
  88. _ASSERTE(filename != NULL);
  89. _ASSERTE(*filename != _T('\0'));
  90. _ASSERTE(arglist != NULL);
  91. _ASSERTE(*arglist != _T('\0'));
  92. va_start(vargs, arglist);
  93. #ifdef WPRFLAG
  94. argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  95. #else
  96. argv = _capture_argv(&vargs, arglist, argbuf, 64);
  97. #endif
  98. envp = va_arg(vargs, _TSCHAR **);
  99. va_end(vargs);
  100. result = _tspawnvpe(modeflag,filename,argv,envp);
  101. if (argv && argv != argbuf)
  102. _free_crt(argv);
  103. return result;
  104. #endif /* _M_IX86 */
  105. }