Copy the correct number of bytes.
[reactos.git] / reactos / lib / crt / process / process.c
index 00ead39..2ba21df 100644 (file)
@@ -1,9 +1,5 @@
-#include "precomp.h"
+#include <precomp.h>
 #include <process.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <internal/file.h>
 #include <tchar.h>
 
 #define NDEBUG
@@ -14,7 +10,7 @@
    #define argvtosT argvtosW
    #define do_spawnT do_spawnW
    #define valisttosT valisttosW
-   #define extT extW   
+   #define extT extW
 #else
    #define find_execT find_execA
    #define argvtosT argvtosA
@@ -37,7 +33,7 @@ const _TCHAR* find_execT(const _TCHAR* path, _TCHAR* rpath)
 {
    _TCHAR *rp;
    const _TCHAR *rd;
-   int i, found = 0;
+   unsigned int i, found = 0;
 
    DPRINT(MK_STR(find_execT)"('%"sT"', %x)\n", path, rpath);
 
@@ -130,7 +126,7 @@ argvtosT(const _TCHAR* const* argv, _TCHAR delim)
    for(i = 0; argv[i]; i++)
    {
       len = _tcslen(argv[i]);
-      memcpy(ptr, argv[i], len);
+      memcpy(ptr, argv[i], len * sizeof(_TCHAR));
       ptr += len;
       *ptr++ = delim;
    }
@@ -166,7 +162,7 @@ valisttosT(const _TCHAR* arg0, va_list alist, _TCHAR delim)
    do
    {
       len = _tcslen(arg0);
-      memcpy(ptr, arg0, len);
+      memcpy(ptr, arg0, len * sizeof(_TCHAR));
       ptr += len;
       *ptr++ = delim;
       arg0 = va_arg(alist2, _TCHAR*);
@@ -190,7 +186,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
    DWORD dwError;
 
    TRACE(MK_STR(do_spawnT)"(%i,'%"sT"','%"sT"','%"sT"')",mode,cmdname,args,envp);
-   
+
 
    if (mode != _P_NOWAIT && mode != _P_NOWAITO && mode != _P_WAIT && mode != _P_DETACH && mode != _P_OVERLAY)
    {
@@ -208,10 +204,10 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
       __set_errno ( EISDIR );
       return(-1);
    }
-   
+
    //memset (&StartupInfo, 0, sizeof(StartupInfo));
    StartupInfo.cb = sizeof(StartupInfo);
-   
+
 #if 0
 
    for (last = i = 0; i < FDINFO_FD_MAX; i++)
@@ -240,7 +236,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
          int _mode = __fileno_getmode(i);
          HANDLE h = _get_osfhandle(i);
          /* FIXME: The test of console handles (((ULONG)Handle) & 0x10000003) == 0x3)
-          *        is possible wrong 
+          *        is possible wrong
           */
          if ((((ULONG)h) & 0x10000003) == 0x3 || _mode & _O_NOINHERIT || (i < 3 && mode == _P_DETACH))
          {
@@ -270,7 +266,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
 #endif
 
    create_io_inherit_block((STARTUPINFOA*) &StartupInfo);
-   
+
    bResult = CreateProcess((_TCHAR *)cmdname,
                             (_TCHAR *)args,
                             NULL,
@@ -281,7 +277,7 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
                             NULL,
                             &StartupInfo,
                             &ProcessInformation);
-                            
+
    if (StartupInfo.lpReserved2)
    {
       free(StartupInfo.lpReserved2);
@@ -299,19 +295,17 @@ do_spawnT(int mode, const _TCHAR* cmdname, const _TCHAR* args, const _TCHAR* env
    {
       case _P_NOWAIT:
       case _P_NOWAITO:
-         CloseHandle(ProcessInformation.hThread);
          return((int)ProcessInformation.hProcess);
       case _P_OVERLAY:
+         CloseHandle(ProcessInformation.hProcess);
          _exit(0);
       case _P_WAIT:
          WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
          GetExitCodeProcess(ProcessInformation.hProcess, &dwExitCode);
          CloseHandle(ProcessInformation.hProcess);
-         CloseHandle(ProcessInformation.hThread);
          return( (int)dwExitCode); //CORRECT?
       case _P_DETACH:
          CloseHandle(ProcessInformation.hProcess);
-         CloseHandle(ProcessInformation.hThread);
          return( 0);
    }
    return( (int)ProcessInformation.hProcess);