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

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 12 00:01:00 PDT 2009


Revision: 893
          http://trac.macosforge.org/projects/ruby/changeset/893
Author:   lsansonetti at apple.com
Date:     2009-03-12 00:00:57 -0700 (Thu, 12 Mar 2009)
Log Message:
-----------
implement rb_io_getbyte()

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

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-03-12 06:52:16 UTC (rev 892)
+++ MacRuby/branches/experimental/io.c	2009-03-12 07:00:57 UTC (rev 893)
@@ -815,6 +815,7 @@
     CFDataIncreaseLength(data, FIX2LONG(len)); // sentinel byte?
     CFReadStreamRead(io_struct->readStream, CFDataGetMutableBytePtr(data),
 	    FIX2LONG(len));
+    // TODO check the return value of CFReadStreamRead() for errors/eof
     return outbuf;
 }
 
@@ -1116,7 +1117,20 @@
 VALUE
 rb_io_getbyte(VALUE io, SEL sel)
 {
-    rb_notimplement();
+    rb_io_t *io_struct = ExtractIOStruct(io);
+    
+    UInt8 byte;
+    int code = CFReadStreamRead(io_struct->readStream, &byte, 1);
+    if (code != 1) {
+	if (code == 0) {
+	    // EOF
+	    return Qnil;
+	}
+	// TODO raise an exception
+	abort();
+    }
+
+    return INT2FIX(byte);
 }
 
 /*
@@ -1130,7 +1144,12 @@
 static VALUE
 rb_io_readbyte(VALUE io, SEL sel)
 {
-    rb_notimplement();
+    VALUE c = rb_io_getbyte(io, 0);
+
+    if (NIL_P(c)) {
+	rb_eof_error();
+    }
+    return c;
 }
 
 /*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090312/cb838c60/attachment-0001.html>


More information about the macruby-changes mailing list