2 Free Software Foundation, Inc.
3 Contributed by Janne Blomqvist
5 This file is part of the GNU Fortran runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
32 /* Formatting buffer. This is a temporary scratch buffer used by
33 formatted read and writes. After every formatted I/O statement,
34 this buffer is flushed. This buffer is needed since not all devices
35 are seekable, and T or TL edit descriptors require moving backwards
36 in the record. However, advance='no' complicates the situation, so
37 the buffer must only be partially flushed from the end of the last
38 flush until the current position in the record. */
42 char *buf
; /* Start of buffer. */
43 int len
; /* Length of buffer. */
44 int act
; /* Active bytes in buffer. */
45 int pos
; /* Current position in buffer. */
48 extern void fbuf_init (gfc_unit
*, int);
49 internal_proto(fbuf_init
);
51 extern void fbuf_destroy (gfc_unit
*);
52 internal_proto(fbuf_destroy
);
54 extern int fbuf_reset (gfc_unit
*);
55 internal_proto(fbuf_reset
);
57 extern char * fbuf_alloc (gfc_unit
*, int);
58 internal_proto(fbuf_alloc
);
60 extern int fbuf_flush (gfc_unit
*, unit_mode
);
61 internal_proto(fbuf_flush
);
63 extern int fbuf_seek (gfc_unit
*, int, int);
64 internal_proto(fbuf_seek
);
66 extern char * fbuf_read (gfc_unit
*, int *);
67 internal_proto(fbuf_read
);
69 /* Never call this function, only use fbuf_getc(). */
70 extern int fbuf_getc_refill (gfc_unit
*);
71 internal_proto(fbuf_getc_refill
);
74 fbuf_getc (gfc_unit
* u
)
76 if (u
->fbuf
->pos
< u
->fbuf
->act
)
77 return (unsigned char) u
->fbuf
->buf
[u
->fbuf
->pos
++];
78 return fbuf_getc_refill (u
);
82 fbuf_getptr (gfc_unit
* u
)
84 return (char*) (u
->fbuf
->buf
+ u
->fbuf
->pos
);