2021-01-04 10:26:59 +01:00
|
|
|
/* Copyright (C) 2009-2021 Free Software Foundation, Inc.
|
2009-11-02 23:14:20 +01:00
|
|
|
Contributed by Janne Blomqvist
|
|
|
|
|
|
|
|
This file is part of the GNU Fortran runtime library (libgfortran).
|
|
|
|
|
|
|
|
Libgfortran is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
Libgfortran is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#ifndef GFOR_FBUF_H
|
|
|
|
#define GFOR_FBUF_H
|
|
|
|
|
2009-11-19 21:23:03 +01:00
|
|
|
#include "io.h"
|
|
|
|
|
2009-11-02 23:14:20 +01:00
|
|
|
|
|
|
|
/* Formatting buffer. This is a temporary scratch buffer used by
|
|
|
|
formatted read and writes. After every formatted I/O 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. */
|
|
|
|
|
|
|
|
struct fbuf
|
|
|
|
{
|
|
|
|
char *buf; /* Start of buffer. */
|
2018-01-07 11:17:52 +01:00
|
|
|
size_t len; /* Length of buffer. */
|
|
|
|
size_t act; /* Active bytes in buffer. */
|
|
|
|
size_t pos; /* Current position in buffer. */
|
2009-11-02 23:14:20 +01:00
|
|
|
};
|
|
|
|
|
2018-01-07 11:17:52 +01:00
|
|
|
extern void fbuf_init (gfc_unit *, size_t);
|
2009-11-02 23:14:20 +01:00
|
|
|
internal_proto(fbuf_init);
|
|
|
|
|
|
|
|
extern void fbuf_destroy (gfc_unit *);
|
|
|
|
internal_proto(fbuf_destroy);
|
|
|
|
|
2018-01-07 11:17:52 +01:00
|
|
|
extern ptrdiff_t fbuf_reset (gfc_unit *);
|
2009-11-02 23:14:20 +01:00
|
|
|
internal_proto(fbuf_reset);
|
|
|
|
|
2018-01-07 11:17:52 +01:00
|
|
|
extern char *fbuf_alloc (gfc_unit *, size_t);
|
2009-11-02 23:14:20 +01:00
|
|
|
internal_proto(fbuf_alloc);
|
|
|
|
|
|
|
|
extern int fbuf_flush (gfc_unit *, unit_mode);
|
|
|
|
internal_proto(fbuf_flush);
|
|
|
|
|
2015-02-07 16:13:15 +01:00
|
|
|
extern int fbuf_flush_list (gfc_unit *, unit_mode);
|
|
|
|
internal_proto(fbuf_flush_list);
|
|
|
|
|
2018-01-07 11:17:52 +01:00
|
|
|
extern ptrdiff_t fbuf_seek (gfc_unit *, ptrdiff_t, int);
|
2009-11-02 23:14:20 +01:00
|
|
|
internal_proto(fbuf_seek);
|
|
|
|
|
2018-01-07 11:17:52 +01:00
|
|
|
extern char *fbuf_read (gfc_unit *, size_t *);
|
2009-11-02 23:14:20 +01:00
|
|
|
internal_proto(fbuf_read);
|
|
|
|
|
|
|
|
/* Never call this function, only use fbuf_getc(). */
|
|
|
|
extern int fbuf_getc_refill (gfc_unit *);
|
|
|
|
internal_proto(fbuf_getc_refill);
|
|
|
|
|
|
|
|
static inline int
|
2017-04-11 16:51:25 +02:00
|
|
|
fbuf_getc (gfc_unit *u)
|
2009-11-02 23:14:20 +01:00
|
|
|
{
|
|
|
|
if (u->fbuf->pos < u->fbuf->act)
|
|
|
|
return (unsigned char) u->fbuf->buf[u->fbuf->pos++];
|
|
|
|
return fbuf_getc_refill (u);
|
|
|
|
}
|
|
|
|
|
2011-02-23 07:59:51 +01:00
|
|
|
static inline char *
|
2017-04-11 16:51:25 +02:00
|
|
|
fbuf_getptr (gfc_unit *u)
|
2011-02-23 07:59:51 +01:00
|
|
|
{
|
|
|
|
return (char*) (u->fbuf->buf + u->fbuf->pos);
|
|
|
|
}
|
|
|
|
|
2009-11-02 23:14:20 +01:00
|
|
|
#endif
|