From: Rolf K. <lab...@us...> - 2005-06-30 20:49:02
|
Update of /cvsroot/opengtoolkit/pipe/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12531/c_source Modified Files: pipes.c Log Message: More modifications to unix code and added an offset parameter to the read and write function Index: pipes.c =================================================================== RCS file: /cvsroot/opengtoolkit/pipe/c_source/pipes.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** pipes.c 28 Jun 2005 00:14:37 -0000 1.14 --- pipes.c 30 Jun 2005 20:48:50 -0000 1.15 *************** *** 46,51 **** uInt32 *fdErr, uInt32 *processID); MgErr LibAPI PipeClose(uInt32 fd); ! MgErr LibAPI PipeRead(uInt32 fd, uInt32 *bytesRead, LStrHandle data, uInt32 *eof); ! MgErr LibAPI PipeWrite(uInt32 fd, uInt32 *bytesWritten, LStrHandle data); #if defined(MSWin) --- 46,51 ---- uInt32 *fdErr, uInt32 *processID); MgErr LibAPI PipeClose(uInt32 fd); ! MgErr LibAPI PipeRead(uInt32 fd, uInt32 offset, uInt32 *bytesRead, LStrHandle data, uInt32 *eof); ! MgErr LibAPI PipeWrite(uInt32 fd, uInt32 offset, uInt32 *bytesWritten, LStrHandle data); #if defined(MSWin) *************** *** 139,146 **** { case kReadMode: ! mode = S_IRUSR; break; case kWriteMode: ! mode = S_IWUSR; break; } --- 139,149 ---- { case kReadMode: ! mode = O_RDONLY; break; case kWriteMode: ! mode = O_WRONLY; ! break; ! case kReadWriteMode: ! mode = O_RDWR; break; } *************** *** 155,159 **** { err = noErr; ! *fd = open(name, O_NONBLOCK); if (*fd < 0) { --- 158,162 ---- { err = noErr; ! *fd = open(name, mode | O_NONBLOCK); if (*fd < 0) { *************** *** 212,219 **** goto out; } - else - { - hChildStderr = GetStdHandle(STD_ERROR_HANDLE); - } /* Now create the child process. */ --- 215,218 ---- *************** *** 260,264 **** } ! MgErr LibAPI PipeRead(uInt32 fd, uInt32 *bytesRead, LStrHandle data, uInt32 *eof) { MgErr err = noErr; --- 259,263 ---- } ! MgErr LibAPI PipeRead(uInt32 fd, uInt32 offset, uInt32 *bytesRead, LStrHandle data, uInt32 *eof) { MgErr err = noErr; *************** *** 274,289 **** } - if (LStrLen(*data) < (int32)bytesReq) - { - err = NumericArrayResize(uB, 1, (UHandle*)&data, bytesReq); - if (err) - return err; - - /* We need to do this in LabVIEW 7.0 as otherwise the next - NumericArrayResize() will optimize out and only copy as much - characters into the new handle as it believes to be in the - array based on this value. */ - LStrLen(*data) = bytesReq; - } #if defined(MSWin) /* ReadFile blocks on any pipe not opened in overlapped mode and the anonymous --- 273,276 ---- *************** *** 306,310 **** { /* There are some bytes to read, so try to read as much as possible now! */ ! if (!ReadFile((HANDLE)fd, LStrBuf(*data), bytesReq, bytesRead, NULL)) { ret = GetLastError(); --- 293,297 ---- { /* There are some bytes to read, so try to read as much as possible now! */ ! if (!ReadFile((HANDLE)fd, LStrBuf(*data) + offset, bytesReq - offset, bytesRead, NULL)) { ret = GetLastError(); *************** *** 315,319 **** } #elif defined(Unix) ! *bytesRead = read((pipe_t)fd, LStrBuf(*data), bytesReq) if (*bytesRead < 0) { --- 302,306 ---- } #elif defined(Unix) ! *bytesRead = read((pipe_t)fd, LStrBuf(*data) + offset, bytesReq - offset) if (*bytesRead < 0) { *************** *** 331,335 **** } ! MgErr LibAPI PipeWrite(uInt32 fd, uInt32 *bytesWritten, LStrHandle data) { MgErr err = noErr; --- 318,322 ---- } ! MgErr LibAPI PipeWrite(uInt32 fd, uInt32 offset, uInt32 *bytesWritten, LStrHandle data) { MgErr err = noErr; *************** *** 338,355 **** return mgArgErr; - /* NULL terminate the LabVIEW string so that the API functions can use - them as a C string */ - *bytesWritten = LStrLen(*data); - err = NumericArrayResize(uB, 1, (UHandle*)&data, *bytesWritten + 1); - if (err) - return err; - LStrBuf(*data)[*bytesWritten] = 0; - #if defined(MSWin) ! if (!WriteFile((HANDLE)fd, LStrBuf(*data), *bytesWritten, bytesWritten, NULL) ) err = Win32ToLVErr(GetLastError()); #elif defined(Unix) ! *bytesWritten = write((pipe_t)fd, LStrBuf(*data), *bytesWritten); if (*bytesWritten < 0) { --- 325,334 ---- return mgArgErr; #if defined(MSWin) ! if (!WriteFile((HANDLE)fd, LStrBuf(*data) + offset, *bytesWritten - offset, bytesWritten, NULL) ) err = Win32ToLVErr(GetLastError()); #elif defined(Unix) ! *bytesWritten = write((pipe_t)fd, LStrBuf(*data) + offset, *bytesWritten - offset); if (*bytesWritten < 0) { *************** *** 377,381 **** /* Save the handle to the current STDIN. */ *stdIO = GetStdHandle(type); ! /* Create a pipe for the child process's standard IO. */ if (type == STANDARD_IN) --- 356,360 ---- /* Save the handle to the current STDIN. */ *stdIO = GetStdHandle(type); ! /* Create a pipe for the child process's standard IO. */ if (type == STANDARD_IN) *************** *** 390,394 **** if (ret) { ! /* Duplicate the write handle to the pipe so it is not inherited. */ ret = DuplicateHandle(GetCurrentProcess(), temp, GetCurrentProcess(), (HANDLE*)lvpipe, 0, --- 369,374 ---- if (ret) { ! /* Duplicate the LabVIEW side handle to the pipe so it is not ! inherited by the child process. */ ret = DuplicateHandle(GetCurrentProcess(), temp, GetCurrentProcess(), (HANDLE*)lvpipe, 0, *************** *** 432,438 **** if (dup2(*rmpipe, type) == type) { ! close(*rmpipe); ! i = fcntl(temp, F_GETFD, 0); ! fcntl(temp, F_SETFD, i | FD_CLOEXEC); if ((*lvpipe = (uInt32)fdopen(temp, type == STANDARD_IN ? "wb" : "rb")) == NULL) --- 412,418 ---- if (dup2(*rmpipe, type) == type) { ! close(*rmpipe); ! i = fcntl(temp, F_GETFD, 0); ! fcntl(temp, F_SETFD, i | FD_CLOEXEC); if ((*lvpipe = (uInt32)fdopen(temp, type == STANDARD_IN ? "wb" : "rb")) == NULL) *************** *** 444,448 **** } #else ! err = mgNotImplementd #endif return err; --- 424,428 ---- } #else ! err = mgNotImplemented #endif return err; *************** *** 461,464 **** --- 441,455 ---- } #elif defined(Unix) + if (rmpipe) + close(rmpipe); + fcntl(stdIO->handle, F_SETFD, stdIO->flags); + dup2(stdIO->handle, type); + if (err) + { + close(*(pipe_t*)lvpipe); + *lvpipe = 0; + } + + #else return mgNotImplementd *************** *** 485,491 **** siStartInfo.dwFlags |= STARTF_USESHOWWINDOW; siStartInfo.wShowWindow = SW_HIDE; ! siStartInfo.hStdInput = stdIn; ! siStartInfo.hStdOutput = stdOut; ! siStartInfo.hStdError = stdErr; /* Create the child process. */ --- 476,491 ---- siStartInfo.dwFlags |= STARTF_USESHOWWINDOW; siStartInfo.wShowWindow = SW_HIDE; ! if (stdIn) ! siStartInfo.hStdInput = stdIn; ! else ! siStartInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); ! if (stdOut) ! siStartInfo.hStdOutput = stdOut; ! else ! siStartInfo.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); ! if (stdErr) ! siStartInfo.hStdError = stdErr; ! else ! siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); /* Create the child process. */ *************** *** 638,641 **** --- 638,642 ---- static struct errentry errtable[] = { {EINVAL, mgArgErr }, + {ENXIO, fNotFound }, {ENOENT, fNotFound }, {EMFILE, fTMFOpen }, |