OSDN Git Service

2010-10-20 Nicola Pero <nicola.pero@meta-innovation.com>
[pf3gnuchains/gcc-fork.git] / libgfortran / io / unix.h
1 /* Copyright (C) 2009, 2010
2    Free Software Foundation, Inc.
3    Contributed by Janne Blomqvist
4
5 This file is part of the GNU Fortran runtime library (libgfortran).
6
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.
11
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.
16
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.
20
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/>.  */
25
26 #ifndef GFOR_UNIX_H
27 #define GFOR_UNIX_H
28
29 #include "io.h"
30
31
32 struct stream
33 {
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 *);
42 };
43
44
45 typedef struct
46 {
47   stream st;
48
49   gfc_offset buffer_offset;     /* File offset of the start of the buffer */
50   gfc_offset physical_offset;   /* Current physical file offset */
51   gfc_offset logical_offset;    /* Current logical file offset */
52   gfc_offset file_length;       /* Length of the file, -1 if not seekable. */
53
54   char *buffer;                 /* Pointer to the buffer.  */
55   int fd;                       /* The POSIX file descriptor.  */
56
57   int active;                   /* Length of valid bytes in the buffer */
58
59   int prot;
60   int ndirty;                   /* Dirty bytes starting at buffer_offset */
61
62   int special_file;             /* =1 if the fd refers to a special file */
63 }
64 unix_stream;
65
66
67 /* Inline functions for doing file I/O given a stream.  */
68 static inline ssize_t
69 sread (stream * s, void * buf, ssize_t nbyte)
70 {
71   return s->read (s, buf, nbyte);
72 }
73
74 static inline ssize_t
75 swrite (stream * s, const void * buf, ssize_t nbyte)
76 {
77   return s->write (s, buf, nbyte);
78 }
79
80 static inline gfc_offset
81 sseek (stream * s, gfc_offset offset, int whence)
82 {
83   return s->seek (s, offset, whence);
84 }
85
86 static inline gfc_offset
87 stell (stream * s)
88 {
89   return s->tell (s);
90 }
91
92 static inline int
93 struncate (stream * s, gfc_offset length)
94 {
95   return s->trunc (s, length);
96 }
97
98 static inline int
99 sflush (stream * s)
100 {
101   return s->flush (s);
102 }
103
104 static inline int
105 sclose (stream * s)
106 {
107   return s->close (s);
108 }
109
110
111 extern int compare_files (stream *, stream *);
112 internal_proto(compare_files);
113
114 extern stream *open_external (st_parameter_open *, unit_flags *);
115 internal_proto(open_external);
116
117 extern stream *open_internal (char *, int, gfc_offset);
118 internal_proto(open_internal);
119
120 extern stream *open_internal4 (char *, int, gfc_offset);
121 internal_proto(open_internal4);
122
123 extern char * mem_alloc_w (stream *, int *);
124 internal_proto(mem_alloc_w);
125
126 extern char * mem_alloc_r (stream *, int *);
127 internal_proto(mem_alloc_r);
128
129 extern gfc_char4_t * mem_alloc_w4 (stream *, int *);
130 internal_proto(mem_alloc_w4);
131
132 extern char * mem_alloc_r4 (stream *, int *);
133 internal_proto(mem_alloc_r4);
134
135 extern stream *input_stream (void);
136 internal_proto(input_stream);
137
138 extern stream *output_stream (void);
139 internal_proto(output_stream);
140
141 extern stream *error_stream (void);
142 internal_proto(error_stream);
143
144 extern int compare_file_filename (gfc_unit *, const char *, int);
145 internal_proto(compare_file_filename);
146
147 extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
148 internal_proto(find_file);
149
150 extern int delete_file (gfc_unit *);
151 internal_proto(delete_file);
152
153 extern int file_exists (const char *file, gfc_charlen_type file_len);
154 internal_proto(file_exists);
155
156 extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len);
157 internal_proto(file_size);
158
159 extern const char *inquire_sequential (const char *, int);
160 internal_proto(inquire_sequential);
161
162 extern const char *inquire_direct (const char *, int);
163 internal_proto(inquire_direct);
164
165 extern const char *inquire_formatted (const char *, int);
166 internal_proto(inquire_formatted);
167
168 extern const char *inquire_unformatted (const char *, int);
169 internal_proto(inquire_unformatted);
170
171 extern const char *inquire_read (const char *, int);
172 internal_proto(inquire_read);
173
174 extern const char *inquire_write (const char *, int);
175 internal_proto(inquire_write);
176
177 extern const char *inquire_readwrite (const char *, int);
178 internal_proto(inquire_readwrite);
179
180 extern gfc_offset file_length (stream *);
181 internal_proto(file_length);
182
183 extern int is_seekable (stream *);
184 internal_proto(is_seekable);
185
186 extern int is_special (stream *);
187 internal_proto(is_special);
188
189 extern void flush_if_preconnected (stream *);
190 internal_proto(flush_if_preconnected);
191
192 extern void empty_internal_buffer(stream *);
193 internal_proto(empty_internal_buffer);
194
195 extern int stream_isatty (stream *);
196 internal_proto(stream_isatty);
197
198 extern char * stream_ttyname (stream *);
199 internal_proto(stream_ttyname);
200
201 extern int unpack_filename (char *, const char *, int);
202 internal_proto(unpack_filename);
203
204
205 #endif