Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgfortran / io / unix.h
1 /* Copyright (C) 2009-2013 Free Software Foundation, Inc.
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
25 #ifndef GFOR_UNIX_H
26 #define GFOR_UNIX_H
27
28 #include "io.h"
29
30 struct stream_vtable
31 {
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 *);
41 };
42
43 struct stream
44 {
45   const struct stream_vtable *vptr;
46 };
47
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)
51 {
52   return s->vptr->read (s, buf, nbyte);
53 }
54
55 static inline ssize_t
56 swrite (stream * s, const void * buf, ssize_t nbyte)
57 {
58   return s->vptr->write (s, buf, nbyte);
59 }
60
61 static inline gfc_offset
62 sseek (stream * s, gfc_offset offset, int whence)
63 {
64   return s->vptr->seek (s, offset, whence);
65 }
66
67 static inline gfc_offset
68 stell (stream * s)
69 {
70   return s->vptr->tell (s);
71 }
72
73 static inline gfc_offset
74 ssize (stream * s)
75 {
76   return s->vptr->size (s);
77 }
78
79 static inline int
80 struncate (stream * s, gfc_offset length)
81 {
82   return s->vptr->trunc (s, length);
83 }
84
85 static inline int
86 sflush (stream * s)
87 {
88   return s->vptr->flush (s);
89 }
90
91 static inline int
92 sclose (stream * s)
93 {
94   return s->vptr->close (s);
95 }
96
97
98 extern int compare_files (stream *, stream *);
99 internal_proto(compare_files);
100
101 extern stream *open_external (st_parameter_open *, unit_flags *);
102 internal_proto(open_external);
103
104 extern stream *open_internal (char *, int, gfc_offset);
105 internal_proto(open_internal);
106
107 extern stream *open_internal4 (char *, int, gfc_offset);
108 internal_proto(open_internal4);
109
110 extern char * mem_alloc_w (stream *, int *);
111 internal_proto(mem_alloc_w);
112
113 extern char * mem_alloc_r (stream *, int *);
114 internal_proto(mem_alloc_r);
115
116 extern gfc_char4_t * mem_alloc_w4 (stream *, int *);
117 internal_proto(mem_alloc_w4);
118
119 extern char * mem_alloc_r4 (stream *, int *);
120 internal_proto(mem_alloc_r4);
121
122 extern stream *input_stream (void);
123 internal_proto(input_stream);
124
125 extern stream *output_stream (void);
126 internal_proto(output_stream);
127
128 extern stream *error_stream (void);
129 internal_proto(error_stream);
130
131 extern int compare_file_filename (gfc_unit *, const char *, int);
132 internal_proto(compare_file_filename);
133
134 extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
135 internal_proto(find_file);
136
137 extern int delete_file (gfc_unit *);
138 internal_proto(delete_file);
139
140 extern int file_exists (const char *file, gfc_charlen_type file_len);
141 internal_proto(file_exists);
142
143 extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len);
144 internal_proto(file_size);
145
146 extern const char *inquire_sequential (const char *, int);
147 internal_proto(inquire_sequential);
148
149 extern const char *inquire_direct (const char *, int);
150 internal_proto(inquire_direct);
151
152 extern const char *inquire_formatted (const char *, int);
153 internal_proto(inquire_formatted);
154
155 extern const char *inquire_unformatted (const char *, int);
156 internal_proto(inquire_unformatted);
157
158 extern const char *inquire_read (const char *, int);
159 internal_proto(inquire_read);
160
161 extern const char *inquire_write (const char *, int);
162 internal_proto(inquire_write);
163
164 extern const char *inquire_readwrite (const char *, int);
165 internal_proto(inquire_readwrite);
166
167 extern void flush_if_preconnected (stream *);
168 internal_proto(flush_if_preconnected);
169
170 extern int stream_isatty (stream *);
171 internal_proto(stream_isatty);
172
173 #ifndef TTY_NAME_MAX
174 #ifdef _POSIX_TTY_NAME_MAX
175 #define TTY_NAME_MAX _POSIX_TTY_NAME_MAX
176 #else
177 /* sysconf(_SC_TTY_NAME_MAX) = 32 which should be enough.  */
178 #define TTY_NAME_MAX 32
179 #endif
180 #endif
181
182 extern int stream_ttyname (stream *, char *, size_t);
183 internal_proto(stream_ttyname);
184
185 extern int unpack_filename (char *, const char *, int);
186 internal_proto(unpack_filename);
187
188
189 #endif