aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorJanne Blomqvist <jb@gcc.gnu.org>2009-04-30 18:12:37 +0300
committerJanne Blomqvist <jb@gcc.gnu.org>2009-04-30 18:12:37 +0300
commitee56ac9def714d225c4c7d1020390241780595c0 (patch)
tree164be18da851f117899e247478ee56e7245b26dc /libgfortran
parent43fcece879afabd701904209451ca9182f251c48 (diff)
downloadgcc-ee56ac9def714d225c4c7d1020390241780595c0.zip
gcc-ee56ac9def714d225c4c7d1020390241780595c0.tar.gz
gcc-ee56ac9def714d225c4c7d1020390241780595c0.tar.bz2
Fix PR libfortran/39667
From-SVN: r147004
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog7
-rw-r--r--libgfortran/io/file_pos.c20
-rw-r--r--libgfortran/io/intrinsics.c14
3 files changed, 22 insertions, 19 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 6763ad1..8b2fb21 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,10 @@
+2009-04-30 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR libfortran/39667
+ * io/file_pos.c (st_rewind): Don't truncate or flush.
+ * io/intrinsics.c (fgetc): Flush if switching mode.
+ (fputc): Likewise.
+
2009-04-18 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/39782
diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c
index 8499232..c169017 100644
--- a/libgfortran/io/file_pos.c
+++ b/libgfortran/io/file_pos.c
@@ -341,26 +341,8 @@ st_rewind (st_parameter_filepos *fpp)
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
- statements do not delete the file contents. */
- if (u->mode == WRITING)
- {
- /* unit_truncate takes care of flushing. */
- unit_truncate (u, stell (u->s), &fpp->common);
- /* .. but we still need to reset since we're going to seek. */
- fbuf_reset (u);
- }
- else
- {
- /* Make sure buffers are reset. */
- if (u->flags.form == FORM_FORMATTED)
- fbuf_reset (u);
- sflush (u->s);
- }
+ fbuf_reset (u);
- u->mode = READING;
u->last_record = 0;
if (sseek (u->s, 0, SEEK_SET) < 0)
diff --git a/libgfortran/io/intrinsics.c b/libgfortran/io/intrinsics.c
index 0a894aa..0e33e84 100644
--- a/libgfortran/io/intrinsics.c
+++ b/libgfortran/io/intrinsics.c
@@ -46,6 +46,13 @@ PREFIX(fgetc) (const int * unit, char * c, gfc_charlen_type c_len)
if (u == NULL)
return -1;
+ fbuf_reset (u);
+ if (u->mode == WRITING)
+ {
+ sflush (u->s);
+ u->mode = READING;
+ }
+
memset (c, ' ', c_len);
ret = sread (u->s, c, 1);
unlock_unit (u);
@@ -118,6 +125,13 @@ PREFIX(fputc) (const int * unit, char * c,
if (u == NULL)
return -1;
+ fbuf_reset (u);
+ if (u->mode == READING)
+ {
+ sflush (u->s);
+ u->mode = WRITING;
+ }
+
s = swrite (u->s, c, 1);
unlock_unit (u);
if (s < 0)