[seed: 2/6] Add os.openpty and os.pipe



commit 266451256299166ec9c2a42523d98dc6b4d2d6dd
Author: Robert Carr <racarr mireia (none)>
Date:   Wed Apr 15 12:29:17 2009 -0400

    Add os.openpty and os.pipe
---
 modules/os/Makefile.am |    2 +-
 modules/os/os.c        |   59 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/modules/os/Makefile.am b/modules/os/Makefile.am
index b4b52b8..4ec59ce 100644
--- a/modules/os/Makefile.am
+++ b/modules/os/Makefile.am
@@ -5,7 +5,7 @@ libos_la_SOURCES = \
 	os.c
 
 libos_la_LDFLAGS = \
-	`pkg-config --libs seed`
+	`pkg-config --libs seed` -lutil
 
 AM_CPPFLAGS = \
 	-I../../libseed/ \
diff --git a/modules/os/os.c b/modules/os/os.c
index 4acccbd..dc59e15 100644
--- a/modules/os/os.c
+++ b/modules/os/os.c
@@ -10,6 +10,8 @@
 
 #include <fcntl.h>
 
+#include <pty.h>
+
 #include <seed.h>
 
 SeedObject os_namespace;
@@ -766,7 +768,60 @@ seed_os_lseek (SeedContext ctx,
   
   return seed_value_from_long (ctx, lseek (fd, offset, whence), exception);
 }
+
+SeedValue
+seed_os_openpty (SeedContext ctx,
+		 SeedObject function,
+		 SeedObject this_object,
+		 size_t argument_count,
+		 const SeedValue arguments[], 
+		 SeedException * exception)
+{
+  SeedValue fds[2], ret;
+  gint master,slave;
+
+  if (argument_count != 0)
+    {
+      EXPECTED_EXCEPTION ("os.openpty", "no arguments");
+    }
+  openpty (&master, &slave, NULL, NULL, NULL);
+  
+  fds[0] = seed_value_from_int (ctx, master, exception);
+  fds[1] = seed_value_from_int (ctx, slave, exception);
+  
+  ret = seed_make_array (ctx, fds, 2, exception);
   
+  return ret;
+}
+
+SeedValue
+seed_os_pipe (SeedContext ctx,
+	      SeedObject function,
+	      SeedObject this_object,
+	      size_t argument_count,
+	      const SeedValue arguments[], 
+	      SeedException * exception)
+{
+  SeedValue fds[2], ret;
+  gint fildes[2];
+
+  if (argument_count != 0)
+    {
+      EXPECTED_EXCEPTION ("os.pipe", "no arguments");
+    }
+  if (pipe (fildes) < 0)
+    {
+      // TODO
+    }
+  
+  fds[0] = seed_value_from_int (ctx, fildes[0], exception);
+  fds[1] = seed_value_from_int (ctx, fildes[1], exception);
+  
+  ret = seed_make_array (ctx, fds, 2, exception);
+  
+  return ret;
+}
+
 seed_static_function os_funcs[] = {
   {"chdir", seed_os_chdir, 0},
   {"fchdir", seed_os_fchdir, 0},
@@ -802,7 +857,9 @@ seed_static_function os_funcs[] = {
   {"fsync", seed_os_fsync, 0},
   {"ftruncate", seed_os_ftruncate, 0},
   {"isatty", seed_os_isatty, 0},
-  {"lseek", seed_os_lseek, 0}
+  {"lseek", seed_os_lseek, 0},
+  {"openpty", seed_os_openpty, 0},
+  {"pipe", seed_os_pipe, 0}
 };
 
 #define OS_DEFINE_ENUM(name, value) \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]