diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2007-03-26 03:23:15 +0000 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2007-03-26 03:23:15 +0000 |
commit | beb6a65e7573a9178764a1844d052cdeeb529322 (patch) | |
tree | 7005f5c75c7f6dbaca78f2f73008ed5b96700d1d /libgfortran/io | |
parent | 75b63e8b5b4a8b5bd7621edb8a4e2eefcc186981 (diff) | |
download | gcc-beb6a65e7573a9178764a1844d052cdeeb529322.zip gcc-beb6a65e7573a9178764a1844d052cdeeb529322.tar.gz gcc-beb6a65e7573a9178764a1844d052cdeeb529322.tar.bz2 |
re PR fortran/31199 (write with "t1" + nonadvancing transfer format gives wrong output)
2007-03-25 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libgfortran/31199
*io/io.h: Add saved_pos to gfc_unit structure.
*io/open.c (new_unit): Initialize saved_pos.
*io/transfer.c (data_transfer_init): Set max_pos to value in saved_pos.
(next_record_w): Fix whitespace.
(finalze_transfer): Calculate max_pos for ADVANCE="no" and save it for
later use. If not ADVANCE="no" set saved_pos to zero.
From-SVN: r123205
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/io.h | 2 | ||||
-rw-r--r-- | libgfortran/io/open.c | 1 | ||||
-rw-r--r-- | libgfortran/io/transfer.c | 13 |
3 files changed, 14 insertions, 2 deletions
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h index 26273d9..ef1a287 100644 --- a/libgfortran/io/io.h +++ b/libgfortran/io/io.h @@ -443,7 +443,7 @@ typedef struct gfc_unit struct gfc_unit *left, *right; int priority; - int read_bad, current_record; + int read_bad, current_record, saved_pos; enum { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE } endfile; diff --git a/libgfortran/io/open.c b/libgfortran/io/open.c index 8c6f9fb..44ff69d 100644 --- a/libgfortran/io/open.c +++ b/libgfortran/io/open.c @@ -423,6 +423,7 @@ new_unit (st_parameter_open *opp, gfc_unit *u, unit_flags * flags) u->mode = READING; u->maxrec = 0; u->bytes_left = 0; + u->saved_pos = 0; if (flags->position == POSITION_APPEND) { diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index 77e2ab1..94bda09 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -1951,6 +1951,10 @@ data_transfer_init (st_parameter_dt *dtp, int read_flag) dtp->u.p.blank_status = dtp->u.p.current_unit->flags.blank; dtp->u.p.sign_status = SIGN_S; + + /* Set the maximum position reached from the previous I/O operation. This + could be greater than zero from a previous non-advancing write. */ + dtp->u.p.max_pos = dtp->u.p.current_unit->saved_pos; pre_position (dtp); @@ -2461,7 +2465,6 @@ next_record_w (st_parameter_dt *dtp, int done) } else { - /* If this is the last call to next_record move to the farthest position reached in preparation for completing the record. (for file unit) */ @@ -2603,12 +2606,20 @@ finalize_transfer (st_parameter_dt *dtp) return; } + /* For non-advancing I/O, save the current maximum position for use in the + next I/O operation if needed. */ if (dtp->u.p.advance_status == ADVANCE_NO) { + int bytes_written = (int) (dtp->u.p.current_unit->recl + - dtp->u.p.current_unit->bytes_left); + dtp->u.p.current_unit->saved_pos = + dtp->u.p.max_pos > 0 ? dtp->u.p.max_pos - bytes_written : 0; flush (dtp->u.p.current_unit->s); return; } + dtp->u.p.current_unit->saved_pos = 0; + next_record (dtp, 1); sfree (dtp->u.p.current_unit->s); } |