PR lto/42531
[official-gcc.git] / libgfortran / io / unix.h
blobe691982e505d96778757f60568c3ce2e3bd40dd3
1 /* Copyright (C) 2009
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)
10 any later version.
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/>. */
26 #ifndef GFOR_UNIX_H
27 #define GFOR_UNIX_H
29 #include "io.h"
32 struct stream
34 ssize_t (*read) (struct stream *, void *, ssize_t);
35 ssize_t (*write) (struct stream *, const void *, ssize_t);
36 gfc_offset (*seek) (struct stream *, gfc_offset, int);
37 gfc_offset (*tell) (struct stream *);
38 /* Avoid keyword truncate due to AIX namespace collision. */
39 int (*trunc) (struct stream *, gfc_offset);
40 int (*flush) (struct stream *);
41 int (*close) (struct stream *);
44 /* Inline functions for doing file I/O given a stream. */
45 static inline ssize_t
46 sread (stream * s, void * buf, ssize_t nbyte)
48 return s->read (s, buf, nbyte);
51 static inline ssize_t
52 swrite (stream * s, const void * buf, ssize_t nbyte)
54 return s->write (s, buf, nbyte);
57 static inline gfc_offset
58 sseek (stream * s, gfc_offset offset, int whence)
60 return s->seek (s, offset, whence);
63 static inline gfc_offset
64 stell (stream * s)
66 return s->tell (s);
69 static inline int
70 struncate (stream * s, gfc_offset length)
72 return s->trunc (s, length);
75 static inline int
76 sflush (stream * s)
78 return s->flush (s);
81 static inline int
82 sclose (stream * s)
84 return s->close (s);
88 extern int compare_files (stream *, stream *);
89 internal_proto(compare_files);
91 extern stream *open_external (st_parameter_open *, unit_flags *);
92 internal_proto(open_external);
94 extern stream *open_internal (char *, int, gfc_offset);
95 internal_proto(open_internal);
97 extern char * mem_alloc_w (stream *, int *);
98 internal_proto(mem_alloc_w);
100 extern char * mem_alloc_r (stream *, int *);
101 internal_proto(mem_alloc_w);
103 extern stream *input_stream (void);
104 internal_proto(input_stream);
106 extern stream *output_stream (void);
107 internal_proto(output_stream);
109 extern stream *error_stream (void);
110 internal_proto(error_stream);
112 extern int compare_file_filename (gfc_unit *, const char *, int);
113 internal_proto(compare_file_filename);
115 extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
116 internal_proto(find_file);
118 extern int delete_file (gfc_unit *);
119 internal_proto(delete_file);
121 extern int file_exists (const char *file, gfc_charlen_type file_len);
122 internal_proto(file_exists);
124 extern const char *inquire_sequential (const char *, int);
125 internal_proto(inquire_sequential);
127 extern const char *inquire_direct (const char *, int);
128 internal_proto(inquire_direct);
130 extern const char *inquire_formatted (const char *, int);
131 internal_proto(inquire_formatted);
133 extern const char *inquire_unformatted (const char *, int);
134 internal_proto(inquire_unformatted);
136 extern const char *inquire_read (const char *, int);
137 internal_proto(inquire_read);
139 extern const char *inquire_write (const char *, int);
140 internal_proto(inquire_write);
142 extern const char *inquire_readwrite (const char *, int);
143 internal_proto(inquire_readwrite);
145 extern gfc_offset file_length (stream *);
146 internal_proto(file_length);
148 extern int is_seekable (stream *);
149 internal_proto(is_seekable);
151 extern int is_special (stream *);
152 internal_proto(is_special);
154 extern void flush_if_preconnected (stream *);
155 internal_proto(flush_if_preconnected);
157 extern void empty_internal_buffer(stream *);
158 internal_proto(empty_internal_buffer);
160 extern int stream_isatty (stream *);
161 internal_proto(stream_isatty);
163 extern char * stream_ttyname (stream *);
164 internal_proto(stream_ttyname);
166 extern int unpack_filename (char *, const char *, int);
167 internal_proto(unpack_filename);
170 #endif