Reverting merge from trunk
[official-gcc.git] / libgfortran / io / unix.h
blobcc82d45739777b21ec75393894c7691f198dc4e9
1 /* Copyright (C) 2009-2013 Free Software Foundation, Inc.
2 Contributed by Janne Blomqvist
4 This file is part of the GNU Fortran runtime library (libgfortran).
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.
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.
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.
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/>. */
25 #ifndef GFOR_UNIX_H
26 #define GFOR_UNIX_H
28 #include "io.h"
30 struct stream_vtable
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 *);
37 /* Avoid keyword truncate due to AIX namespace collision. */
38 int (* const trunc) (struct stream *, gfc_offset);
39 int (* const flush) (struct stream *);
40 int (* const close) (struct stream *);
43 struct stream
45 const struct stream_vtable *vptr;
48 /* Inline functions for doing file I/O given a stream. */
49 static inline ssize_t
50 sread (stream * s, void * buf, ssize_t nbyte)
52 return s->vptr->read (s, buf, nbyte);
55 static inline ssize_t
56 swrite (stream * s, const void * buf, ssize_t nbyte)
58 return s->vptr->write (s, buf, nbyte);
61 static inline gfc_offset
62 sseek (stream * s, gfc_offset offset, int whence)
64 return s->vptr->seek (s, offset, whence);
67 static inline gfc_offset
68 stell (stream * s)
70 return s->vptr->tell (s);
73 static inline gfc_offset
74 ssize (stream * s)
76 return s->vptr->size (s);
79 static inline int
80 struncate (stream * s, gfc_offset length)
82 return s->vptr->trunc (s, length);
85 static inline int
86 sflush (stream * s)
88 return s->vptr->flush (s);
91 static inline int
92 sclose (stream * s)
94 return s->vptr->close (s);
98 extern int compare_files (stream *, stream *);
99 internal_proto(compare_files);
101 extern stream *open_external (st_parameter_open *, unit_flags *);
102 internal_proto(open_external);
104 extern stream *open_internal (char *, int, gfc_offset);
105 internal_proto(open_internal);
107 extern stream *open_internal4 (char *, int, gfc_offset);
108 internal_proto(open_internal4);
110 extern char * mem_alloc_w (stream *, int *);
111 internal_proto(mem_alloc_w);
113 extern char * mem_alloc_r (stream *, int *);
114 internal_proto(mem_alloc_r);
116 extern gfc_char4_t * mem_alloc_w4 (stream *, int *);
117 internal_proto(mem_alloc_w4);
119 extern char * mem_alloc_r4 (stream *, int *);
120 internal_proto(mem_alloc_r4);
122 extern stream *input_stream (void);
123 internal_proto(input_stream);
125 extern stream *output_stream (void);
126 internal_proto(output_stream);
128 extern stream *error_stream (void);
129 internal_proto(error_stream);
131 extern int compare_file_filename (gfc_unit *, const char *, int);
132 internal_proto(compare_file_filename);
134 extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
135 internal_proto(find_file);
137 extern int delete_file (gfc_unit *);
138 internal_proto(delete_file);
140 extern int file_exists (const char *file, gfc_charlen_type file_len);
141 internal_proto(file_exists);
143 extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len);
144 internal_proto(file_size);
146 extern const char *inquire_sequential (const char *, int);
147 internal_proto(inquire_sequential);
149 extern const char *inquire_direct (const char *, int);
150 internal_proto(inquire_direct);
152 extern const char *inquire_formatted (const char *, int);
153 internal_proto(inquire_formatted);
155 extern const char *inquire_unformatted (const char *, int);
156 internal_proto(inquire_unformatted);
158 extern const char *inquire_read (const char *, int);
159 internal_proto(inquire_read);
161 extern const char *inquire_write (const char *, int);
162 internal_proto(inquire_write);
164 extern const char *inquire_readwrite (const char *, int);
165 internal_proto(inquire_readwrite);
167 extern void flush_if_preconnected (stream *);
168 internal_proto(flush_if_preconnected);
170 extern int flush_if_unbuffered (stream*);
171 internal_proto(flush_if_unbuffered);
173 extern int stream_isatty (stream *);
174 internal_proto(stream_isatty);
176 #ifndef TTY_NAME_MAX
177 #ifdef _POSIX_TTY_NAME_MAX
178 #define TTY_NAME_MAX _POSIX_TTY_NAME_MAX
179 #else
180 /* sysconf(_SC_TTY_NAME_MAX) = 32 which should be enough. */
181 #define TTY_NAME_MAX 32
182 #endif
183 #endif
185 extern int stream_ttyname (stream *, char *, size_t);
186 internal_proto(stream_ttyname);
188 extern int unpack_filename (char *, const char *, int);
189 internal_proto(unpack_filename);
192 #endif