From: ts Date: 2003-09-09T22:46:43+09:00 Subject: Re: IO#clone and 1.6 -> 1.8 question >>>>> "d" == dblack writes: d> I always get 20 lines of output. But when I clone fh, I start to get d> the behavior where one fh advances to EOF and the other doesn't. I'm d> afraid I'm still not seeing why cloning a file handle would or should d> cause any of this to happen. With your original example d> fh = File.new("nums") # 'nums' is 1..20, one integer per line d> puts fh.gets d> d> fd = fh.clone d> puts fd.gets d> d> puts fh.gets it do this (well with some more tests :-))) svg% cat nums 1 2 3 4 5 6 7 8 9 svg% svg% cat a.c #include main() { FILE *f1, *f2; char line[1024]; f1 = fopen("nums", "r"); line[0] = line[1] = line[2] = 0; fread(line, 1, 2, f1); printf("%s", line); fseeko(f1, 0L, SEEK_CUR); f2 = fdopen(dup(fileno(f1)), "r"); line[0] = line[1] = 0; fread(line, 1, 2, f2); printf("%s", line); line[0] = line[1] = 0; if (fread(line, 1, 2, f1) == 0) { printf("EOF\n"); } else { printf("%s", line); } } svg% svg% a.out 1 2 EOF svg% Guy Decoux