[macruby-changes] [1610] MacRuby/branches/experimental/io.c

source_changes at macosforge.org source_changes at macosforge.org
Wed May 27 13:18:16 PDT 2009


Revision: 1610
          http://trac.macosforge.org/projects/ruby/changeset/1610
Author:   pthomson at apple.com
Date:     2009-05-27 13:18:15 -0700 (Wed, 27 May 2009)
Log Message:
-----------
Added IO#pipe.

Modified Paths:
--------------
    MacRuby/branches/experimental/io.c

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-05-27 16:56:48 UTC (rev 1609)
+++ MacRuby/branches/experimental/io.c	2009-05-27 20:18:15 UTC (rev 1610)
@@ -30,10 +30,6 @@
 
 extern void Init_File(void);
 
-#if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG)
-# error off_t is bigger than long, but you have no long long...
-#endif
-
 VALUE rb_cIO;
 VALUE rb_eEOFError;
 VALUE rb_eIOError;
@@ -282,11 +278,11 @@
     CFReadStreamRef r = NULL;
     CFWriteStreamRef w = NULL;
 
-    if (mode & FMODE_READABLE) {
+    if (mode != FMODE_WRITABLE) {
 	r = _CFReadStreamCreateFromFileDescriptor(NULL, fd);
     }
 
-    if (mode & FMODE_WRITABLE) {
+    if (mode != FMODE_READABLE) {
 	w = _CFWriteStreamCreateFromFileDescriptor(NULL, fd);
     }
 
@@ -3199,7 +3195,17 @@
 static VALUE
 rb_io_s_pipe(VALUE recv, SEL sel, int argc, VALUE *argv)
 {
-	rb_notimplement();
+	VALUE ext_enc = Qnil, int_enc = Qnil;
+	VALUE rd, wr;
+	rb_scan_args(argc, argv, "02", &ext_enc, &int_enc);
+	
+	int fd[2] = {-1, -1};
+	pipe(fd);
+	
+	rd = prep_io(fd[0], FMODE_READABLE, rb_cIO);
+	wr = prep_io(fd[1], FMODE_WRITABLE, rb_cIO);
+	
+	return rb_assoc_new(rd, wr);
 }
 
 /*
@@ -4081,23 +4087,9 @@
     rb_file_const("APPEND", INT2FIX(O_APPEND));
     rb_file_const("CREAT", INT2FIX(O_CREAT));
     rb_file_const("EXCL", INT2FIX(O_EXCL));
-#if defined(O_NDELAY) || defined(O_NONBLOCK)
-# ifdef O_NONBLOCK
     rb_file_const("NONBLOCK", INT2FIX(O_NONBLOCK));
-# else
-    rb_file_const("NONBLOCK", INT2FIX(O_NDELAY));
-# endif
-#endif
     rb_file_const("TRUNC", INT2FIX(O_TRUNC));
-#ifdef O_NOCTTY
     rb_file_const("NOCTTY", INT2FIX(O_NOCTTY));
-#endif
-#ifdef O_BINARY
-    rb_file_const("BINARY", INT2FIX(O_BINARY));
-#else
     rb_file_const("BINARY", INT2FIX(0));
-#endif
-#ifdef O_SYNC
     rb_file_const("SYNC", INT2FIX(O_SYNC));
-#endif
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090527/0304019e/attachment-0001.html>


More information about the macruby-changes mailing list