Hello!

	I wish to propose the IO#sysseek method, which is to comprehend
the IO#sysread and IO#syswrite methods. Generic IO#seek does not work
well for them, especially in case of mixing generic FILE-based and
handle-based I/O methods (I know it's a bad thing, but...).

	The following patch adds this functionality.

--- io.c~	Thu Mar 14 09:23:44 2002
+++ io.c	Fri Mar 15 11:56:37 2002
@@ -365,6 +365,29 @@
 }
 
 static VALUE
+rb_io_sysseek_m(argc, argv, io)
+    int argc;
+    VALUE *argv;
+    VALUE io;
+{
+    VALUE offset, ptrname;
+    int whence;
+    OpenFile *fptr;
+    long pos;
+
+    rb_scan_args(argc, argv, "11", &offset, &ptrname);
+    if (argc == 1) whence = SEEK_SET;
+    else whence = NUM2INT(ptrname);
+
+    GetOpenFile(io, fptr);
+    pos = lseek(fileno(fptr->f), NUM2LONG(offset), whence);
+    if (pos == -1) rb_sys_fail(fptr->path);
+    clearerr(fptr->f);
+
+    return LONG2NUM(pos);
+}
+
+static VALUE
 rb_io_seek_m(argc, argv, io)
     int argc;
     VALUE *argv;
@@ -3724,6 +3747,7 @@
     rb_define_method(rb_cIO, "isatty", rb_io_isatty, 0);
     rb_define_method(rb_cIO, "tty?", rb_io_isatty, 0);
     rb_define_method(rb_cIO, "binmode",  rb_io_binmode, 0);
+    rb_define_method(rb_cIO, "sysseek", rb_io_sysseek_m, -1);
 
     rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
     rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);

Zagorodnikov Aristarkh | Lead Programmer | xm / bolotov-team.ru
bolotov.ru creative group http://www.bolotov.ru/