[Patch, libfortran, 1/3] Simplify handling of special files

Janne Blomqvist blomqvist.janne@gmail.com
Tue Oct 18 15:11:00 GMT 2011


Hi,

in a few places in libgfortran we have some code for handling special
and/or non-seekable files differently. The problem is that special
files don't all have some nice consistent behavior. E.g. wrt. seeking,
some allow seeking just fine, others allow some seeks and not others,
others allow them but always return an offset of 0, and yet others
fail the seek completely.

The Fortran standard doesn't really help here except for noting that
some files may not be positionable, and thus statements requiring the
file position to be modified may fail on such files.

Obviously, libgfortran itself cannot enumerate all the possible
variations for how a special file may behave, and trying to impose
some kind of least common denominator may hide essential capability.
Having thought about this, my conclusion is that the only thing that
makes sense is that we do what the caller asks us to do, and if that
fails, we report the error back to the caller and let the caller
handle it. The attached patch implements this.

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

2011-10-18  Janne Blomqvist  <jb@gcc.gnu.org>

	* io/file_pos.c (st_rewind): Handle regular and special files
	identically.
	* io/intrinsics.c (fseek_sub): Don't check whether we think the
	file is seekable, just do what the caller says.
	* io/transfer.c (skip_record): First try to seek, then fallback to
	reading and throwing away what we read.
	* io/unit.c (update_position): Don't check whether file is
	seekable, just try to do what we're told.
	(unit_truncate): Likewise.
	* io/unix.c (struct unix_stream): Remove special_file flag.
	(buf_flush): Remove code for handling unseekable files.
	(buf_seek): Likewise.
	(fd_to_stream): Use buffered IO only for regular files.
	(file_length): Remove is_seekable() call.
	(is_seekable): Remove function.
	(is_special): Likewise.
	* io/unix.h: Remove prototypes for is_seekable and is_special.


-- 
Janne Blomqvist
-------------- next part --------------
A non-text attachment was scrubbed...
Name: seekable1.diff
Type: text/x-patch
Size: 10731 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20111018/f57cf422/attachment.bin>


More information about the Gcc-patches mailing list