[Ecls-list] [patch] SI:MAKE-PIPE, making a pipe()
Samium Gromoff
_deepfire at feelingofgreen.ru
Fri Jun 27 11:58:55 UTC 2008
Good day, list,
the attached patch provides POSIX pipes formulated in terms of CL streams,
both on unices (tested on Linux) and win32/msvc (tested, as well).
This raises a related question -- whether SI:OPEN-PIPE is well-named[1].
regards, Samium Gromoff
P.S. Sorry if I botched the patch format, the cut and paste lowpass
filter interferred..
1. I understand, though, where it comes from, the popen() libc call..
diff --git a/src/c/symbols_list.h b/src/c/symbols_list.h
--- a/src/c/symbols_list.h
+++ b/src/c/symbols_list.h
@@ -1141,6 +1141,7 @@ cl_symbols[] = {
{SYS_ "MKDIR", SI_ORDINARY, si_mkdir, 2, OBJNULL},
{SYS_ "MKSTEMP", SI_ORDINARY, si_mkstemp, 1, OBJNULL},
{SYS_ "RMDIR", SI_ORDINARY, si_rmdir, 1, OBJNULL},
+{SYS_ "MAKE-PIPE", SI_ORDINARY, si_make_pipe, -1, OBJNULL},
{SYS_ "OPEN-PIPE", SI_ORDINARY, si_open_pipe, 1, OBJNULL},
{SYS_ "PACKAGE-LOCK", SI_ORDINARY, si_package_lock, 2, OBJNULL},
{SYS_ "PACKAGE-HASH-TABLES", SI_ORDINARY, si_package_hash_tables, 1, OBJNULL},
diff --git a/src/c/symbols_list2.h b/src/c/symbols_list2.h
--- a/src/c/symbols_list2.h
+++ b/src/c/symbols_list2.h
@@ -1141,6 +1141,7 @@ cl_symbols[] = {
{SYS_ "MKDIR","si_mkdir"},
{SYS_ "MKSTEMP","si_mkstemp"},
{SYS_ "RMDIR","si_rmdir"},
+{SYS_ "MAKE-PIPE", "si_make_pipe"},
{SYS_ "OPEN-PIPE","si_open_pipe"},
{SYS_ "PACKAGE-LOCK","si_package_lock"},
{SYS_ "PACKAGE-HASH-TABLES","si_package_hash_tables"},
diff --git a/src/c/unixsys.d b/src/c/unixsys.d
--- a/src/c/unixsys.d
+++ b/src/c/unixsys.d
@@ -28,6 +28,8 @@
#endif
#ifdef _MSC_VER
#include <windows.h>
+#include <io.h>
+#include <fcntl.h>
#endif
cl_object
@@ -48,6 +50,29 @@ si_getpid(void)
@(return MAKE_FIXNUM(getpid()))
}
+/************************************************************
+ * Unix pipe *
+ ************************************************************/
+cl_object
+si_make_pipe(void)
+{
+ int fds[2], ret; /* file descriptor */
+
+#ifdef _MSC_VER
+ ret = _pipe(fds, 4096, _O_BINARY);
+#else
+ ret = pipe(fds);
+#endif
+
+ if (ret < 0) {
+ FElibc_error("Unable to create a pipe", 0);
+ @(return Cnil)
+ }
+
+ @(return ecl_make_stream_from_fd(make_simple_base_string("PIPE-READ-ENDPOINT"), fds[0], smm_input)
+ ecl_make_stream_from_fd(make_simple_base_string("PIPE-WRITE-ENDPOINT"), fds[1], smm_output))
+}
+
cl_object
si_open_pipe(cl_object cmd_string)
{
diff --git a/src/h/external.h b/src/h/external.h
index df51731..228f420 100644
--- a/src/h/external.h
+++ b/src/h/external.h
@@ -1538,6 +1538,7 @@ extern ECL_API cl_object si_trap_fpe(cl_object condition, cl_object flag);
/* unixsys.c */
extern ECL_API cl_object si_system(cl_object cmd);
+extern ECL_API cl_object si_make_pipe(void);
extern ECL_API cl_object si_open_pipe(cl_object cmd);
extern ECL_API cl_object si_close_pipe(cl_object stream);
extern ECL_API cl_object si_run_program _ARGS((cl_narg narg, cl_object command, cl_object args, ...));
More information about the ecl-devel
mailing list