redirect e$B$N=hM}$r$A$g$C$H=q$$$F$$?$H$3$m!"e(B
IO.sysdup2, IO.sysdup, IO.sysclose e$B$,M$7$/$J$C$?$N$G$9$,!"e(B
e$B2C$($F$b$$$$$G$7$g$&$+!#e(B(e$B%I%-%e%a%s%H$O8e$G=q$-$^$9!#e(B)
e$BNc$($P!“e(Bsh e$B$Ne(B 3>&1 e$B$r<B8=$9$k$K$O$Oe(B dup2(1,3)
e$B$r8F$S=P$5$J$$e(B
e$B$H$$$1$J$$$o$1$G$9$,!“e(BIO#reopen e$B$G$3$l$r9T$&$K$O!”$^$:e(B fd
e$B$,e(B
3 e$B$Je(B IO e$B%*%V%8%’%/%H$r$($kI,MW$,$”$j$^$9!#$7$+$7!"e(B3 e$B$,e(B
close
e$B>uBV$@$H!"e(BIO.new e$B$,$G$-$^$;$s!#$G$Oe(B 3 e$B$r$I$&$K$+$7$Fe(B
open e$B>ue(B
e$BBV$Ke(B… e$B$H$+9M$($k$h$j$Oe(B dup2
e$B$,$$$-$J$j;H$($k$N$,NI$+$m$&!"e(B
e$B$H$$$&$o$1$G$9!#e(B
dup e$B$He(B sysclose e$B$O!"e(BIO
e$B%l%Y%k$G$d$k$3$H$b$G$-$^$9$,!"e(Bdup2 e$B$Ge(B
e$B$=$&$d$C$Fe(B fd e$B%l%Y%k$G$NA`:n$r9T$C$F$$$k$H!“e(BIO
e$B%l%Y%k$K;}$Ae(B
e$B>e$2$F$+$i:n6H$9$k$N$,LLE]$/$5$/!”$^$?!"e(BGC e$B$r5$$K$7$J$$$H$$e(B
e$B$1$J$/$F$$$d$J$N$,DI2C$NM}M3$G$9!#$=$l$K!“e(Bsysopen
e$B$O$9$G$K$”$Ce(B
e$B$F!"BP$K$J$ke(B sysclose e$B$,$J$$$He(B close e$B$7$K$/$$$G$9$7!#e(B
Index: io.c
— io.c (e$B%j%S%8%g%se(B 13236)
+++ io.c (e$B:n6H%3%T!<e(B)
@@ -5143,6 +5143,43 @@
#endif
}
+static VALUE
+rb_io_s_sysdup(VALUE klass, VALUE oldfd_v)
+{
- int oldfd, ret;
- oldfd = NUM2INT(oldfd_v);
- ret = dup(oldfd);
- if (ret == -1) {
-
rb_sys_fail(0);
- }
- return INT2NUM(ret);
+}
+static VALUE
+rb_io_s_sysdup2(VALUE klass, VALUE oldfd_v, VALUE newfd_v)
+{
- int oldfd, newfd, ret;
- oldfd = NUM2INT(oldfd_v);
- newfd = NUM2INT(newfd_v);
- ret = dup2(oldfd, newfd);
- if (ret == -1) {
-
rb_sys_fail(0);
- }
- return INT2NUM(ret);
+}
+static VALUE
+rb_io_s_sysclose(VALUE klass, VALUE fd_v)
+{
- int fd, ret;
- fd = NUM2INT(fd_v);
- ret = close(fd);
- if (ret == -1) {
-
rb_sys_fail(0);
- }
- return INT2NUM(ret);
+}
struct foreach_arg {
int argc;
VALUE *argv;
@@ -5708,6 +5745,9 @@
rb_define_singleton_method(rb_cIO, “read”, rb_io_s_read, -1);
rb_define_singleton_method(rb_cIO, “select”, rb_f_select, -1);
rb_define_singleton_method(rb_cIO, “pipe”, rb_io_s_pipe, 0);
-
rb_define_singleton_method(rb_cIO, “sysdup”, rb_io_s_sysdup, 1);
-
rb_define_singleton_method(rb_cIO, “sysdup2”, rb_io_s_sysdup2, 2);
-
rb_define_singleton_method(rb_cIO, “sysclose”, rb_io_s_sysclose,
1);rb_define_method(rb_cIO, “initialize”, rb_io_initialize, -1);