diff options
Diffstat (limited to 'libgfortran/io/backspace.c')
-rw-r--r-- | libgfortran/io/backspace.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/libgfortran/io/backspace.c b/libgfortran/io/backspace.c index f8ab01c3488..d4ba3a9baaa 100644 --- a/libgfortran/io/backspace.c +++ b/libgfortran/io/backspace.c @@ -28,6 +28,7 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "config.h" +#include <string.h> #include "libgfortran.h" #include "io.h" @@ -101,17 +102,19 @@ formatted_backspace (void) static void unformatted_backspace (void) { - gfc_offset *p, new; + gfc_offset m, new; int length; + char *p; length = sizeof (gfc_offset); - p = (gfc_offset *) salloc_r_at (current_unit->s, &length, - file_position (current_unit->s) - length); + p = salloc_r_at (current_unit->s, &length, + file_position (current_unit->s) - length); if (p == NULL) goto io_error; - new = file_position (current_unit->s) - *p - length; + memcpy (&m, p, sizeof (gfc_offset)); + new = file_position (current_unit->s) - m - 2*length; if (sseek (current_unit->s, new) == FAILURE) goto io_error; @@ -155,16 +158,23 @@ st_backspace (void) u->endfile = AT_ENDFILE; else { - if (u->current_record) - next_record (1); - if (file_position (u->s) == 0) goto done; /* Common special case */ + if (u->mode == WRITING) + { + flush (u->s); + struncate (u->s); + u->mode = READING; + } + if (u->flags.form == FORM_FORMATTED) formatted_backspace (); else unformatted_backspace (); + + u->endfile = NO_ENDFILE; + u->current_record = 0; } done: |