diff options
author | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-12-13 19:35:09 +0000 |
---|---|---|
committer | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-12-13 19:35:09 +0000 |
commit | 442c1e06790600fe721015acaa931f030d33eb03 (patch) | |
tree | 7ee9f3011890308864977fc29d3c36da9d6ab850 /libgfortran/io/file_pos.c | |
parent | 05da47ad3b9968881f0bfe4e1d63e19b1e04b770 (diff) | |
download | gcc-442c1e06790600fe721015acaa931f030d33eb03.tar.gz |
2007-12-13 Thomas Koenig <tkoenig@gcc.gnu.org>
PR libfortran/34370
PR libfortran/34323
PR libfortran/34405
* io/io.h: Add previous_nonadvancing_write to gfc_unit.
Add prototype for finish_last_advance_record.
* io/file_pos.c (st_backspace): Generate error if backspace is
attempted for direct access or unformatted stream.
If there are bytes left from a previous ADVANCE="no", write
them out before performing the backspace.
(st_endfile): Generate error if endfile is attempted for
direct access.
If there are bytes left from a previous ADVANCE="no", write
them out before performing the endfile.
(st_rewind): Generate error if rewind is attempted for
direct access.
* unit.c (close_unit_1): Move functionality to write
previously written bytes to...
(finish_last_advance_record): ... here.
* transfer.c (data_transfer_init): If reading, reset
previous_nonadvancing_write.
(finalize_transfer): Set the previous_noadvancing_write
flag if we are writing and ADVANCE="no" was specified.
Only call next_record() if advance="no" wasn't specified.
2007-12-13 Thomas Koenig <tkoenig@gcc.gnu.org>
PR libfortran/34370
PR libfortran/34323
PR libfortran/34405
* gfortran.dg/advance_6.f90: New test case.
* gfortran.dg/direct_io_7.f90: New test case.
* gfortran.dg/streamio_13.f90: New test case.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130912 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/io/file_pos.c')
-rw-r--r-- | libgfortran/io/file_pos.c | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c index 96e5e243787..94e29899fb1 100644 --- a/libgfortran/io/file_pos.c +++ b/libgfortran/io/file_pos.c @@ -199,12 +199,22 @@ st_backspace (st_parameter_filepos *fpp) goto done; } - /* Ignore direct access. Non-advancing I/O is only allowed for formatted - sequential I/O and the next direct access transfer repositions the file - anyway. */ + /* Direct access is prohibited, and so is unformatted stream access. */ - if (u->flags.access == ACCESS_DIRECT || u->flags.access == ACCESS_STREAM) - goto done; + + if (u->flags.access == ACCESS_DIRECT) + { + generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT, + "Cannot BACKSPACE a file opened for DIRECT access"); + goto done; + } + + if (u->flags.access == ACCESS_STREAM && u->flags.form == FORM_UNFORMATTED) + { + generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT, + "Cannot BACKSPACE an unformatted stream file"); + goto done; + } /* Check for special cases involving the ENDFILE record first. */ @@ -224,6 +234,15 @@ st_backspace (st_parameter_filepos *fpp) if (u->mode == WRITING) { + /* If there are previously written bytes from a write with + ADVANCE="no", add a record marker before performing the + BACKSPACE. */ + + if (u->previous_nonadvancing_write) + finish_last_advance_record (u); + + u->previous_nonadvancing_write = 0; + flush (u->s); struncate (u->s); u->mode = READING; @@ -261,6 +280,22 @@ st_endfile (st_parameter_filepos *fpp) u = find_unit (fpp->common.unit); if (u != NULL) { + if (u->flags.access == ACCESS_DIRECT) + { + generate_error (&fpp->common, LIBERROR_OPTION_CONFLICT, + "Cannot perform ENDFILE on a file opened" + " for DIRECT access"); + goto done; + } + + /* If there are previously written bytes from a write with ADVANCE="no", + add a record marker before performing the ENDFILE. */ + + if (u->previous_nonadvancing_write) + finish_last_advance_record (u); + + u->previous_nonadvancing_write = 0; + if (u->current_record) { st_parameter_dt dtp; @@ -274,6 +309,7 @@ st_endfile (st_parameter_filepos *fpp) struncate (u->s); u->endfile = AFTER_ENDFILE; update_position (u); + done: unlock_unit (u); } @@ -299,6 +335,14 @@ st_rewind (st_parameter_filepos *fpp) "Cannot REWIND a file opened for DIRECT access"); else { + /* If there are previously written bytes from a write with ADVANCE="no", + add a record marker before performing the ENDFILE. */ + + if (u->previous_nonadvancing_write) + finish_last_advance_record (u); + + u->previous_nonadvancing_write = 0; + /* Flush the buffers. If we have been writing to the file, the last written record is the last record in the file, so truncate the file now. Reset to read mode so two consecutive rewind |