commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r896817 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr.h include/arch/windows/acr_arch_private.h os/win32/pipe.c os/win32/posix.c
Date Thu, 07 Jan 2010 09:34:12 GMT
Author: mturk
Date: Thu Jan  7 09:33:21 2010
New Revision: 896817

URL: http://svn.apache.org/viewvc?rev=896817&view=rev
Log:
Add nullpipe and dup3 to windows port

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=896817&r1=896816&r2=896817&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Thu Jan  7 09:33:21 2010
@@ -177,6 +177,7 @@
 /* Add MSVCRT specific includes
  */
 #include <io.h>
+#include <fcntl.h>
 #include <process.h>    /* getpid() */
 #include <sys/stat.h>
 #else

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=896817&r1=896816&r2=896817&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Thu Jan  7 09:33:21 2010
@@ -262,6 +262,15 @@
 pid_t    getppid(void);
 #endif
 
+HANDLE dup3(HANDLE, HANDLE, int);
+
+/**
+ * Functions from pipe.c
+ */
+int socketpair(SOCKET *, SOCKET *, int);
+int pipepair(HANDLE *, HANDLE *, wchar_t **, int);
+HANDLE nullpipe(int, HANDLE);
+
 /**
  * Wide char envvar functions from env.c
  */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c?rev=896817&r1=896816&r2=896817&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pipe.c Thu Jan  7 09:33:21 2010
@@ -200,6 +200,36 @@
     return rv;
 }
 
+HANDLE nullpipe(int flags, HANDLE fd)
+{
+    SECURITY_ATTRIBUTES sa;
+    HANDLE nd;
+    DWORD  saved_errno = 0;
+
+    sa.nLength              = sizeof(SECURITY_ATTRIBUTES);
+    sa.bInheritHandle       = TRUE;
+    sa.lpSecurityDescriptor = NULL;
+
+    nd = CreateFileW(L"NUL",
+                     flags,
+                     0,
+                     &sa,
+                     OPEN_EXISTING,
+                     FILE_ATTRIBUTE_NORMAL,
+                     NULL);
+    if (IS_INVALID_HANDLE(nd))
+        return NULL;
+    if (IS_INVALID_HANDLE(fd))
+        return nd;
+    fd = dup3(nd, fd, 0);
+    if (IS_INVALID_HANDLE(fd))
+        saved_errno = GetLastError();
+    CloseHandle(nd);
+    if (saved_errno)
+        SetLastError(saved_errno);
+    return fd;
+}
+
 int pipepair(HANDLE *rd, HANDLE *wr, wchar_t **pname, int flags)
 {
     int rc = 0;
@@ -261,7 +291,6 @@
                            int flags)
 {
     int rc = 0;
-    SECURITY_ATTRIBUTES sa;
     HANDLE   hr   = NULL;
     HANDLE   hw   = NULL;
     wchar_t *name = NULL;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c?rev=896817&r1=896816&r2=896817&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/posix.c Thu Jan  7 09:33:21 2010
@@ -64,3 +64,89 @@
 
     return ppid;
 }
+
+HANDLE dup3(HANDLE oldfd, HANDLE newfd, int flags)
+{
+    int    osfd;
+    int    osdd;
+    DWORD  saved_errno = 0;
+    HANDLE duph = INVALID_HANDLE_VALUE;
+
+    if (IS_INVALID_HANDLE(oldfd) ||
+        IS_INVALID_HANDLE(newfd)) {
+        ACR_SET_OS_ERROR(ACR_EINVAL);
+        return INVALID_HANDLE_VALUE;
+    }
+    if (oldfd == newfd)
+        return newfd;
+
+    if (newfd == GetStdHandle(STD_INPUT_HANDLE)) {
+        fflush(stdin);
+        setvbuf(stdin, NULL, _IONBF, 0);
+        _commit(STDIN_FILENO);
+
+        osfd = _open_osfhandle((INT_PTR)oldfd, _O_RDONLY | _O_BINARY);
+        if (osfd == -1) {
+            return INVALID_HANDLE_VALUE;
+        }
+        osdd = _dup2(osfd, STDIN_FILENO);
+        if (osdd == -1) {
+            return INVALID_HANDLE_VALUE;
+        }
+        _setmode(STDIN_FILENO, _O_BINARY);
+        duph = (HANDLE)_get_osfhandle(STDIN_FILENO);
+        if (IS_VALID_HANDLE(duph) && flags)
+            SetHandleInformation(duph, HANDLE_FLAG_INHERIT, 0);
+        return duph;
+    }
+    else if (newfd == GetStdHandle(STD_OUTPUT_HANDLE)) {
+        fflush(stdout);
+        setvbuf(stdout, NULL, _IONBF, 0);
+        _commit(STDOUT_FILENO);
+
+        osfd = _open_osfhandle((INT_PTR)oldfd, _O_WRONLY | _O_BINARY);
+        if (osfd == -1) {
+            return INVALID_HANDLE_VALUE;
+        }
+        osdd = _dup2(osfd, STDOUT_FILENO);
+        if (osdd == -1) {
+            return INVALID_HANDLE_VALUE;
+        }
+        _setmode(STDOUT_FILENO, _O_BINARY);
+        duph = (HANDLE)_get_osfhandle(STDOUT_FILENO);
+        if (IS_VALID_HANDLE(duph) && flags)
+            SetHandleInformation(duph, HANDLE_FLAG_INHERIT, 0);
+        return duph;
+    }
+    else if (newfd == GetStdHandle(STD_ERROR_HANDLE)) {
+        fflush(stderr);
+        setvbuf(stderr, NULL, _IONBF, 0);
+        _commit(STDERR_FILENO);
+
+        osfd = _open_osfhandle((INT_PTR)oldfd, _O_WRONLY | _O_BINARY);
+        if (osfd == -1) {
+            return INVALID_HANDLE_VALUE;
+        }
+        osdd = _dup2(osfd, STDERR_FILENO);
+        if (osdd == -1) {
+            return INVALID_HANDLE_VALUE;
+        }
+        _setmode(STDOUT_FILENO, _O_BINARY);
+        duph = (HANDLE)_get_osfhandle(STDERR_FILENO);
+        if (IS_VALID_HANDLE(duph) && flags)
+            SetHandleInformation(duph, HANDLE_FLAG_INHERIT, 0);
+        return duph;
+    }
+    if (!DuplicateHandle(GetCurrentProcess(),
+                         oldfd,
+                         GetCurrentProcess(),
+                         &duph,
+                         0,
+                         flags ? FALSE : TRUE,
+                         DUPLICATE_SAME_ACCESS))
+        return INVALID_HANDLE_VALUE;
+
+
+    CloseHandle(newfd);
+    return duph;
+}



Mime
View raw message