summaryrefslogtreecommitdiff
path: root/libgfortran/io/io.h
diff options
context:
space:
mode:
authorjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2008-05-15 15:53:34 +0000
committerjb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>2008-05-15 15:53:34 +0000
commitd875179d7d2d8f4aa45d4f06379b3b1b111ac43b (patch)
tree92c8aa4fe936ead640e8d996aa90baaf7c81a1a9 /libgfortran/io/io.h
parente66b310fb9a3ddc7ed5143db3c468711c8a36d08 (diff)
downloadgcc-d875179d7d2d8f4aa45d4f06379b3b1b111ac43b.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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135373 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran/io/io.h')
-rw-r--r--libgfortran/io/io.h54
1 files changed, 45 insertions, 9 deletions
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h
index 30d4051f126..e554d8cccbc 100644
--- a/libgfortran/io/io.h
+++ b/libgfortran/io/io.h
@@ -49,8 +49,7 @@ struct st_parameter_dt;
typedef struct stream
{
- char *(*alloc_w_at) (struct stream *, int *, gfc_offset);
- char *(*alloc_r_at) (struct stream *, int *, gfc_offset);
+ char *(*alloc_w_at) (struct stream *, int *);
try (*sfree) (struct stream *);
try (*close) (struct stream *);
try (*seek) (struct stream *, gfc_offset);
@@ -70,11 +69,7 @@ io_mode;
#define sfree(s) ((s)->sfree)(s)
#define sclose(s) ((s)->close)(s)
-#define salloc_r(s, len) ((s)->alloc_r_at)(s, len, -1)
-#define salloc_w(s, len) ((s)->alloc_w_at)(s, len, -1)
-
-#define salloc_r_at(s, len, where) ((s)->alloc_r_at)(s, len, where)
-#define salloc_w_at(s, len, where) ((s)->alloc_w_at)(s, len, where)
+#define salloc_w(s, len) ((s)->alloc_w_at)(s, len)
#define sseek(s, pos) ((s)->seek)(s, pos)
#define struncate(s) ((s)->trunc)(s)
@@ -528,6 +523,25 @@ typedef struct
unit_flags;
+/* Formatting buffer. This is a temporary scratch buffer. Currently used only
+ by formatted writes. After every
+ formatted write statement, this buffer is flushed. This buffer is needed since
+ not all devices are seekable, and T or TL edit descriptors require
+ moving backwards in the record. However, advance='no' complicates the
+ situation, so the buffer must only be partially flushed from the end of the
+ last flush until the current position in the record. */
+
+typedef struct fbuf
+{
+ char *buf; /* Start of buffer. */
+ size_t len; /* Length of buffer. */
+ size_t act; /* Active bytes in buffer. */
+ size_t flushed; /* Flushed bytes from beginning of buffer. */
+ char *ptr; /* Current position in buffer. */
+}
+fbuf;
+
+
typedef struct gfc_unit
{
int unit_number;
@@ -578,6 +592,9 @@ typedef struct gfc_unit
int file_len;
char *file;
+
+ /* Formatting buffer. */
+ struct fbuf *fbuf;
}
gfc_unit;
@@ -812,8 +829,8 @@ internal_proto(free_format_data);
extern const char *type_name (bt);
internal_proto(type_name);
-extern void *read_block (st_parameter_dt *, int *);
-internal_proto(read_block);
+extern try read_block_form (st_parameter_dt *, void *, size_t *);
+internal_proto(read_block_form);
extern char *read_sf (st_parameter_dt *, int *, int);
internal_proto(read_sf);
@@ -931,6 +948,25 @@ internal_proto(size_from_real_kind);
extern size_t size_from_complex_kind (int);
internal_proto(size_from_complex_kind);
+/* fbuf.c */
+extern void fbuf_init (gfc_unit *, size_t);
+internal_proto(fbuf_init);
+
+extern void fbuf_destroy (gfc_unit *);
+internal_proto(fbuf_destroy);
+
+extern void fbuf_reset (gfc_unit *);
+internal_proto(fbuf_reset);
+
+extern char * fbuf_alloc (gfc_unit *, size_t);
+internal_proto(fbuf_alloc);
+
+extern int fbuf_flush (gfc_unit *, int);
+internal_proto(fbuf_flush);
+
+extern int fbuf_seek (gfc_unit *, gfc_offset);
+internal_proto(fbuf_seek);
+
/* lock.c */
extern void free_ionml (st_parameter_dt *);
internal_proto(free_ionml);