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.

108 lines
3.4 KiB

  1. /***
  2. *spawnl.c - spawn a child process
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _spawnl() - spawn a child process
  8. *
  9. *Revision History:
  10. * 04-15-84 DFW Re-do to correspond to similar exec call format
  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 and added #include
  16. * <cruntime.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 <malloc.h>
  37. #include <tchar.h>
  38. #include <dbgint.h>
  39. /***
  40. *int _spawnl(modeflag, pathname, arglist) - spawn a child process
  41. *
  42. *Purpose:
  43. * Spawns a child process.
  44. * formats the parameters and calls spawnve to do the actual work. The
  45. * new process will inherit the parent's environment. NOTE - at least
  46. * one argument must be present. This argument is always, by convention,
  47. * the name of the file being spawned.
  48. *
  49. *Entry:
  50. * int modeflag - defines which mode of spawn (WAIT, NOWAIT, or OVERLAY)
  51. * only WAIT and OVERLAY are currently implemented
  52. * _TSCHAR *pathname - file to be spawned
  53. * _TSCHAR *arglist - list of argument
  54. * call as _spawnl(modeflag, path, arg0, arg1, ..., argn, NULL);
  55. *
  56. *Exit:
  57. * returns exit code of child process
  58. * returns -1 if fails
  59. *
  60. *Exceptions:
  61. *
  62. *******************************************************************************/
  63. intptr_t __cdecl _tspawnl (
  64. int modeflag,
  65. const _TSCHAR *pathname,
  66. const _TSCHAR *arglist,
  67. ...
  68. )
  69. {
  70. #ifdef _M_IX86
  71. _ASSERTE(pathname != NULL);
  72. _ASSERTE(*pathname != _T('\0'));
  73. _ASSERTE(arglist != NULL);
  74. _ASSERTE(*arglist != _T('\0'));
  75. return(_tspawnve(modeflag,pathname,&arglist,NULL));
  76. #else /* ndef _M_IX86 */
  77. va_list vargs;
  78. _TSCHAR * argbuf[64];
  79. _TSCHAR ** argv;
  80. intptr_t result;
  81. _ASSERTE(pathname != NULL);
  82. _ASSERTE(*pathname != _T('\0'));
  83. _ASSERTE(arglist != NULL);
  84. _ASSERTE(*arglist != _T('\0'));
  85. va_start(vargs, arglist);
  86. #ifdef WPRFLAG
  87. argv = _wcapture_argv(&vargs, arglist, argbuf, 64);
  88. #else
  89. argv = _capture_argv(&vargs, arglist, argbuf, 64);
  90. #endif
  91. va_end(vargs);
  92. result = _tspawnve(modeflag,pathname,argv,NULL);
  93. if (argv && argv != argbuf)
  94. _free_crt(argv);
  95. return result;
  96. #endif /* _M_IX86 */
  97. }