| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 38 |
int (* const trunc) (struct stream *, gfc_offset); |
| 39 |
int (* const flush) (struct stream *); |
| 40 |
int (* const close) (struct stream *); |
| 41 |
int (* const markeor) (struct stream *); |
| 42 |
}; |
| 43 |
|
| 44 |
struct stream |
| 45 |
{ |
| 46 |
const struct stream_vtable *vptr; |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
static inline ssize_t |
| 51 |
sread (stream *s, void *buf, ssize_t nbyte) |
| 52 |
{ |
| 53 |
return s->vptr->read (s, buf, nbyte); |
| 54 |
} |
| 55 |
|
| 56 |
static inline ssize_t |
| 57 |
swrite (stream *s, const void *buf, ssize_t nbyte) |
| 58 |
{ |
| 59 |
return s->vptr->write (s, buf, nbyte); |
| 60 |
} |
| 61 |
|
| 62 |
static inline gfc_offset |
| 63 |
sseek (stream *s, gfc_offset offset, int whence) |
| 64 |
{ |
| 65 |
return s->vptr->seek (s, offset, whence); |
| 66 |
} |
| 67 |
|
| 68 |
static inline gfc_offset |
| 69 |
stell (stream *s) |
| 70 |
{ |
| 71 |
return s->vptr->tell (s); |
| 72 |
} |
| 73 |
|
| 74 |
static inline gfc_offset |
| 75 |
ssize (stream *s) |
| 76 |
{ |
| 77 |
return s->vptr->size (s); |
| 78 |
} |
| 79 |
|
| 80 |
static inline int |
| 81 |
struncate (stream *s, gfc_offset length) |
| 82 |
{ |
| 83 |
return s->vptr->trunc (s, length); |
| 84 |
} |
| 85 |
|
| 86 |
static inline int |
| 87 |
sflush (stream *s) |
| 88 |
{ |
| 89 |
return s->vptr->flush (s); |
| 90 |
} |
| 91 |
|
| 92 |
static inline int |
| 93 |
sclose (stream *s) |
| 94 |
{ |
| 95 |
return s->vptr->close (s); |
| 96 |
} |
| 97 |
|
| 98 |
static inline int |
| 99 |
smarkeor (stream *s) |
| 100 |
{ |
| 101 |
return s->vptr->markeor (s); |
| 102 |
} |
| 103 |
|
| 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 |
|
| 111 |
extern stream *open_internal (char *, size_t, gfc_offset); |
| 112 |
internal_proto(open_internal); |
| 113 |
|
| 114 |
extern stream *open_internal4 (char *, size_t, gfc_offset); |
| 115 |
internal_proto(open_internal4); |
| 116 |
|
| 117 |
extern char *mem_alloc_w (stream *, size_t *); |
| 118 |
internal_proto(mem_alloc_w); |
| 119 |
|
| 120 |
extern char *mem_alloc_r (stream *, size_t *); |
| 121 |
internal_proto(mem_alloc_r); |
| 122 |
|
| 123 |
extern gfc_char4_t *mem_alloc_w4 (stream *, size_t *); |
| 124 |
internal_proto(mem_alloc_w4); |
| 125 |
|
| 126 |
extern char *mem_alloc_r4 (stream *, size_t *); |
| 127 |
internal_proto(mem_alloc_r4); |
| 128 |
|
| 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 |
|
| 138 |
extern int compare_file_filename (gfc_unit *, const char *, gfc_charlen_type); |
| 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 |
|
| 144 |
extern int close_share (gfc_unit *); |
| 145 |
internal_proto(close_share); |
| 146 |
|
| 147 |
extern int file_exists (const char *file, gfc_charlen_type file_len); |
| 148 |
internal_proto(file_exists); |
| 149 |
|
| 150 |
extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len); |
| 151 |
internal_proto(file_size); |
| 152 |
|
| 153 |
extern const char *inquire_sequential (const char *, gfc_charlen_type); |
| 154 |
internal_proto(inquire_sequential); |
| 155 |
|
| 156 |
extern const char *inquire_direct (const char *, gfc_charlen_type); |
| 157 |
internal_proto(inquire_direct); |
| 158 |
|
| 159 |
extern const char *inquire_formatted (const char *, gfc_charlen_type); |
| 160 |
internal_proto(inquire_formatted); |
| 161 |
|
| 162 |
extern const char *inquire_unformatted (const char *, gfc_charlen_type); |
| 163 |
internal_proto(inquire_unformatted); |
| 164 |
|
| 165 |
extern const char *inquire_read (const char *, gfc_charlen_type); |
| 166 |
internal_proto(inquire_read); |
| 167 |
|
| 168 |
extern const char *inquire_write (const char *, gfc_charlen_type); |
| 169 |
internal_proto(inquire_write); |
| 170 |
|
| 171 |
extern const char *inquire_readwrite (const char *, gfc_charlen_type); |
| 172 |
internal_proto(inquire_readwrite); |
| 173 |
|
| 174 |
extern void flush_if_preconnected (stream *); |
| 175 |
internal_proto(flush_if_preconnected); |
| 176 |
|
| 177 |
extern int stream_isatty (stream *); |
| 178 |
internal_proto(stream_isatty); |
| 179 |
|
| 180 |
#ifndef TTY_NAME_MAX |
| 181 |
#ifdef _POSIX_TTY_NAME_MAX |
| 182 |
#define TTY_NAME_MAX _POSIX_TTY_NAME_MAX |
| 183 |
#else |
| 184 |
|
| 185 |
#define TTY_NAME_MAX 32 |
| 186 |
#endif |
| 187 |
#endif |
| 188 |
|
| 189 |
extern int stream_ttyname (stream *, char *, size_t); |
| 190 |
internal_proto(stream_ttyname); |
| 191 |
|
| 192 |
#endif |