From: Rolf K. <lab...@us...> - 2005-06-05 21:12:02
|
Update of /cvsroot/opengtoolkit/pipe/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31563/c_source Modified Files: pipes.c Log Message: Comitting various minor fixes Index: pipes.c =================================================================== RCS file: /cvsroot/opengtoolkit/pipe/c_source/pipes.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pipes.c 18 Sep 2004 21:35:50 -0000 1.8 --- pipes.c 5 Jun 2005 21:11:39 -0000 1.9 *************** *** 42,47 **** } Modes; ! MgErr LibAPI PipeOpen(CStr name, uInt8 mode, uInt32 *fd); ! MgErr LibAPI PipeOpenCmd(CStr name, uInt8 mode, uInt32 *fdIn, uInt32 *fdOut, uInt32 *fdErr, uInt32 *processID); MgErr LibAPI PipeClose(uInt32 fd); --- 42,47 ---- } Modes; ! MgErr LibAPI PipeOpen(CStr name, uInt16 mode, uInt32 *fd); ! MgErr LibAPI PipeOpenCmd(CStr name, uInt16 mode, uInt32 *fdIn, uInt32 *fdOut, uInt32 *fdErr, uInt32 *processID); MgErr LibAPI PipeClose(uInt32 fd); *************** *** 50,54 **** #if defined(MSWin) ! static MgErr CreateChildProcess(LPSTR cmdline, HANDLE *pid); static MgErr Win32ToLVErr(DWORD error); #elif defined (Unix) --- 50,54 ---- #if defined(MSWin) ! static MgErr CreateChildProcess(LPSTR cmdline, DWORD *pid); static MgErr Win32ToLVErr(DWORD error); #elif defined (Unix) *************** *** 58,62 **** #endif ! MgErr LibAPI PipeOpen(CStr name, uInt8 mode, uInt32 *fd) { MgErr err = noErr; --- 58,62 ---- #endif ! MgErr LibAPI PipeOpen(CStr name, uInt16 mode, uInt32 *fd) { MgErr err = noErr; *************** *** 157,163 **** } ! MgErr LibAPI PipeOpenCmd(CStr cmd, uInt8 mode, uInt32 *fdIn, uInt32 *fdOut, uInt32 *fdErr, uInt32 *processID) { MgErr err = noErr; #if defined(MSWin) SECURITY_ATTRIBUTES saAttr = { 0 }; --- 157,164 ---- } ! MgErr LibAPI PipeOpenCmd(CStr cmd, uInt16 mode, uInt32 *fdIn, uInt32 *fdOut, uInt32 *fdErr, uInt32 *processID) { MgErr err = noErr; + uInt32 retErr = fdErr ? *fdErr : 0; #if defined(MSWin) SECURITY_ATTRIBUTES saAttr = { 0 }; *************** *** 165,174 **** HANDLE hSaveStdin = 0L, hChildStdinRd = 0L, hChildStdinWr = 0L; HANDLE hSaveStderr = 0L, hChildStderrRd = 0L, hChildStderrWr = 0L; - BOOL bError = *fdErr != FALSE; if (mode > kReadWriteMode) return mgArgErr; ! *fdIn = *fdOut = *fdErr = 0; DebugBreaking(); --- 166,176 ---- HANDLE hSaveStdin = 0L, hChildStdinRd = 0L, hChildStdinWr = 0L; HANDLE hSaveStderr = 0L, hChildStderrRd = 0L, hChildStderrWr = 0L; if (mode > kReadWriteMode) return mgArgErr; ! *fdIn = 0; ! *fdOut = 0; ! *fdErr = 0; DebugBreaking(); *************** *** 192,199 **** /* Create noninheritable read handle and close the inheritable read handle. */ ! if (!DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, ! GetCurrentProcess(), (HANDLE*)fdOut , 0, ! FALSE, ! DUPLICATE_SAME_ACCESS)) goto error; CloseHandle(hChildStdoutRd); --- 194,201 ---- /* Create noninheritable read handle and close the inheritable read handle. */ ! if (!DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, ! GetCurrentProcess(), (HANDLE*)fdOut , 0, ! FALSE, ! DUPLICATE_SAME_ACCESS)) goto error; CloseHandle(hChildStdoutRd); *************** *** 224,228 **** } ! if (bError) { /* Save the handle to the current STDERR. */ --- 226,230 ---- } ! if (retErr) { /* Save the handle to the current STDERR. */ *************** *** 248,252 **** /* Now create the child process. */ ! err = CreateChildProcess(cmd, (HANDLE*)processID); if (err) goto error; --- 250,254 ---- /* Now create the child process. */ ! err = CreateChildProcess(cmd, processID); if (err) goto error; *************** *** 270,278 **** } ! if (mode == kWriteMode || mode == kReadWriteMode) { CloseHandle(hChildStderrWr); hChildStderrWr = 0; ! if (!SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout)) goto error; } --- 272,280 ---- } ! if (retErr) { CloseHandle(hChildStderrWr); hChildStderrWr = 0; ! if (!SetStdHandle(STD_ERROR_HANDLE, hSaveStderr)) goto error; } *************** *** 365,369 **** DWORD ret; #elif defined(Unix) ! int32 ret; #endif --- 367,371 ---- DWORD ret; #elif defined(Unix) ! int32 len; #endif *************** *** 412,417 **** #elif defined(Unix) ! ret = read((pipe_t)fd, LStrBuf(*data), *bytesRead) ! if (ret < 0) { *eof = (errno == EEOF); --- 414,419 ---- #elif defined(Unix) ! len = read((pipe_t)fd, LStrBuf(*data), *bytesRead) ! if (len < 0) { *eof = (errno == EEOF); *************** *** 421,425 **** else { ! *bytesRead = ret; } --- 423,427 ---- else { ! *bytesRead = len; } *************** *** 432,436 **** { if (err) ! NumericArrayResize(uB, 1, &(UHandle)data, *bytesRead); else err = NumericArrayResize(uB, 1, &(UHandle)data, *bytesRead); --- 434,438 ---- { if (err) ! NumericArrayResize(uB, 1, &(UHandle)data, *bytesRead); else err = NumericArrayResize(uB, 1, &(UHandle)data, *bytesRead); *************** *** 443,466 **** { MgErr err = noErr; ! if (!fd) return mgArgErr; /* NULL terminate the LabVIEW string so that the API functions can use them a C strings */ ! err = NumericArrayResize(uB, 1, (UHandle*)&data, LStrLen(*data) + 1); if (err) return err; ! LStrBuf(*data)[LStrLen(*data)]; #if defined(MSWin) ! if (!WriteFile((HANDLE)fd, LStrBuf(*data), LStrLen(*data), bytesWritten, NULL) ) err = Win32ToLVErr(GetLastError()); #elif defined(Unix) ! *bytesWritten = write((pipe_t)fd, LStrBuf(*data), LStrLen(*data); ! if (*bytesWritten == -1) err = UnixToLVErr(errno); ! #else err = mgNotImplementd: --- 445,473 ---- { MgErr err = noErr; + int32 len; ! if (!fd || !data) return mgArgErr; + DebugBreaking(); + /* NULL terminate the LabVIEW string so that the API functions can use them a C strings */ ! len = LStrLen(*data); ! err = NumericArrayResize(uB, 1, (UHandle*)&data, len + 1); if (err) return err; ! LStrBuf(*data)[len]; #if defined(MSWin) ! if (!WriteFile((HANDLE)fd, LStrBuf(*data), len, bytesWritten, NULL) ) err = Win32ToLVErr(GetLastError()); #elif defined(Unix) ! len = write((pipe_t)fd, LStrBuf(*data), LStrLen(*data); ! if (len < 0) err = UnixToLVErr(errno); ! else ! *bytesWritten = len; #else err = mgNotImplementd: *************** *** 473,477 **** #if defined(MSWin) ! static MgErr CreateChildProcess(LPSTR cmdline, HANDLE *pid) { PROCESS_INFORMATION piProcInfo; --- 480,484 ---- #if defined(MSWin) ! static MgErr CreateChildProcess(LPSTR cmdline, DWORD *pid) { PROCESS_INFORMATION piProcInfo; *************** *** 505,511 **** { if (pid) ! *pid = piProcInfo.hProcess; ! else ! CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); return noErr; --- 512,517 ---- { if (pid) ! *pid = piProcInfo.dwProcessId; ! CloseHandle(piProcInfo.hProcess); CloseHandle(piProcInfo.hThread); return noErr; |