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/unix.c | |
parent | 2819ae08d2787c83eb63e8526082a983fe9335c9 (diff) | |
download | gcc-15877a88eb5c78571ebc0f718e8ff2bf32c5cc5e.zip gcc-15877a88eb5c78571ebc0f718e8ff2bf32c5cc5e.tar.gz gcc-15877a88eb5c78571ebc0f718e8ff2bf32c5cc5e.tar.bz2 |
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/unix.c')
-rw-r--r-- | libgfortran/io/unix.c | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 3896f04..2958380 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -530,12 +530,10 @@ fd_alloc (unix_stream * s, gfc_offset where, * NULL on I/O error. */ static char * -fd_alloc_r_at (unix_stream * s, int *len, gfc_offset where) +fd_alloc_r_at (unix_stream * s, int *len) { gfc_offset m; - - if (where == -1) - where = s->logical_offset; + gfc_offset where = s->logical_offset; if (s->buffer != NULL && s->buffer_offset <= where && where + *len <= s->buffer_offset + s->active) @@ -593,12 +591,10 @@ fd_alloc_r_at (unix_stream * s, int *len, gfc_offset where) * we've already buffered the data or we need to load it. */ static char * -fd_alloc_w_at (unix_stream * s, int *len, gfc_offset where) +fd_alloc_w_at (unix_stream * s, int *len) { gfc_offset n; - - if (where == -1) - where = s->logical_offset; + gfc_offset where = s->logical_offset; if (s->buffer == NULL || s->buffer_offset > where || where + *len > s->buffer_offset + s->len) @@ -752,7 +748,7 @@ fd_sset (unix_stream * s, int c, size_t n) /* memset() in chunks of BUFFER_SIZE. */ trans = (bytes_left < BUFFER_SIZE) ? bytes_left : BUFFER_SIZE; - p = fd_alloc_w_at (s, &trans, -1); + p = fd_alloc_w_at (s, &trans); if (p) memset (p, c, trans); else @@ -779,7 +775,7 @@ fd_read (unix_stream * s, void * buf, size_t * nbytes) if (*nbytes < BUFFER_SIZE && s->method == SYNC_BUFFERED) { tmp = *nbytes; - p = fd_alloc_r_at (s, &tmp, -1); + p = fd_alloc_r_at (s, &tmp); if (p) { *nbytes = tmp; @@ -827,7 +823,7 @@ fd_write (unix_stream * s, const void * buf, size_t * nbytes) if (*nbytes < BUFFER_SIZE && s->method == SYNC_BUFFERED) { tmp = *nbytes; - p = fd_alloc_w_at (s, &tmp, -1); + p = fd_alloc_w_at (s, &tmp); if (p) { *nbytes = tmp; @@ -890,7 +886,6 @@ fd_open (unix_stream * s) else s->method = SYNC_BUFFERED; - s->st.alloc_r_at = (void *) fd_alloc_r_at; s->st.alloc_w_at = (void *) fd_alloc_w_at; s->st.sfree = (void *) fd_sfree; s->st.close = (void *) fd_close; @@ -918,12 +913,10 @@ fd_open (unix_stream * s) static char * -mem_alloc_r_at (int_stream * s, int *len, gfc_offset where) +mem_alloc_r_at (int_stream * s, int *len) { gfc_offset n; - - if (where == -1) - where = s->logical_offset; + gfc_offset where = s->logical_offset; if (where < s->buffer_offset || where > s->buffer_offset + s->active) return NULL; @@ -939,15 +932,13 @@ mem_alloc_r_at (int_stream * s, int *len, gfc_offset where) static char * -mem_alloc_w_at (int_stream * s, int *len, gfc_offset where) +mem_alloc_w_at (int_stream * s, int *len) { gfc_offset m; + gfc_offset where = s->logical_offset; assert (*len >= 0); /* Negative values not allowed. */ - if (where == -1) - where = s->logical_offset; - m = where + *len; if (where < s->buffer_offset) @@ -962,9 +953,7 @@ mem_alloc_w_at (int_stream * s, int *len, gfc_offset where) } -/* Stream read function for internal units. This is not actually used - at the moment, as all internal IO is formatted and the formatted IO - routines use mem_alloc_r_at. */ +/* Stream read function for internal units. */ static int mem_read (int_stream * s, void * buf, size_t * nbytes) @@ -973,7 +962,7 @@ mem_read (int_stream * s, void * buf, size_t * nbytes) int tmp; tmp = *nbytes; - p = mem_alloc_r_at (s, &tmp, -1); + p = mem_alloc_r_at (s, &tmp); if (p) { *nbytes = tmp; @@ -983,7 +972,7 @@ mem_read (int_stream * s, void * buf, size_t * nbytes) else { *nbytes = 0; - return errno; + return 0; } } @@ -998,10 +987,8 @@ mem_write (int_stream * s, const void * buf, size_t * nbytes) void *p; int tmp; - errno = 0; - tmp = *nbytes; - p = mem_alloc_w_at (s, &tmp, -1); + p = mem_alloc_w_at (s, &tmp); if (p) { *nbytes = tmp; @@ -1011,7 +998,7 @@ mem_write (int_stream * s, const void * buf, size_t * nbytes) else { *nbytes = 0; - return errno; + return 0; } } @@ -1038,7 +1025,7 @@ mem_set (int_stream * s, int c, size_t n) len = n; - p = mem_alloc_w_at (s, &len, -1); + p = mem_alloc_w_at (s, &len); if (p) { memset (p, c, len); @@ -1104,7 +1091,6 @@ open_internal (char *base, int length, gfc_offset offset) s->logical_offset = 0; s->active = s->file_length = length; - s->st.alloc_r_at = (void *) mem_alloc_r_at; s->st.alloc_w_at = (void *) mem_alloc_w_at; s->st.sfree = (void *) mem_sfree; s->st.close = (void *) mem_close; |