From ee56ac9def714d225c4c7d1020390241780595c0 Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Thu, 30 Apr 2009 18:12:37 +0300 Subject: Fix PR libfortran/39667 From-SVN: r147004 --- libgfortran/ChangeLog | 7 +++++++ libgfortran/io/file_pos.c | 20 +------------------- libgfortran/io/intrinsics.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 19 deletions(-) (limited to 'libgfortran') 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 + + 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 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) -- cgit v1.1