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.

110 lines
3.5 KiB

  1. /***
  2. *spawnlp.c - spawn a file; search along PATH
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _spawnlp() - spawn a file with search along PATH
  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 and added #include
  17. * <cruntime.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. *_spawnlp(modeflag, filename, arglist) - spawn file and search along PATH
  41. *
  42. *Purpose:
  43. * Spawns a child process.
  44. * formats the parameters and calls _spawnvp 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 - mode of spawn (WAIT, NOWAIT, OVERLAY)
  53. * only WAIT, OVERLAY currently implemented
  54. * _TSCHAR *pathname - file to spawn
  55. * _TSCHAR *arglist - argument list
  56. * call as _spawnlp(modeflag, path, arg0, arg1, ..., argn, NULL);
  57. *
  58. *Exit:
  59. * returns exit code of child process
  60. * returns -1 if fails
  61. *
  62. *Exceptions:
  63. *
  64. *******************************************************************************/
  65. intptr_t __cdecl _tspawnlp (
  66. int modeflag,
  67. const _TSCHAR *filename,
  68. const _TSCHAR *arglist,
  69. ...
  70. )
  71. {
  72. #ifdef _M_IX86
  73. _ASSERTE(filename != NULL);
  74. _ASSERTE(*filename != _T('\0'));
  75. _ASSERTE(arglist != NULL);
  76. _ASSERTE(*arglist != _T('\0'));
  77. return(_tspawnvp(modeflag,filename,&arglist));
  78. #else /* ndef _M_IX86 */
  79. va_list vargs;
  80. _TSCHAR * argbuf[64];
  81. _TSCHAR ** argv;
  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. va_end(vargs);
  94. result = _tspawnvp(modeflag,filename,argv);
  95. if (argv && argv != argbuf)
  96. _free_crt(argv);
  97. return result;
  98. #endif /* _M_IX86 */
  99. }