http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30162
--- Comment #43 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2013-02-17 20:10:52 UTC --- I finally had a look at this PR. First the test on comment #41 works on x86_64-apple-darwin10 r196109: macbook] f90/bug% mkfifo pipe [macbook] f90/bug% read_f & [1] 6998 [macbook] f90/bug% write_f Hello, world! [macbook] f90/bug% [1] Done read_f I have done the following changes to the original test: [macbook] f90/bug% cat pr30162_1_db.f integer status integer i open(unit=20,file='np',action='write', & form='unformatted',iostat=status); print*,'status for write from open is ',status do i = 1,5 print *, "write ", i write(20)i end do end [macbook] f90/bug% cat pr30162_2_db.f integer status integer i integer val open(unit=21,file='np',action='read', & form='unformatted',iostat=status); print*,'status for read from open is ',status do i = 1,5 read(21)val print*,val end do end and I got [macbook] f90/bug% write_f status for write from open is 0 write 1 At line 8 of file pr30162_1_db.f (unit = 20, file = 'np') Fortran runtime error: Illegal seek status for read from open is 0 At line 8 of file pr30162_2_db.f (unit = 21, file = 'np') Fortran runtime error: I/O past end of record on unformatted file [macbook] f90/bug% [1] Exit 2 read_f Then I have applied the following patch (based on r194679): --- ../_clean/libgfortran/io/unix.c 2013-01-14 19:25:10.000000000 +0100 +++ libgfortran/io/unix.c 2013-02-17 20:23:43.000000000 +0100 @@ -336,7 +336,14 @@ raw_write (unix_stream * s, const void * static gfc_offset raw_seek (unix_stream * s, gfc_offset offset, int whence) { - return lseek (s->fd, offset, whence); + gfc_offset x; + x = lseek (s->fd, offset, whence); + /* Non-seekable files should always be assumed to be at + current position. */ + if (x == -1 && errno == ESPIPE) + x = 0; + return x; + /* return lseek (s->fd, offset, whence); */ } static gfc_offset and now I get [macbook] f90/bug% write_f status for write from open is 0 write 1 write 2 write 3 write 4 write 5 status for read from open is 0 At line 8 of file pr30162_2_db.f (unit = 21, file = 'np') Fortran runtime error: I/O past end of record on unformatted file [macbook] f90/bug% [1] Exit 2 read_f So the write seems now OK. For the read, dtrace gives fstat64(0x3, 0x7FFF5FBFD580, 0x50) = 0 0 fstat64(0x3, 0x7FFF5FBFD5C0, 0x0) = 0 0 lseek(0x3, 0x0, 0x1) = -1 Err#29 write(0x1, " status for read from open is 0\n\0", 0x2B) = 43 0 read(0x3, "\0", 0x4) = 4 0 read(0x3, "\0", 0x0) = 0 0 lseek(0x3, 0x4, 0x1) = -1 Err#29 write(0x2, "At line 8 of file pr30162_2_db.f (unit = 21, file = 'np')\n\0", 0x3A) = 58 0 write(0x2, "Fortran runtime error: \0", 0x17) = 23 0 write(0x2, "I/O past end of record on unformatted file\0", 0x2A) = 42 0 write(0x2, "\n\0", 0x1) = 1 0 close(0x3) = 0 0 i.e., 2 errors #29 on lseek. I did not find out how this is connected to the error "I/O past end of record on unformatted file".