]>
Commit | Line | Data |
---|---|---|
a945c346 | 1 | /* Copyright (C) 2009-2024 Free Software Foundation, Inc. |
a2f560d0 JB |
2 | Contributed by Janne Blomqvist |
3 | ||
4 | This file is part of the GNU Fortran runtime library (libgfortran). | |
5 | ||
6 | Libgfortran is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 3, or (at your option) | |
9 | any later version. | |
10 | ||
11 | Libgfortran is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | Under Section 7 of GPL version 3, you are granted additional | |
17 | permissions described in the GCC Runtime Library Exception, version | |
18 | 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | You should have received a copy of the GNU General Public License and | |
21 | a copy of the GCC Runtime Library Exception along with this program; | |
22 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | <http://www.gnu.org/licenses/>. */ | |
24 | ||
a2f560d0 JB |
25 | #ifndef GFOR_UNIX_H |
26 | #define GFOR_UNIX_H | |
27 | ||
872d2094 JB |
28 | #include "io.h" |
29 | ||
33959d1d | 30 | struct stream_vtable |
a2f560d0 | 31 | { |
33959d1d JB |
32 | ssize_t (* const read) (struct stream *, void *, ssize_t); |
33 | ssize_t (* const write) (struct stream *, const void *, ssize_t); | |
34 | gfc_offset (* const seek) (struct stream *, gfc_offset, int); | |
35 | gfc_offset (* const tell) (struct stream *); | |
36 | gfc_offset (* const size) (struct stream *); | |
a2f560d0 | 37 | /* Avoid keyword truncate due to AIX namespace collision. */ |
33959d1d JB |
38 | int (* const trunc) (struct stream *, gfc_offset); |
39 | int (* const flush) (struct stream *); | |
40 | int (* const close) (struct stream *); | |
89a862b4 | 41 | int (* const markeor) (struct stream *); |
a2f560d0 JB |
42 | }; |
43 | ||
33959d1d JB |
44 | struct stream |
45 | { | |
46 | const struct stream_vtable *vptr; | |
47 | }; | |
01b99774 | 48 | |
a2f560d0 JB |
49 | /* Inline functions for doing file I/O given a stream. */ |
50 | static inline ssize_t | |
f29876bb | 51 | sread (stream *s, void *buf, ssize_t nbyte) |
a2f560d0 | 52 | { |
33959d1d | 53 | return s->vptr->read (s, buf, nbyte); |
a2f560d0 JB |
54 | } |
55 | ||
56 | static inline ssize_t | |
f29876bb | 57 | swrite (stream *s, const void *buf, ssize_t nbyte) |
a2f560d0 | 58 | { |
33959d1d | 59 | return s->vptr->write (s, buf, nbyte); |
a2f560d0 JB |
60 | } |
61 | ||
a4384bad | 62 | static inline gfc_offset |
f29876bb | 63 | sseek (stream *s, gfc_offset offset, int whence) |
a2f560d0 | 64 | { |
33959d1d | 65 | return s->vptr->seek (s, offset, whence); |
a2f560d0 JB |
66 | } |
67 | ||
a4384bad | 68 | static inline gfc_offset |
f29876bb | 69 | stell (stream *s) |
a2f560d0 | 70 | { |
33959d1d | 71 | return s->vptr->tell (s); |
a2f560d0 JB |
72 | } |
73 | ||
3469bd86 | 74 | static inline gfc_offset |
f29876bb | 75 | ssize (stream *s) |
3469bd86 | 76 | { |
33959d1d | 77 | return s->vptr->size (s); |
3469bd86 JB |
78 | } |
79 | ||
a2f560d0 | 80 | static inline int |
f29876bb | 81 | struncate (stream *s, gfc_offset length) |
a2f560d0 | 82 | { |
33959d1d | 83 | return s->vptr->trunc (s, length); |
a2f560d0 JB |
84 | } |
85 | ||
86 | static inline int | |
f29876bb | 87 | sflush (stream *s) |
a2f560d0 | 88 | { |
33959d1d | 89 | return s->vptr->flush (s); |
a2f560d0 JB |
90 | } |
91 | ||
92 | static inline int | |
f29876bb | 93 | sclose (stream *s) |
a2f560d0 | 94 | { |
33959d1d | 95 | return s->vptr->close (s); |
a2f560d0 JB |
96 | } |
97 | ||
89a862b4 | 98 | static inline int |
f29876bb | 99 | smarkeor (stream *s) |
89a862b4 JB |
100 | { |
101 | return s->vptr->markeor (s); | |
102 | } | |
103 | ||
a2f560d0 JB |
104 | |
105 | extern int compare_files (stream *, stream *); | |
106 | internal_proto(compare_files); | |
107 | ||
108 | extern stream *open_external (st_parameter_open *, unit_flags *); | |
109 | internal_proto(open_external); | |
110 | ||
ea99ec5b | 111 | extern stream *open_internal (char *, size_t, gfc_offset); |
a2f560d0 JB |
112 | internal_proto(open_internal); |
113 | ||
ea99ec5b | 114 | extern stream *open_internal4 (char *, size_t, gfc_offset); |
c7421e06 JD |
115 | internal_proto(open_internal4); |
116 | ||
ea99ec5b | 117 | extern char *mem_alloc_w (stream *, size_t *); |
a2f560d0 JB |
118 | internal_proto(mem_alloc_w); |
119 | ||
ea99ec5b | 120 | extern char *mem_alloc_r (stream *, size_t *); |
68cb9e8a | 121 | internal_proto(mem_alloc_r); |
a2f560d0 | 122 | |
ea99ec5b | 123 | extern gfc_char4_t *mem_alloc_w4 (stream *, size_t *); |
c7421e06 JD |
124 | internal_proto(mem_alloc_w4); |
125 | ||
ea99ec5b | 126 | extern char *mem_alloc_r4 (stream *, size_t *); |
c7421e06 JD |
127 | internal_proto(mem_alloc_r4); |
128 | ||
a2f560d0 JB |
129 | extern stream *input_stream (void); |
130 | internal_proto(input_stream); | |
131 | ||
132 | extern stream *output_stream (void); | |
133 | internal_proto(output_stream); | |
134 | ||
135 | extern stream *error_stream (void); | |
136 | internal_proto(error_stream); | |
137 | ||
c0ab1530 | 138 | extern int compare_file_filename (gfc_unit *, const char *, gfc_charlen_type); |
a2f560d0 JB |
139 | internal_proto(compare_file_filename); |
140 | ||
141 | extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len); | |
142 | internal_proto(find_file); | |
143 | ||
0ef33d44 FR |
144 | extern int close_share (gfc_unit *); |
145 | internal_proto(close_share); | |
146 | ||
a2f560d0 JB |
147 | extern int file_exists (const char *file, gfc_charlen_type file_len); |
148 | internal_proto(file_exists); | |
149 | ||
41c3cddc JD |
150 | extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len); |
151 | internal_proto(file_size); | |
152 | ||
c0ab1530 | 153 | extern const char *inquire_sequential (const char *, gfc_charlen_type); |
a2f560d0 JB |
154 | internal_proto(inquire_sequential); |
155 | ||
c0ab1530 | 156 | extern const char *inquire_direct (const char *, gfc_charlen_type); |
a2f560d0 JB |
157 | internal_proto(inquire_direct); |
158 | ||
c0ab1530 | 159 | extern const char *inquire_formatted (const char *, gfc_charlen_type); |
a2f560d0 JB |
160 | internal_proto(inquire_formatted); |
161 | ||
c0ab1530 | 162 | extern const char *inquire_unformatted (const char *, gfc_charlen_type); |
a2f560d0 JB |
163 | internal_proto(inquire_unformatted); |
164 | ||
c0ab1530 | 165 | extern const char *inquire_read (const char *, gfc_charlen_type); |
a2f560d0 JB |
166 | internal_proto(inquire_read); |
167 | ||
c0ab1530 | 168 | extern const char *inquire_write (const char *, gfc_charlen_type); |
a2f560d0 JB |
169 | internal_proto(inquire_write); |
170 | ||
c0ab1530 | 171 | extern const char *inquire_readwrite (const char *, gfc_charlen_type); |
a2f560d0 JB |
172 | internal_proto(inquire_readwrite); |
173 | ||
a2f560d0 JB |
174 | extern void flush_if_preconnected (stream *); |
175 | internal_proto(flush_if_preconnected); | |
176 | ||
a2f560d0 JB |
177 | extern int stream_isatty (stream *); |
178 | internal_proto(stream_isatty); | |
179 | ||
6a0f6e77 JB |
180 | #ifndef TTY_NAME_MAX |
181 | #ifdef _POSIX_TTY_NAME_MAX | |
182 | #define TTY_NAME_MAX _POSIX_TTY_NAME_MAX | |
183 | #else | |
184 | /* sysconf(_SC_TTY_NAME_MAX) = 32 which should be enough. */ | |
185 | #define TTY_NAME_MAX 32 | |
186 | #endif | |
187 | #endif | |
188 | ||
189 | extern int stream_ttyname (stream *, char *, size_t); | |
a2f560d0 JB |
190 | internal_proto(stream_ttyname); |
191 | ||
a2f560d0 | 192 | #endif |