--Apple-Mail-20--84711544
Content-Type: multipart/mixed; boundary=Apple-Mail-19--84711565


--Apple-Mail-19--84711565
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

I wanted to implement tail(1) in ruby cleanly, but found the best I 
could do was to trigger clearerr(3) with fp.pos = fp.pos.  So then I 
whipped up this nice little patch to add IO#clearerr.


--Apple-Mail-19--84711565
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="io.c.clearrerr.patch"
Content-Disposition: attachment;
	filename=io.c.clearrerr.patch

Index: io.c
===================================================================
RCS file: /src/ruby/io.c,v
retrieving revision 1.246.2.71
diff -u -r1.246.2.71 io.c
--- io.c	25 Jan 2005 04:02:27 -0000	1.246.2.71
+++ io.c	30 Jan 2005 07:48:31 -0000
@@ -760,6 +760,33 @@
 
 /*
  *  call-seq:
+ *     ios.clearerr => nil
+ *  
+ *  Clears the end of file and error indicators for <em>ios</em>.
+ *     
+ *     f = File.new("testfile")
+ *     dummy = f.read
+ *     f.eof   #=> true
+ *     f.clearerr
+ *     # wait for more data
+ *     dummy = f.read
+ */
+
+VALUE
+rb_io_clearerr(io)
+    VALUE io;
+{
+    OpenFile *fptr;
+
+    GetOpenFile(io, fptr);
+
+    clearerr(fptr->f);
+
+    return Qnil;
+}
+
+/*
+ *  call-seq:
  *     ios.sync    => true or false
  *  
  *  Returns the current ``sync mode'' of <em>ios</em>. When sync mode is
@@ -5171,6 +5198,17 @@
 }
 
 static VALUE
+argf_clearerr()
+{
+    if (current_file) {
+	if (init_p == 0) return Qnil;
+	ARGF_FORWARD();
+	return rb_io_clearerr(current_file);
+    }
+    return Qnil;
+}
+
+static VALUE
 argf_read(argc, argv)
     int argc;
     VALUE *argv;
@@ -5563,6 +5601,7 @@
     rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);
     rb_define_method(rb_cIO, "eof", rb_io_eof, 0);
     rb_define_method(rb_cIO, "eof?", rb_io_eof, 0);
+    rb_define_method(rb_cIO, "clearerr", rb_io_clearerr, 0);
 
     rb_define_method(rb_cIO, "close", rb_io_close_m, 0);
     rb_define_method(rb_cIO, "closed?", rb_io_closed, 0);
@@ -5627,6 +5666,7 @@
     rb_define_singleton_method(argf, "pos=", argf_set_pos, 1);
     rb_define_singleton_method(argf, "eof", argf_eof, 0);
     rb_define_singleton_method(argf, "eof?", argf_eof, 0);
+    rb_define_singleton_method(argf, "clearerr", argf_clearerr, 0);
     rb_define_singleton_method(argf, "binmode", argf_binmode, 0);
 
     rb_define_singleton_method(argf, "filename", argf_filename, 0);

--Apple-Mail-19--84711565
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed



I'm not sure if argf_clearerr is good to add or not, but I implemented 
it for completeness.

-- 
Eric Hodel - drbrain / segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04
--Apple-Mail-19--84711565--

--Apple-Mail-20--84711544
content-type: application/pgp-signature; x-mac-type=70674453;
	name=PGP.sig
content-description: This is a digitally signed message part
content-disposition: inline; filename=PGP.sig
content-transfer-encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFB/JITMypVHHlsnwQRAqXGAKCqOynp5/7OmqNhP+p5ojAeF+U3HgCeM4WF
f/yYJ6OYZVQAvBuU2iSusHg=
=Q6SS
-----END PGP SIGNATURE-----

--Apple-Mail-20--84711544--