diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2008-05-15 18:53:34 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2008-05-15 18:53:34 +0300 |
commit | 15877a88eb5c78571ebc0f718e8ff2bf32c5cc5e (patch) | |
tree | 92c8aa4fe936ead640e8d996aa90baaf7c81a1a9 /libgfortran/io/file_pos.c | |
parent | 2819ae08d2787c83eb63e8526082a983fe9335c9 (diff) | |
download | gcc-15877a88eb5c78571ebc0f718e8ff2bf32c5cc5e.tar.gz |
Part 1 of PR 25561.
2008-05-15 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/25561
* Makefile.am: Add fbuf.c to gfor_io_src.
* Makefile.in: Regenerate.
* io/io.h (read_block): Remove.
(struct stream): Remove alloc_r_at function pointer.
(salloc_r): Remove.
(salloc_r_at): Remove.
(salloc_w_at): Remove.
(salloc_w): Remove offset argument.
(struct fbuf): New struct for format buffer.
(struct gfc_unit): Add fbuf.
(read_block_form): New prototype.
(fbuf_init): Likewise.
(fbuf_destroy): Likewise.
(fbuf_reset): Likewise.
(fbuf_alloc): Likewise.
(fbuf_flush): Likewise.
(fbuf_seek): Likewise.
* io/file_pos.c (formatted_backspace): Change to use sread.
(unformatted_backspace): Likewise.
(st_backspace): Flush format buffer.
(st_rewind): Likewise.
* io/list_read.c (next_char): Likewise.
(nml_query): Tidying, flush format buffer.
* io/open.c (new_unit): Init format buffer.
* io/read.c (read_l): Change to use read_block_form.
(read_a): Likewise.
(read_decimal): Likewise.
(read_radix): Likewise.
(read_f): Likewise.
(read_x): Empty reads also for stream I/O.
* io/transfer.c (read_sf): Change to use sread.
(read_block): Rename to read_block_form, change prototype, use sread.
(read_block_direct): Don't seek stream files.
(write_block): Change to use fbuf if external file, don't seek stream
files.
(write_buf): Don't seek stream files.
(formatted_transfer_scalar): Use fbuf for external files.
(us_read): Change to use sread.
(pre_position): Do nothing for stream I/O.
(data_transfer_init): Flush fbuf when switching from write to read, if
POS is specified, seek stream file to correct offset.
(skip_record): Change to use sread.
(min_off): New function.
(next_record_r): Change to use sread.
(next_record_w): Change to use sset/sseek, flush fbuf.
(finalize_transfer): Flush fbuf.
* io/unit.c (init_units): Init fbuf for stdout, stderr.
(close_unit_1): Destroy fbuf.
(finish_last_advance_record): Flush fbuf, no need to seek.
* io/unix.c (fd_alloc_r_at): Remove unused where argument.
(fd_alloc_w_at): Likewise.
(fd_read): Remove third argument to fd_alloc_r_at.
(fd_write): Remove third argument to fd_alloc_w_at.
(fd_sset): Likewise.
(fd_open): Don't set alloc_r_at.
(mem_alloc_r_at): Remove unused where argument.
(mem_alloc_w_at): Likewise.
(mem_read): Don't incorrectly return previous errno, remove unused
third argument to alloc function.
(mem_write): Likewise.
(mem_set): Likewise.
(open_internal): Don't set alloc_r_at pointer.
* io/fbuf.c: New file.
From-SVN: r135373
Diffstat (limited to 'libgfortran/io/file_pos.c')
-rw-r--r-- | libgfortran/io/file_pos.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/libgfortran/io/file_pos.c b/libgfortran/io/file_pos.c index 94e29899fb1..f4864884f33 100644 --- a/libgfortran/io/file_pos.c +++ b/libgfortran/io/file_pos.c @@ -39,14 +39,14 @@ Boston, MA 02110-1301, USA. */ record, and we have to sift backwards to find the newline before that or the start of the file, whichever comes first. */ -#define READ_CHUNK 4096 +static const unsigned int READ_CHUNK = 4096; static void formatted_backspace (st_parameter_filepos *fpp, gfc_unit *u) { gfc_offset base; - char *p; - int n; + char p[READ_CHUNK]; + size_t n; base = file_position (u->s) - 1; @@ -54,9 +54,9 @@ formatted_backspace (st_parameter_filepos *fpp, gfc_unit *u) { n = (base < READ_CHUNK) ? base : READ_CHUNK; base -= n; - - p = salloc_r_at (u->s, &n, base); - if (p == NULL) + if (sseek (u->s, base) == FAILURE) + goto io_error; + if (sread (u->s, p, &n) != 0) goto io_error; /* We have moved backwards from the current position, it should @@ -66,15 +66,14 @@ formatted_backspace (st_parameter_filepos *fpp, gfc_unit *u) /* There is no memrchr() in the C library, so we have to do it ourselves. */ - n--; - while (n >= 0) + while (n > 0) { + n--; if (p[n] == '\n') { base += n + 1; goto done; } - n--; } } @@ -104,9 +103,9 @@ unformatted_backspace (st_parameter_filepos *fpp, gfc_unit *u) gfc_offset m, new; GFC_INTEGER_4 m4; GFC_INTEGER_8 m8; - int length, length_read; + size_t length; int continued; - char *p; + char p[sizeof (GFC_INTEGER_8)]; if (compile_options.record_marker == 0) length = sizeof (GFC_INTEGER_4); @@ -115,12 +114,10 @@ unformatted_backspace (st_parameter_filepos *fpp, gfc_unit *u) do { - length_read = length; - - p = salloc_r_at (u->s, &length_read, - file_position (u->s) - length); - if (p == NULL || length_read != length) - goto io_error; + if (sseek (u->s, file_position (u->s) - length) == FAILURE) + goto io_error; + if (sread (u->s, p, &length) != 0) + goto io_error; /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here. */ if (u->flags.convert == GFC_CONVERT_NATIVE) @@ -216,6 +213,9 @@ st_backspace (st_parameter_filepos *fpp) goto done; } + /* Make sure format buffer is flushed. */ + fbuf_flush (u, 1); + /* Check for special cases involving the ENDFILE record first. */ if (u->endfile == AFTER_ENDFILE) |