diff options
Diffstat (limited to 'libgfortran/io/file_pos.c')
-rw-r--r-- | libgfortran/io/file_pos.c | 62 |
1 files changed, 56 insertions, 6 deletions
diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c index 5d247d9c6b3..fd6333a667e 100644 --- a/libgfortran/io/file_pos.c +++ b/libgfortran/io/file_pos.c @@ -104,21 +104,71 @@ static void unformatted_backspace (st_parameter_filepos *fpp, gfc_unit *u) { gfc_offset m, new; - int length; + GFC_INTEGER_4 m4; + GFC_INTEGER_8 m8; + int length, length_read; char *p; - length = sizeof (gfc_offset); + if (compile_options.record_marker == 0) + length = sizeof (gfc_offset); + else + length = compile_options.record_marker; + + length_read = length; - p = salloc_r_at (u->s, &length, + p = salloc_r_at (u->s, &length_read, file_position (u->s) - length); - if (p == NULL) + if (p == NULL || length_read != length) goto io_error; /* Only CONVERT_NATIVE and CONVERT_SWAP are valid here. */ if (u->flags.convert == CONVERT_NATIVE) - memcpy (&m, p, sizeof (gfc_offset)); + { + switch (compile_options.record_marker) + { + case 0: + memcpy (&m, p, sizeof(gfc_offset)); + break; + + case sizeof(GFC_INTEGER_4): + memcpy (&m4, p, sizeof (m4)); + m = m4; + break; + + case sizeof(GFC_INTEGER_8): + memcpy (&m8, p, sizeof (m8)); + m = m8; + break; + + default: + runtime_error ("Illegal value for record marker"); + break; + } + } else - reverse_memcpy (&m, p, sizeof (gfc_offset)); + { + switch (compile_options.record_marker) + { + case 0: + reverse_memcpy (&m, p, sizeof(gfc_offset)); + break; + + case sizeof(GFC_INTEGER_4): + reverse_memcpy (&m4, p, sizeof (m4)); + m = m4; + break; + + case sizeof(GFC_INTEGER_8): + reverse_memcpy (&m8, p, sizeof (m8)); + m = m8; + break; + + default: + runtime_error ("Illegal value for record marker"); + break; + } + + } if ((new = file_position (u->s) - m - 2*length) < 0) new = 0; |