commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1097021 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/iodefs.h os/unix/arch_opts.h os/unix/util.c
Date Wed, 27 Apr 2011 07:27:11 GMT
Author: mturk
Date: Wed Apr 27 07:27:10 2011
New Revision: 1097021

URL: http://svn.apache.org/viewvc?rev=1097021&view=rev
Log:
Add iodefs header

Added:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h?rev=1097021&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h Wed Apr 27 07:27:10
2011
@@ -0,0 +1,33 @@
+/* Copyright (c) 2011 The MyoMake Project <http://www.myomake.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _ACR_IODEFS_H_
+#define _ACR_IODEFS_H_
+
+#include "acr/stdtypes.h"
+
+/** PipeIoMode flags
+ */
+#define ACR_PIPE_FULL_BLOCK     1
+#define ACR_PIPE_FULL_NONBLOCK  2
+#define ACR_PIPE_READ_BLOCK     3
+#define ACR_PIPE_WRITE_BLOCK    4
+
+#define ACR_PIPE_MODE_MASK      0x000F
+#define ACR_PIPE_NOINHERIT      0x0010
+
+
+#endif /* _ACR_IODEFS_H */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/iodefs.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h?rev=1097021&r1=1097020&r2=1097021&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_opts.h Wed Apr 27 07:27:10
2011
@@ -74,4 +74,11 @@ ACR_INLINE(ssize_t) r_write(int fd, cons
     return w;
 }
 
+int     AcrNonblock(int fd, int on);
+int     AcrCloseOnExec(int fd, int on);
+int     AcrWaitIO(int fd, int timeout, int events);
+int     AcrNullPipe(int flags, int fd);
+int     AcrPipePair(int pd[2], int flags);
+
+
 #endif /* _ACR_ARCH_OPTS_H_ */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c?rev=1097021&r1=1097020&r2=1097021&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/util.c Wed Apr 27 07:27:10 2011
@@ -16,7 +16,9 @@
 
 #include "acr/error.h"
 #include "acr/memory.h"
+#include "acr/iodefs.h"
 #include "acr/port.h"
+#include "arch_opts.h"
 #include <poll.h>
 
 int
@@ -135,3 +137,77 @@ AcrWaitIO(int fd, int timeout, int event
     else
         return ACR_EPIPE;
 }
+
+int
+AcrNullPipe(int flags, int fd)
+{
+    int nd;
+    int saved_errno = 0;
+
+    if ((nd = open("/dev/null", flags)) == -1)
+        return -1;
+    FD_ABOVE_STDFILENO(nd);
+    if (nd == -1)
+        return -1;
+    if (fd == -1)
+        return nd;
+    if ((fd = dup2(nd, fd)) == -1)
+        saved_errno = errno;
+    close(nd);
+    if (saved_errno)
+        errno = saved_errno;
+    return fd;
+}
+
+int
+AcrPipePair(int pd[2], int flags)
+{
+    int rc = 0;
+
+#if HAVE_PIPE2
+    int pf = 0;
+
+    if (flags == ACR_PIPE_FULL_NONBLOCK)
+        pf |= O_NONBLOCK;
+    if (pipe2(pd, pf) == -1)
+        return ACR_GET_OS_ERROR();
+    if (flags == ACR_PIPE_WRITE_BLOCK) {
+        if ((rc = AcrNonblock(pd[0], 1)))
+            goto finally;
+    }
+    if (flags == ACR_PIPE_READ_BLOCK) {
+        if ((rc = AcrNonblock(pd[1], 1)))
+            goto finally;
+    }
+#else
+    if (pipe(pd) == -1)
+        return ACR_GET_OS_ERROR();
+    if (flags == ACR_PIPE_WRITE_BLOCK ||
+        flags == ACR_PIPE_FULL_NONBLOCK) {
+        if ((rc = AcrNonblock(pd[0], 1)))
+            goto finally;
+        }
+        if (flags == ACR_PIPE_READ_BLOCK ||
+            flags == ACR_PIPE_FULL_NONBLOCK) {
+            if ((rc = AcrNonblock(pd[1], 1)))
+                goto finally;
+        }
+#endif
+    FD_ABOVE_STDFILENO(pd[0]);
+    if (pd[0] == -1) {
+        rc = ACR_GET_OS_ERROR();
+        goto finally;
+    }
+    FD_ABOVE_STDFILENO(pd[1]);
+    if (pd[1] == -1) {
+        rc = ACR_GET_OS_ERROR();
+        goto finally;
+    }
+
+    return 0;
+finally:
+    s_close(pd[0]);
+    s_close(pd[1]);
+
+    return rc;
+}



Mime
View raw message