[Bug #2747] io.dup doesn't handle pos properly

Bug #2747: io.dup doesn’t handle pos properly
http://redmine.ruby-lang.org/issues/show/2747

e$B5/I<<Te(B: Motohiro KOSAKI
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: core, Target version: 1.9.x
ruby -v: ruby 1.9.2dev (2010-02-03) [x86_64-linux]

e$B5-O?$N$?$a$K!"e(BIRCe$B$+$iE>5-$7$^$9!#e(B

duptest.rb

f1 = File.new(“foo.txt”)
f2 = f1.dup()
p f1.pos
p f2.gets
p f1.pos
p f2.pos

foo.txt

1
2
3

e$B$3$N$h$&$J%F%9%H%W%m%0%i%`$r<B9T$9$k$H!"e(B

0
“1\n”
6
2

e$B$H$J$j$^$9!#e(Bdupe$B$Oe(Bf1e$B$He(Bf2e$B$GF1$8e(Bpose$B$,JV$k$Y$-$G$"$k$7!"e(B6e$B$O$I$3$+$i=P$F$-$?$N$+$h$/J,$+$j$^$;$s!#e(B

e$B%A%1%C%He(B #2747 e$B$,99?7$5$l$^$7$?!#e(B (by Motohiro KOSAKI)

#2516 e$B$H4XO"$7$F$$$^$9e(B

http://redmine.ruby-lang.org/issues/show/2747

e$B%A%1%C%He(B #2747 e$B$,99?7$5$l$^$7$?!#e(B (by Motohiro KOSAKI)

1.8.6e$B$G$N5sF0e(B

% /usr/bin/ruby -v duptest.rb
ruby 1.8.6 (2009-08-04 patchlevel 383) [x86_64-linux]
0
“1\n”
0
2

f1e$B$He(Bf2e$B$Ne(Bpose$B$,$:$l$F$$$k$N$G!"$3$l$b$*$+$7$$e(B


http://redmine.ruby-lang.org/issues/show/2747

e$B%A%1%C%He(B #2747 e$B$,99?7$5$l$^$7$?!#e(B (by Motohiro KOSAKI)

6e$B$NHkL)$Oe(Bstracee$B$,65$($F$/$l$F$$$ke(B

dup(4) = 5
lseek(4, 0, SEEK_CUR) = 0
lseek(5, 0, SEEK_SET) = 0
lseek(4, 0, SEEK_CUR) = 0
write(1, “0\n”, 20
) = 2
read(5, “1\n2\n3\n”, 8192) = 6
write(1, “"1\n"\n”, 6"1\n"
) = 6
lseek(4, 0, SEEK_CUR) = 6
write(1, “6\n”, 26
) = 2
lseek(5, -4, SEEK_CUR) = 2
lseek(5, 0, SEEK_CUR) = 2
write(1, “2\n”, 22
)

read(f2, buf,
8192)e$B$G%P%C%U%!%j%s%0FI$9~$$7$?$“$H!”%*%U%;%C%H$rLa$9$N$rK:$l$Fe(B
lseek(f1, 0, SEEK_CUR)
e$B$Ge(Bpose$B$rFI$_9~$`$N$G%U%!%$%k=*C<$Ne(Bpose$B$,F@$i$l$F$$$k!#e(B


http://redmine.ruby-lang.org/issues/show/2747

e$B%A%1%C%He(B #2747 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BRejectede$B$KJQ99e(B

e$B1sF#$G$9!#e(B

1.9.2 e$B$G$O;EMM$H$$$&$3$H$Ge(B reject e$B$7$^$9!#e(B([ruby-core:28335]
e$BB>e(B)

e$B$o$+$j$K$/$$5sF0$J$3$H$O3N$+$J$N$G!"e(B1.9.3 e$B0J9_$G$N2~A1$re(B
Feature
e$B%A%1%C%H$H$7$FJL$KEPO?$7$F$*$-$^$9!#e(B


Yusuke E. [email protected]

http://redmine.ruby-lang.org/issues/show/2747

kosaki e$B$5$se(B
e$B1sF#$G$9!#e(B

2010e$BG/e(B2e$B7ne(B15e$BF|e(B21:40 Motohiro KOSAKI
[email protected]:

6e$B$NHkL)$Oe(Bstracee$B$,65$($F$/$l$F$$$ke(B

snip

read(f2, buf, 8192)e$B$G%P%C%U%!%j%s%0FI$9~$$7$?$“$H!”%*%U%;%C%H$rLa$9$N$rK:$l$Fe(B
lseek(f1, 0, SEEK_CUR) e$B$Ge(Bpose$B$rFI$_9~$`$N$G%U%!%$%k=*C<$Ne(Bpose$B$,F@$i$l$F$$$k!#e(B

dup e$B$NA08e$G%P%C%U%!$r6&M-$7$F$$$J$$$N$,LdBj$G$9$h$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