1*b1e83836Smrg /* Copyright (C) 2009-2022 Free Software Foundation, Inc.
2181254a7Smrg Contributed by Janne Blomqvist
3181254a7Smrg
4181254a7Smrg This file is part of the GNU Fortran runtime library (libgfortran).
5181254a7Smrg
6181254a7Smrg Libgfortran is free software; you can redistribute it and/or modify
7181254a7Smrg it under the terms of the GNU General Public License as published by
8181254a7Smrg the Free Software Foundation; either version 3, or (at your option)
9181254a7Smrg any later version.
10181254a7Smrg
11181254a7Smrg Libgfortran is distributed in the hope that it will be useful,
12181254a7Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
13181254a7Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14181254a7Smrg GNU General Public License for more details.
15181254a7Smrg
16181254a7Smrg Under Section 7 of GPL version 3, you are granted additional
17181254a7Smrg permissions described in the GCC Runtime Library Exception, version
18181254a7Smrg 3.1, as published by the Free Software Foundation.
19181254a7Smrg
20181254a7Smrg You should have received a copy of the GNU General Public License and
21181254a7Smrg a copy of the GCC Runtime Library Exception along with this program;
22181254a7Smrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23181254a7Smrg <http://www.gnu.org/licenses/>. */
24181254a7Smrg
25181254a7Smrg #ifndef GFOR_UNIX_H
26181254a7Smrg #define GFOR_UNIX_H
27181254a7Smrg
28181254a7Smrg #include "io.h"
29181254a7Smrg
30181254a7Smrg struct stream_vtable
31181254a7Smrg {
32181254a7Smrg ssize_t (* const read) (struct stream *, void *, ssize_t);
33181254a7Smrg ssize_t (* const write) (struct stream *, const void *, ssize_t);
34181254a7Smrg gfc_offset (* const seek) (struct stream *, gfc_offset, int);
35181254a7Smrg gfc_offset (* const tell) (struct stream *);
36181254a7Smrg gfc_offset (* const size) (struct stream *);
37181254a7Smrg /* Avoid keyword truncate due to AIX namespace collision. */
38181254a7Smrg int (* const trunc) (struct stream *, gfc_offset);
39181254a7Smrg int (* const flush) (struct stream *);
40181254a7Smrg int (* const close) (struct stream *);
41181254a7Smrg int (* const markeor) (struct stream *);
42181254a7Smrg };
43181254a7Smrg
44181254a7Smrg struct stream
45181254a7Smrg {
46181254a7Smrg const struct stream_vtable *vptr;
47181254a7Smrg };
48181254a7Smrg
49181254a7Smrg /* Inline functions for doing file I/O given a stream. */
50181254a7Smrg static inline ssize_t
sread(stream * s,void * buf,ssize_t nbyte)51181254a7Smrg sread (stream *s, void *buf, ssize_t nbyte)
52181254a7Smrg {
53181254a7Smrg return s->vptr->read (s, buf, nbyte);
54181254a7Smrg }
55181254a7Smrg
56181254a7Smrg static inline ssize_t
swrite(stream * s,const void * buf,ssize_t nbyte)57181254a7Smrg swrite (stream *s, const void *buf, ssize_t nbyte)
58181254a7Smrg {
59181254a7Smrg return s->vptr->write (s, buf, nbyte);
60181254a7Smrg }
61181254a7Smrg
62181254a7Smrg static inline gfc_offset
sseek(stream * s,gfc_offset offset,int whence)63181254a7Smrg sseek (stream *s, gfc_offset offset, int whence)
64181254a7Smrg {
65181254a7Smrg return s->vptr->seek (s, offset, whence);
66181254a7Smrg }
67181254a7Smrg
68181254a7Smrg static inline gfc_offset
stell(stream * s)69181254a7Smrg stell (stream *s)
70181254a7Smrg {
71181254a7Smrg return s->vptr->tell (s);
72181254a7Smrg }
73181254a7Smrg
74181254a7Smrg static inline gfc_offset
ssize(stream * s)75181254a7Smrg ssize (stream *s)
76181254a7Smrg {
77181254a7Smrg return s->vptr->size (s);
78181254a7Smrg }
79181254a7Smrg
80181254a7Smrg static inline int
struncate(stream * s,gfc_offset length)81181254a7Smrg struncate (stream *s, gfc_offset length)
82181254a7Smrg {
83181254a7Smrg return s->vptr->trunc (s, length);
84181254a7Smrg }
85181254a7Smrg
86181254a7Smrg static inline int
sflush(stream * s)87181254a7Smrg sflush (stream *s)
88181254a7Smrg {
89181254a7Smrg return s->vptr->flush (s);
90181254a7Smrg }
91181254a7Smrg
92181254a7Smrg static inline int
sclose(stream * s)93181254a7Smrg sclose (stream *s)
94181254a7Smrg {
95181254a7Smrg return s->vptr->close (s);
96181254a7Smrg }
97181254a7Smrg
98181254a7Smrg static inline int
smarkeor(stream * s)99181254a7Smrg smarkeor (stream *s)
100181254a7Smrg {
101181254a7Smrg return s->vptr->markeor (s);
102181254a7Smrg }
103181254a7Smrg
104181254a7Smrg
105181254a7Smrg extern int compare_files (stream *, stream *);
106181254a7Smrg internal_proto(compare_files);
107181254a7Smrg
108181254a7Smrg extern stream *open_external (st_parameter_open *, unit_flags *);
109181254a7Smrg internal_proto(open_external);
110181254a7Smrg
111181254a7Smrg extern stream *open_internal (char *, size_t, gfc_offset);
112181254a7Smrg internal_proto(open_internal);
113181254a7Smrg
114181254a7Smrg extern stream *open_internal4 (char *, size_t, gfc_offset);
115181254a7Smrg internal_proto(open_internal4);
116181254a7Smrg
117181254a7Smrg extern char *mem_alloc_w (stream *, size_t *);
118181254a7Smrg internal_proto(mem_alloc_w);
119181254a7Smrg
120181254a7Smrg extern char *mem_alloc_r (stream *, size_t *);
121181254a7Smrg internal_proto(mem_alloc_r);
122181254a7Smrg
123181254a7Smrg extern gfc_char4_t *mem_alloc_w4 (stream *, size_t *);
124181254a7Smrg internal_proto(mem_alloc_w4);
125181254a7Smrg
126181254a7Smrg extern char *mem_alloc_r4 (stream *, size_t *);
127181254a7Smrg internal_proto(mem_alloc_r4);
128181254a7Smrg
129181254a7Smrg extern stream *input_stream (void);
130181254a7Smrg internal_proto(input_stream);
131181254a7Smrg
132181254a7Smrg extern stream *output_stream (void);
133181254a7Smrg internal_proto(output_stream);
134181254a7Smrg
135181254a7Smrg extern stream *error_stream (void);
136181254a7Smrg internal_proto(error_stream);
137181254a7Smrg
138181254a7Smrg extern int compare_file_filename (gfc_unit *, const char *, gfc_charlen_type);
139181254a7Smrg internal_proto(compare_file_filename);
140181254a7Smrg
141181254a7Smrg extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
142181254a7Smrg internal_proto(find_file);
143181254a7Smrg
144181254a7Smrg extern int close_share (gfc_unit *);
145181254a7Smrg internal_proto(close_share);
146181254a7Smrg
147181254a7Smrg extern int file_exists (const char *file, gfc_charlen_type file_len);
148181254a7Smrg internal_proto(file_exists);
149181254a7Smrg
150181254a7Smrg extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len);
151181254a7Smrg internal_proto(file_size);
152181254a7Smrg
153181254a7Smrg extern const char *inquire_sequential (const char *, gfc_charlen_type);
154181254a7Smrg internal_proto(inquire_sequential);
155181254a7Smrg
156181254a7Smrg extern const char *inquire_direct (const char *, gfc_charlen_type);
157181254a7Smrg internal_proto(inquire_direct);
158181254a7Smrg
159181254a7Smrg extern const char *inquire_formatted (const char *, gfc_charlen_type);
160181254a7Smrg internal_proto(inquire_formatted);
161181254a7Smrg
162181254a7Smrg extern const char *inquire_unformatted (const char *, gfc_charlen_type);
163181254a7Smrg internal_proto(inquire_unformatted);
164181254a7Smrg
165181254a7Smrg extern const char *inquire_read (const char *, gfc_charlen_type);
166181254a7Smrg internal_proto(inquire_read);
167181254a7Smrg
168181254a7Smrg extern const char *inquire_write (const char *, gfc_charlen_type);
169181254a7Smrg internal_proto(inquire_write);
170181254a7Smrg
171181254a7Smrg extern const char *inquire_readwrite (const char *, gfc_charlen_type);
172181254a7Smrg internal_proto(inquire_readwrite);
173181254a7Smrg
174181254a7Smrg extern void flush_if_preconnected (stream *);
175181254a7Smrg internal_proto(flush_if_preconnected);
176181254a7Smrg
177181254a7Smrg extern int stream_isatty (stream *);
178181254a7Smrg internal_proto(stream_isatty);
179181254a7Smrg
180181254a7Smrg #ifndef TTY_NAME_MAX
181181254a7Smrg #ifdef _POSIX_TTY_NAME_MAX
182181254a7Smrg #define TTY_NAME_MAX _POSIX_TTY_NAME_MAX
183181254a7Smrg #else
184181254a7Smrg /* sysconf(_SC_TTY_NAME_MAX) = 32 which should be enough. */
185181254a7Smrg #define TTY_NAME_MAX 32
186181254a7Smrg #endif
187181254a7Smrg #endif
188181254a7Smrg
189181254a7Smrg extern int stream_ttyname (stream *, char *, size_t);
190181254a7Smrg internal_proto(stream_ttyname);
191181254a7Smrg
192181254a7Smrg #endif
193