commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r820753 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
Date Thu, 01 Oct 2009 19:07:52 GMT
Author: mturk
Date: Thu Oct  1 19:07:52 2009
New Revision: 820753

URL: http://svn.apache.org/viewvc?rev=820753&view=rev
Log:
Close std handles like APR, but guard against duplicate _close(x) calls

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=820753&r1=820752&r2=820753&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Thu Oct  1 19:07:52 2009
@@ -51,6 +51,10 @@
     return rc;
 }
 
+static LONG volatile _std_in  = 1;
+static LONG volatile _std_out = 1;
+static LONG volatile _std_err = 1;
+
 static int file_cclose(void *file, int type, unsigned int flags)
 {
     int rc = ACR_SUCCESS;
@@ -69,7 +73,26 @@
         /* This is from Descriptor.close() call
          */
         if (IS_VALID_HANDLE(fp->fd)) {
-            if (!CloseHandle(fp->fd))
+            if  (fp->flags & ACR_STDFILE_FLAGS) {
+                switch (fp->flags & ACR_STDFILE_FLAGS) {
+                    case ACR_STDIN_FLAG:
+                        if (InterlockedExchange(&_std_in, 0))
+                            _close(0);
+                        SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);
+                    break;
+                    case ACR_STDOUT_FLAG:
+                        if (InterlockedExchange(&_std_out, 0))
+                            _close(1);
+                        SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
+                    break;
+                    case ACR_STDERR_FLAG:
+                        if (InterlockedExchange(&_std_err, 0))
+                            _close(2);
+                        SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
+                    break;
+                }
+            }
+            else if (!CloseHandle(fp->fd))
                 rc = ACR_GET_OS_ERROR();
         }
         else



Mime
View raw message