diff options
author | bdavis <bdavis@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-27 07:59:30 +0000 |
---|---|---|
committer | bdavis <bdavis@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-08-27 07:59:30 +0000 |
commit | 95bfa7b376344bf3e0dab4b515b34ffd77414e24 (patch) | |
tree | 4050f4a405b432378b98cbcd6661afa4a1f0be61 /libgfortran | |
parent | 5e1a75c5bb2b9881d906142ed8e1a320ec1dbfc5 (diff) | |
download | gcc-95bfa7b376344bf3e0dab4b515b34ffd77414e24.tar.gz |
2004-08-27 Bud Davis <bdavis9659@comcast.net>
PR fortran/16597
* io/io.h: created typedef for unit_mode.
* io/io.h (gfc_unit): added mode to unit structure.
* io/transfer.c (data_transfer_init): flush if a write then
read is done on a unit (direct access files).
* io/rewind.c (st_rewind): Used unit mode instead of global.
* gfortran.dg/pr16597.f90: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@86654 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 9 | ||||
-rw-r--r-- | libgfortran/io/io.h | 7 | ||||
-rw-r--r-- | libgfortran/io/rewind.c | 2 | ||||
-rw-r--r-- | libgfortran/io/transfer.c | 8 |
4 files changed, 22 insertions, 4 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 33e16c9dd31..e0039ec0ac9 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,12 @@ +2004-08-27 Bud Davis <bdavis9659@comcast.net> + + PR fortran/16597 + * io/io.h: created typedef for unit_mode. + * io/io.h (gfc_unit): added mode to unit structure. + * io/transfer.c (data_transfer_init): flush if a write then + read is done on a unit (direct access files). + * io/rewind.c (st_rewind): Used unit mode instead of global. + 2004-08-24 Bud Davis <bdavis9659@comcast.net> PR fortran/17143 diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h index 796a6247f21..d2c15af7ec7 100644 --- a/libgfortran/io/io.h +++ b/libgfortran/io/io.h @@ -144,7 +144,9 @@ typedef enum { ADVANCE_YES, ADVANCE_NO, ADVANCE_UNSPECIFIED } unit_advance; - +typedef enum +{READING, WRITING} +unit_mode; /* Statement parameters. These are all the things that can appear in an I/O statement. Some are inputs and some are outputs, but none @@ -271,6 +273,7 @@ typedef struct gfc_unit { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE } endfile; + unit_mode mode; unit_flags flags; gfc_offset recl, last_record, maxrec, bytes_left; @@ -299,7 +302,7 @@ typedef struct gfc_unit *unit_root; int seen_dollar; - enum {READING, WRITING} mode; + unit_mode mode; unit_blank blank_status; enum {SIGN_S, SIGN_SS, SIGN_SP} sign_status; diff --git a/libgfortran/io/rewind.c b/libgfortran/io/rewind.c index 76fd1948e05..d9758a6d5ec 100644 --- a/libgfortran/io/rewind.c +++ b/libgfortran/io/rewind.c @@ -40,7 +40,7 @@ st_rewind (void) "Cannot REWIND a file opened for DIRECT access"); else { - if (g.mode==WRITING) + if (u->mode==WRITING) struncate(u->s); u->last_record = 0; if (sseek (u->s, 0) == FAILURE) diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c index b6f7c0e0129..3800d0b90cb 100644 --- a/libgfortran/io/transfer.c +++ b/libgfortran/io/transfer.c @@ -1044,13 +1044,19 @@ data_transfer_init (int read_flag) return; } - /* Position the file. */ + /* Check to see if we might be reading what we wrote before */ + + if (g.mode == READING && current_unit->mode == WRITING) + flush(current_unit->s); + /* Position the file. */ if (sseek (current_unit->s, (ioparm.rec - 1) * current_unit->recl) == FAILURE) generate_error (ERROR_OS, NULL); } + current_unit->mode = g.mode; + /* Set the initial value of flags. */ g.blank_status = current_unit->flags.blank; |