]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/io/io.h
Fix a typo in gcc.dg/pg-override.c
[thirdparty/gcc.git] / libgfortran / io / io.h
CommitLineData
f0bcf628 1/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
6de9cd9a 2 Contributed by Andy Vaught
10256cbe 3 F2003 I/O support contributed by Jerry DeLisle
6de9cd9a 4
eea58adb 5This file is part of the GNU Fortran runtime library (libgfortran).
6de9cd9a
DN
6
7Libgfortran is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
748086b7 9the Free Software Foundation; either version 3, or (at your option)
6de9cd9a
DN
10any later version.
11
12Libgfortran is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
57dea9f6 25
6de9cd9a
DN
26#ifndef GFOR_IO_H
27#define GFOR_IO_H
28
29/* IO library include. */
30
6de9cd9a 31#include "libgfortran.h"
73e5b024 32
5e805e44 33#include <gthr.h>
7d7b8bfe 34
92cbdb68 35/* Forward declarations. */
5e805e44 36struct st_parameter_dt;
92cbdb68
JB
37typedef struct stream stream;
38struct fbuf;
39struct format_data;
40typedef struct fnode fnode;
41struct gfc_unit;
6de9cd9a 42
82b8244c 43
d10fb73e
JD
44/* Macros for testing what kinds of I/O we are doing. */
45
46#define is_array_io(dtp) ((dtp)->internal_unit_desc)
47
48#define is_internal_unit(dtp) ((dtp)->u.p.unit_is_internal)
49
50#define is_stream_io(dtp) ((dtp)->u.p.current_unit->flags.access == ACCESS_STREAM)
51
c7421e06
JD
52#define is_char4_unit(dtp) ((dtp)->u.p.unit_is_internal && (dtp)->common.unit)
53
965eec16 54/* The array_loop_spec contains the variables for the loops over index ranges
44720bef 55 that are encountered. */
29dc5138 56
965eec16 57typedef struct array_loop_spec
29dc5138 58{
29dc5138 59 /* Index counter for this dimension. */
44720bef 60 index_type idx;
6de9cd9a 61
29dc5138 62 /* Start for the index counter. */
44720bef 63 index_type start;
29dc5138
PT
64
65 /* End for the index counter. */
44720bef 66 index_type end;
29dc5138
PT
67
68 /* Step for the index counter. */
44720bef 69 index_type step;
29dc5138 70}
965eec16
JD
71array_loop_spec;
72
eea58adb 73/* A structure to build a hash table for format data. */
7812c78c 74
92cbdb68 75#define FORMAT_HASH_SIZE 16
7812c78c
JD
76
77typedef struct format_hash_entry
78{
79 char *key;
80 gfc_charlen_type key_len;
81 struct format_data *hashed_fmt;
82}
83format_hash_entry;
84
965eec16 85/* Representation of a namelist object in libgfortran
29dc5138 86
965eec16
JD
87 Namelist Records
88 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]].../
89 or
90 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]]...&END
91
8b6dba81 92 The object can be a fully qualified, compound name for an intrinsic
965eec16
JD
93 type, derived types or derived type components. So, a substring
94 a(:)%b(4)%ch(2:4)(1:7) has to be treated correctly in namelist
95 read. Hence full information about the structure of the object has
96 to be available to list_read.c and write.
97
98 These requirements are met by the following data structures.
99
100 namelist_info type contains all the scalar information about the
101 object and arrays of descriptor_dimension and array_loop_spec types for
29dc5138 102 arrays. */
6de9cd9a
DN
103
104typedef struct namelist_type
105{
a11930ba
JD
106 /* Object type. */
107 bt type;
29dc5138
PT
108
109 /* Object name. */
6de9cd9a 110 char * var_name;
29dc5138
PT
111
112 /* Address for the start of the object's data. */
6de9cd9a 113 void * mem_pos;
29dc5138
PT
114
115 /* Flag to show that a read is to be attempted for this node. */
116 int touched;
117
118 /* Length of intrinsic type in bytes. */
6de9cd9a 119 int len;
29dc5138
PT
120
121 /* Rank of the object. */
122 int var_rank;
123
124 /* Overall size of the object in bytes. */
125 index_type size;
126
127 /* Length of character string. */
128 index_type string_length;
129
130 descriptor_dimension * dim;
965eec16 131 array_loop_spec * ls;
6de9cd9a
DN
132 struct namelist_type * next;
133}
134namelist_info;
135
136/* Options for the OPEN statement. */
137
138typedef enum
91b30ee5 139{ ACCESS_SEQUENTIAL, ACCESS_DIRECT, ACCESS_APPEND, ACCESS_STREAM,
6de9cd9a
DN
140 ACCESS_UNSPECIFIED
141}
142unit_access;
143
144typedef enum
145{ ACTION_READ, ACTION_WRITE, ACTION_READWRITE,
146 ACTION_UNSPECIFIED
147}
148unit_action;
149
150typedef enum
151{ BLANK_NULL, BLANK_ZERO, BLANK_UNSPECIFIED }
152unit_blank;
153
154typedef enum
155{ DELIM_NONE, DELIM_APOSTROPHE, DELIM_QUOTE,
156 DELIM_UNSPECIFIED
157}
158unit_delim;
159
160typedef enum
161{ FORM_FORMATTED, FORM_UNFORMATTED, FORM_UNSPECIFIED }
162unit_form;
163
164typedef enum
165{ POSITION_ASIS, POSITION_REWIND, POSITION_APPEND,
166 POSITION_UNSPECIFIED
167}
168unit_position;
169
170typedef enum
171{ STATUS_UNKNOWN, STATUS_OLD, STATUS_NEW, STATUS_SCRATCH,
172 STATUS_REPLACE, STATUS_UNSPECIFIED
173}
174unit_status;
175
176typedef enum
177{ PAD_YES, PAD_NO, PAD_UNSPECIFIED }
178unit_pad;
179
10256cbe
JD
180typedef enum
181{ DECIMAL_POINT, DECIMAL_COMMA, DECIMAL_UNSPECIFIED }
182unit_decimal;
183
184typedef enum
185{ ENCODING_UTF8, ENCODING_DEFAULT, ENCODING_UNSPECIFIED }
186unit_encoding;
187
188typedef enum
82a4f54c
TB
189{ ROUND_UP = GFC_FPE_UPWARD,
190 ROUND_DOWN = GFC_FPE_DOWNWARD,
191 ROUND_ZERO = GFC_FPE_TOWARDZERO,
192 ROUND_NEAREST = GFC_FPE_TONEAREST,
193 ROUND_COMPATIBLE = 10, /* round away from zero. */
194 ROUND_PROCDEFINED, /* Here as ROUND_NEAREST. */
195 ROUND_UNSPECIFIED /* Should never occur. */
196}
10256cbe
JD
197unit_round;
198
199/* NOTE: unit_sign must correspond with the sign_status enumerator in
200 st_parameter_dt to not break the ABI. */
201typedef enum
202{ SIGN_PROCDEFINED, SIGN_SUPPRESS, SIGN_PLUS, SIGN_UNSPECIFIED }
203unit_sign;
204
6de9cd9a
DN
205typedef enum
206{ ADVANCE_YES, ADVANCE_NO, ADVANCE_UNSPECIFIED }
207unit_advance;
208
55948b69
BD
209typedef enum
210{READING, WRITING}
211unit_mode;
6de9cd9a 212
10256cbe 213typedef enum
931149a6 214{ ASYNC_YES, ASYNC_NO, ASYNC_UNSPECIFIED }
10256cbe
JD
215unit_async;
216
d7445152
JD
217typedef enum
218{ SIGN_S, SIGN_SS, SIGN_SP }
219unit_sign_s;
220
5e805e44
JJ
221#define CHARACTER1(name) \
222 char * name; \
223 gfc_charlen_type name ## _len
224#define CHARACTER2(name) \
225 gfc_charlen_type name ## _len; \
226 char * name
227
6de9cd9a
DN
228typedef struct
229{
5e805e44
JJ
230 st_parameter_common common;
231 GFC_INTEGER_4 recl_in;
232 CHARACTER2 (file);
233 CHARACTER1 (status);
234 CHARACTER2 (access);
235 CHARACTER1 (form);
236 CHARACTER2 (blank);
237 CHARACTER1 (position);
238 CHARACTER2 (action);
239 CHARACTER1 (delim);
240 CHARACTER2 (pad);
181c9f4a 241 CHARACTER1 (convert);
10256cbe
JD
242 CHARACTER2 (decimal);
243 CHARACTER1 (encoding);
244 CHARACTER2 (round);
245 CHARACTER1 (sign);
246 CHARACTER2 (asynchronous);
dcfddbd4 247 GFC_INTEGER_4 *newunit;
5e805e44
JJ
248}
249st_parameter_open;
6de9cd9a 250
5e805e44 251#define IOPARM_CLOSE_HAS_STATUS (1 << 7)
6de9cd9a 252
5e805e44
JJ
253typedef struct
254{
255 st_parameter_common common;
256 CHARACTER1 (status);
257}
258st_parameter_close;
6de9cd9a 259
5e805e44
JJ
260typedef struct
261{
262 st_parameter_common common;
263}
264st_parameter_filepos;
265
266#define IOPARM_INQUIRE_HAS_EXIST (1 << 7)
267#define IOPARM_INQUIRE_HAS_OPENED (1 << 8)
268#define IOPARM_INQUIRE_HAS_NUMBER (1 << 9)
269#define IOPARM_INQUIRE_HAS_NAMED (1 << 10)
270#define IOPARM_INQUIRE_HAS_NEXTREC (1 << 11)
271#define IOPARM_INQUIRE_HAS_RECL_OUT (1 << 12)
91b30ee5
JD
272#define IOPARM_INQUIRE_HAS_STRM_POS_OUT (1 << 13)
273#define IOPARM_INQUIRE_HAS_FILE (1 << 14)
274#define IOPARM_INQUIRE_HAS_ACCESS (1 << 15)
275#define IOPARM_INQUIRE_HAS_FORM (1 << 16)
276#define IOPARM_INQUIRE_HAS_BLANK (1 << 17)
277#define IOPARM_INQUIRE_HAS_POSITION (1 << 18)
278#define IOPARM_INQUIRE_HAS_ACTION (1 << 19)
279#define IOPARM_INQUIRE_HAS_DELIM (1 << 20)
280#define IOPARM_INQUIRE_HAS_PAD (1 << 21)
281#define IOPARM_INQUIRE_HAS_NAME (1 << 22)
282#define IOPARM_INQUIRE_HAS_SEQUENTIAL (1 << 23)
283#define IOPARM_INQUIRE_HAS_DIRECT (1 << 24)
284#define IOPARM_INQUIRE_HAS_FORMATTED (1 << 25)
285#define IOPARM_INQUIRE_HAS_UNFORMATTED (1 << 26)
286#define IOPARM_INQUIRE_HAS_READ (1 << 27)
287#define IOPARM_INQUIRE_HAS_WRITE (1 << 28)
288#define IOPARM_INQUIRE_HAS_READWRITE (1 << 29)
289#define IOPARM_INQUIRE_HAS_CONVERT (1 << 30)
10256cbe
JD
290#define IOPARM_INQUIRE_HAS_FLAGS2 (1 << 31)
291
292#define IOPARM_INQUIRE_HAS_ASYNCHRONOUS (1 << 0)
293#define IOPARM_INQUIRE_HAS_DECIMAL (1 << 1)
294#define IOPARM_INQUIRE_HAS_ENCODING (1 << 2)
e1456843
JJ
295#define IOPARM_INQUIRE_HAS_ROUND (1 << 3)
296#define IOPARM_INQUIRE_HAS_SIGN (1 << 4)
297#define IOPARM_INQUIRE_HAS_PENDING (1 << 5)
10256cbe
JD
298#define IOPARM_INQUIRE_HAS_SIZE (1 << 6)
299#define IOPARM_INQUIRE_HAS_ID (1 << 7)
797332ed 300#define IOPARM_INQUIRE_HAS_IQSTREAM (1 << 8)
b8d5e926 301
5e805e44
JJ
302typedef struct
303{
304 st_parameter_common common;
305 GFC_INTEGER_4 *exist, *opened, *number, *named;
306 GFC_INTEGER_4 *nextrec, *recl_out;
91b30ee5 307 GFC_IO_INT *strm_pos_out;
5e805e44
JJ
308 CHARACTER1 (file);
309 CHARACTER2 (access);
310 CHARACTER1 (form);
311 CHARACTER2 (blank);
312 CHARACTER1 (position);
313 CHARACTER2 (action);
314 CHARACTER1 (delim);
315 CHARACTER2 (pad);
316 CHARACTER1 (name);
317 CHARACTER2 (sequential);
318 CHARACTER1 (direct);
319 CHARACTER2 (formatted);
320 CHARACTER1 (unformatted);
321 CHARACTER2 (read);
322 CHARACTER1 (write);
323 CHARACTER2 (readwrite);
181c9f4a 324 CHARACTER1 (convert);
10256cbe
JD
325 GFC_INTEGER_4 flags2;
326 CHARACTER1 (asynchronous);
931149a6 327 CHARACTER2 (decimal);
10256cbe 328 CHARACTER1 (encoding);
e1456843
JJ
329 CHARACTER2 (round);
330 CHARACTER1 (sign);
331 GFC_INTEGER_4 *pending;
260f179b 332 GFC_IO_INT *size;
931149a6 333 GFC_INTEGER_4 *id;
797332ed 334 CHARACTER1 (iqstream);
5e805e44
JJ
335}
336st_parameter_inquire;
337
5e805e44
JJ
338
339#define IOPARM_DT_LIST_FORMAT (1 << 7)
340#define IOPARM_DT_NAMELIST_READ_MODE (1 << 8)
341#define IOPARM_DT_HAS_REC (1 << 9)
342#define IOPARM_DT_HAS_SIZE (1 << 10)
343#define IOPARM_DT_HAS_IOLENGTH (1 << 11)
344#define IOPARM_DT_HAS_FORMAT (1 << 12)
345#define IOPARM_DT_HAS_ADVANCE (1 << 13)
346#define IOPARM_DT_HAS_INTERNAL_UNIT (1 << 14)
347#define IOPARM_DT_HAS_NAMELIST_NAME (1 << 15)
10256cbe
JD
348#define IOPARM_DT_HAS_ID (1 << 16)
349#define IOPARM_DT_HAS_POS (1 << 17)
350#define IOPARM_DT_HAS_ASYNCHRONOUS (1 << 18)
351#define IOPARM_DT_HAS_BLANK (1 << 19)
352#define IOPARM_DT_HAS_DECIMAL (1 << 20)
353#define IOPARM_DT_HAS_DELIM (1 << 21)
354#define IOPARM_DT_HAS_PAD (1 << 22)
355#define IOPARM_DT_HAS_ROUND (1 << 23)
356#define IOPARM_DT_HAS_SIGN (1 << 24)
d7445152 357#define IOPARM_DT_HAS_F2003 (1 << 25)
5e805e44
JJ
358/* Internal use bit. */
359#define IOPARM_DT_IONML_SET (1 << 31)
360
d7445152 361
d7445152
JD
362typedef struct st_parameter_dt
363{
364 st_parameter_common common;
365 GFC_IO_INT rec;
366 GFC_IO_INT *size, *iolength;
367 gfc_array_char *internal_unit_desc;
368 CHARACTER1 (format);
369 CHARACTER2 (advance);
370 CHARACTER1 (internal_unit);
371 CHARACTER2 (namelist_name);
5e805e44
JJ
372 /* Private part of the structure. The compiler just needs
373 to reserve enough space. */
374 union
375 {
e1456843
JJ
376 struct
377 {
378 void (*transfer) (struct st_parameter_dt *, bt, void *, int,
379 size_t, size_t);
380 struct gfc_unit *current_unit;
381 /* Item number in a formatted data transfer. Also used in namelist
382 read_logical as an index into line_buffer. */
383 int item_count;
384 unit_mode mode;
385 unit_blank blank_status;
386 unit_sign sign_status;
387 int scale_factor;
388 int max_pos; /* Maximum righthand column written to. */
389 /* Number of skips + spaces to be done for T and X-editing. */
390 int skips;
391 /* Number of spaces to be done for T and X-editing. */
392 int pending_spaces;
393 /* Whether an EOR condition was encountered. Value is:
394 0 if no EOR was encountered
395 1 if an EOR was encountered due to a 1-byte marker (LF)
396 2 if an EOR was encountered due to a 2-bytes marker (CRLF) */
397 int sf_seen_eor;
398 unit_advance advance_status;
399 unsigned reversion_flag : 1; /* Format reversion has occurred. */
400 unsigned first_item : 1;
401 unsigned seen_dollar : 1;
402 unsigned eor_condition : 1;
403 unsigned no_leading_blank : 1;
404 unsigned char_flag : 1;
405 unsigned input_complete : 1;
406 unsigned at_eol : 1;
407 unsigned comma_flag : 1;
408 /* A namelist specific flag used in the list directed library
eea58adb 409 to flag that calls are being made from namelist read (e.g. to
e1456843
JJ
410 ignore comments or to treat '/' as a terminator) */
411 unsigned namelist_mode : 1;
412 /* A namelist specific flag used in the list directed library
413 to flag read errors and return, so that an attempt can be
414 made to read a new object name. */
415 unsigned nml_read_error : 1;
416 /* A sequential formatted read specific flag used to signal that a
417 character string is being read so don't use commas to shorten a
418 formatted field width. */
419 unsigned sf_read_comma : 1;
420 /* A namelist specific flag used to enable reading input from
421 line_buffer for logical reads. */
422 unsigned line_buffer_enabled : 1;
423 /* An internal unit specific flag used to identify that the associated
424 unit is internal. */
425 unsigned unit_is_internal : 1;
426 /* An internal unit specific flag to signify an EOF condition for list
427 directed read. */
428 unsigned at_eof : 1;
50220190
JD
429 /* Used for g0 floating point output. */
430 unsigned g0_no_blanks : 1;
2418d0e0
JD
431 /* Used to signal use of free_format_data. */
432 unsigned format_not_saved : 1;
2558e2e8
JD
433 /* A flag used to identify when a non-standard expanded namelist read
434 has occurred. */
435 unsigned expanded_read : 1;
436 /* 13 unused bits. */
e1456843 437
c86af7f3
JB
438 /* Used for ungetc() style functionality. Possible values
439 are an unsigned char, EOF, or EOF - 1 used to mark the
440 field as not valid. */
441 int last_char;
e1456843
JJ
442 char nml_delim;
443
444 int repeat_count;
445 int saved_length;
446 int saved_used;
447 bt saved_type;
448 char *saved_string;
449 char *scratch;
450 char *line_buffer;
451 struct format_data *fmt;
e1456843 452 namelist_info *ionml;
2558e2e8
JD
453 /* Current position within the look-ahead line buffer. */
454 int line_buffer_pos;
60c063fa
JB
455 /* Storage area for values except for strings. Must be
456 large enough to hold a complex value (two reals) of the
6b680210
JB
457 largest kind. */
458 char value[32];
e1456843
JJ
459 GFC_IO_INT size_used;
460 } p;
ebf85e50
JJ
461 /* This pad size must be equal to the pad_size declared in
462 trans-io.c (gfc_build_io_library_fndecls). The above structure
463 must be smaller or equal to this array. */
e1456843 464 char pad[16 * sizeof (char *) + 32 * sizeof (int)];
5e805e44 465 } u;
e1456843
JJ
466 GFC_INTEGER_4 *id;
467 GFC_IO_INT pos;
468 CHARACTER1 (asynchronous);
469 CHARACTER2 (blank);
470 CHARACTER1 (decimal);
471 CHARACTER2 (delim);
472 CHARACTER1 (pad);
473 CHARACTER2 (round);
474 CHARACTER1 (sign);
6de9cd9a 475}
5e805e44 476st_parameter_dt;
6de9cd9a 477
ebf85e50
JJ
478/* Ensure st_parameter_dt's u.pad is bigger or equal to u.p. */
479extern char check_st_parameter_dt[sizeof (((st_parameter_dt *) 0)->u.pad)
480 >= sizeof (((st_parameter_dt *) 0)->u.p)
481 ? 1 : -1];
482
10256cbe
JD
483#define IOPARM_WAIT_HAS_ID (1 << 7)
484
485typedef struct
486{
487 st_parameter_common common;
488 CHARACTER1 (id);
489}
490st_parameter_wait;
491
492
5e805e44
JJ
493#undef CHARACTER1
494#undef CHARACTER2
6de9cd9a
DN
495
496typedef struct
497{
498 unit_access access;
499 unit_action action;
500 unit_blank blank;
501 unit_delim delim;
502 unit_form form;
503 int is_notpadded;
504 unit_position position;
505 unit_status status;
506 unit_pad pad;
d7445152
JD
507 unit_convert convert;
508 int has_recl;
10256cbe
JD
509 unit_decimal decimal;
510 unit_encoding encoding;
511 unit_round round;
512 unit_sign sign;
10256cbe 513 unit_async async;
6de9cd9a
DN
514}
515unit_flags;
516
517
909087e0 518typedef struct gfc_unit
6de9cd9a
DN
519{
520 int unit_number;
6de9cd9a 521 stream *s;
965eec16
JD
522
523 /* Treap links. */
524 struct gfc_unit *left, *right;
6de9cd9a
DN
525 int priority;
526
108bc190
TK
527 int read_bad, current_record, saved_pos, previous_nonadvancing_write;
528
6de9cd9a
DN
529 enum
530 { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE }
531 endfile;
532
5e805e44 533 unit_mode mode;
6de9cd9a 534 unit_flags flags;
105b7136
JD
535 unit_pad pad_status;
536 unit_decimal decimal_status;
537 unit_delim delim_status;
379924dd 538 unit_round round_status;
5e805e44 539
07b3bbf2
TK
540 /* recl -- Record length of the file.
541 last_record -- Last record number read or written
542 maxrec -- Maximum record number in a direct access file
543 bytes_left -- Bytes left in current record.
544 strm_pos -- Current position in file for STREAM I/O.
545 recl_subrecord -- Maximum length for subrecord.
546 bytes_left_subrecord -- Bytes left in current subrecord. */
547 gfc_offset recl, last_record, maxrec, bytes_left, strm_pos,
548 recl_subrecord, bytes_left_subrecord;
549
550 /* Set to 1 if we have read a subrecord. */
551
552 int continued;
6de9cd9a 553
5e805e44
JJ
554 __gthread_mutex_t lock;
555 /* Number of threads waiting to acquire this unit's lock.
556 When non-zero, close_unit doesn't only removes the unit
557 from the UNIT_ROOT tree, but doesn't free it and the
558 last of the waiting threads will do that.
559 This must be either atomically increased/decreased, or
560 always guarded by UNIT_LOCK. */
561 int waiting;
562 /* Flag set by close_unit if the unit as been closed.
563 Must be manipulated under unit's lock. */
564 int closed;
565
965eec16
JD
566 /* For traversing arrays */
567 array_loop_spec *ls;
568 int rank;
5e805e44 569
6de9cd9a 570 int file_len;
5e805e44 571 char *file;
7812c78c
JD
572
573 /* The format hash table. */
574 struct format_hash_entry format_hash_table[FORMAT_HASH_SIZE];
15877a88
JB
575
576 /* Formatting buffer. */
577 struct fbuf *fbuf;
d428be77
JD
578
579 /* Function pointer, points to list_read worker functions. */
580 int (*next_char_fn_ptr) (st_parameter_dt *);
581 void (*push_char_fn_ptr) (st_parameter_dt *, int);
6de9cd9a 582}
909087e0 583gfc_unit;
6de9cd9a 584
10c682a0 585
6de9cd9a
DN
586/* unit.c */
587
5e805e44
JJ
588/* Maximum file offset, computed at library initialization time. */
589extern gfc_offset max_offset;
590internal_proto(max_offset);
591
592/* Unit tree root. */
593extern gfc_unit *unit_root;
594internal_proto(unit_root);
595
596extern __gthread_mutex_t unit_lock;
597internal_proto(unit_lock);
6de9cd9a 598
7d7b8bfe
RH
599extern int close_unit (gfc_unit *);
600internal_proto(close_unit);
6de9cd9a 601
54ffdb12
JD
602extern gfc_unit *get_internal_unit (st_parameter_dt *);
603internal_proto(get_internal_unit);
604
605extern void free_internal_unit (st_parameter_dt *);
606internal_proto(free_internal_unit);
91b30ee5 607
7d7b8bfe
RH
608extern gfc_unit *find_unit (int);
609internal_proto(find_unit);
6de9cd9a 610
5e805e44 611extern gfc_unit *find_or_create_unit (int);
59c0928b 612internal_proto(find_or_create_unit);
5e805e44
JJ
613
614extern gfc_unit *get_unit (st_parameter_dt *, int);
7d7b8bfe 615internal_proto(get_unit);
6de9cd9a 616
5e805e44
JJ
617extern void unlock_unit (gfc_unit *);
618internal_proto(unlock_unit);
619
108bc190
TK
620extern void finish_last_advance_record (gfc_unit *u);
621internal_proto (finish_last_advance_record);
622
7812c78c
JD
623extern int unit_truncate (gfc_unit *, gfc_offset, st_parameter_common *);
624internal_proto (unit_truncate);
625
dcfddbd4
JD
626extern GFC_INTEGER_4 get_unique_unit_number (st_parameter_open *);
627internal_proto(get_unique_unit_number);
628
6de9cd9a
DN
629/* open.c */
630
5e805e44 631extern gfc_unit *new_unit (st_parameter_open *, gfc_unit *, unit_flags *);
7d7b8bfe 632internal_proto(new_unit);
6de9cd9a 633
7812c78c 634
6de9cd9a
DN
635/* transfer.c */
636
637#define SCRATCH_SIZE 300
638
7d7b8bfe
RH
639extern const char *type_name (bt);
640internal_proto(type_name);
6de9cd9a 641
7812c78c 642extern void * read_block_form (st_parameter_dt *, int *);
15877a88 643internal_proto(read_block_form);
6de9cd9a 644
74db2a47
JD
645extern void * read_block_form4 (st_parameter_dt *, int *);
646internal_proto(read_block_form4);
647
5e805e44 648extern void *write_block (st_parameter_dt *, int);
7d7b8bfe 649internal_proto(write_block);
6de9cd9a 650
9370b3c0
TK
651extern gfc_offset next_array_record (st_parameter_dt *, array_loop_spec *,
652 int*);
965eec16
JD
653internal_proto(next_array_record);
654
9370b3c0
TK
655extern gfc_offset init_loop_spec (gfc_array_char *, array_loop_spec *,
656 gfc_offset *);
965eec16
JD
657internal_proto(init_loop_spec);
658
5e805e44 659extern void next_record (st_parameter_dt *, int);
7d7b8bfe 660internal_proto(next_record);
6de9cd9a 661
10256cbe
JD
662extern void st_wait (st_parameter_wait *);
663export_proto(st_wait);
664
7812c78c
JD
665extern void hit_eof (st_parameter_dt *);
666internal_proto(hit_eof);
667
6de9cd9a
DN
668/* read.c */
669
32aa3bff 670extern void set_integer (void *, GFC_INTEGER_LARGEST, int);
7d7b8bfe 671internal_proto(set_integer);
6de9cd9a 672
80b91c0b
JB
673extern GFC_UINTEGER_LARGEST si_max (int);
674internal_proto(si_max);
6de9cd9a 675
5e805e44 676extern int convert_real (st_parameter_dt *, void *, const char *, int);
7d7b8bfe 677internal_proto(convert_real);
6de9cd9a 678
458653cc
JDA
679extern int convert_infnan (st_parameter_dt *, void *, const char *, int);
680internal_proto(convert_infnan);
681
5e805e44 682extern void read_a (st_parameter_dt *, const fnode *, char *, int);
7d7b8bfe 683internal_proto(read_a);
6de9cd9a 684
cea93abb
JD
685extern void read_a_char4 (st_parameter_dt *, const fnode *, char *, int);
686internal_proto(read_a);
687
5e805e44 688extern void read_f (st_parameter_dt *, const fnode *, char *, int);
7d7b8bfe 689internal_proto(read_f);
6de9cd9a 690
5e805e44 691extern void read_l (st_parameter_dt *, const fnode *, char *, int);
7d7b8bfe 692internal_proto(read_l);
6de9cd9a 693
5e805e44 694extern void read_x (st_parameter_dt *, int);
7d7b8bfe 695internal_proto(read_x);
6de9cd9a 696
5e805e44 697extern void read_radix (st_parameter_dt *, const fnode *, char *, int, int);
7d7b8bfe 698internal_proto(read_radix);
6de9cd9a 699
5e805e44 700extern void read_decimal (st_parameter_dt *, const fnode *, char *, int);
7d7b8bfe 701internal_proto(read_decimal);
6de9cd9a
DN
702
703/* list_read.c */
704
5e805e44
JJ
705extern void list_formatted_read (st_parameter_dt *, bt, void *, int, size_t,
706 size_t);
7d7b8bfe 707internal_proto(list_formatted_read);
6de9cd9a 708
5e805e44 709extern void finish_list_read (st_parameter_dt *);
7d7b8bfe 710internal_proto(finish_list_read);
6de9cd9a 711
5e805e44 712extern void namelist_read (st_parameter_dt *);
7d7b8bfe 713internal_proto(namelist_read);
6de9cd9a 714
5e805e44 715extern void namelist_write (st_parameter_dt *);
7d7b8bfe 716internal_proto(namelist_write);
6de9cd9a
DN
717
718/* write.c */
719
5e805e44 720extern void write_a (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 721internal_proto(write_a);
6de9cd9a 722
cea93abb
JD
723extern void write_a_char4 (st_parameter_dt *, const fnode *, const char *, int);
724internal_proto(write_a_char4);
725
5e805e44 726extern void write_b (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 727internal_proto(write_b);
6de9cd9a 728
5e805e44 729extern void write_d (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 730internal_proto(write_d);
6de9cd9a 731
5e805e44 732extern void write_e (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 733internal_proto(write_e);
6de9cd9a 734
5e805e44 735extern void write_en (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 736internal_proto(write_en);
6de9cd9a 737
5e805e44 738extern void write_es (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 739internal_proto(write_es);
6de9cd9a 740
5e805e44 741extern void write_f (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 742internal_proto(write_f);
6de9cd9a 743
5e805e44 744extern void write_i (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 745internal_proto(write_i);
6de9cd9a 746
5e805e44 747extern void write_l (st_parameter_dt *, const fnode *, char *, int);
7d7b8bfe 748internal_proto(write_l);
6de9cd9a 749
5e805e44 750extern void write_o (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 751internal_proto(write_o);
6de9cd9a 752
9355110f
JD
753extern void write_real (st_parameter_dt *, const char *, int);
754internal_proto(write_real);
755
900e887f
JD
756extern void write_real_g0 (st_parameter_dt *, const char *, int, int);
757internal_proto(write_real_g0);
758
5e805e44 759extern void write_x (st_parameter_dt *, int, int);
7d7b8bfe 760internal_proto(write_x);
6de9cd9a 761
5e805e44 762extern void write_z (st_parameter_dt *, const fnode *, const char *, int);
7d7b8bfe 763internal_proto(write_z);
6de9cd9a 764
5e805e44
JJ
765extern void list_formatted_write (st_parameter_dt *, bt, void *, int, size_t,
766 size_t);
7d7b8bfe 767internal_proto(list_formatted_write);
6de9cd9a 768
e5ef4b3b
JB
769/* size_from_kind.c */
770extern size_t size_from_real_kind (int);
771internal_proto(size_from_real_kind);
772
773extern size_t size_from_complex_kind (int);
774internal_proto(size_from_complex_kind);
775
7812c78c 776
5e805e44
JJ
777/* lock.c */
778extern void free_ionml (st_parameter_dt *);
779internal_proto(free_ionml);
780
781static inline void
782inc_waiting_locked (gfc_unit *u)
783{
784#ifdef HAVE_SYNC_FETCH_AND_ADD
785 (void) __sync_fetch_and_add (&u->waiting, 1);
786#else
787 u->waiting++;
788#endif
789}
790
791static inline int
792predec_waiting_locked (gfc_unit *u)
793{
794#ifdef HAVE_SYNC_FETCH_AND_ADD
795 return __sync_add_and_fetch (&u->waiting, -1);
796#else
797 return --u->waiting;
798#endif
799}
800
801static inline void
802dec_waiting_unlocked (gfc_unit *u)
803{
804#ifdef HAVE_SYNC_FETCH_AND_ADD
805 (void) __sync_fetch_and_add (&u->waiting, -1);
806#else
807 __gthread_mutex_lock (&unit_lock);
808 u->waiting--;
809 __gthread_mutex_unlock (&unit_lock);
810#endif
811}
812
992b0aa1
JB
813
814static inline void
815memset4 (gfc_char4_t *p, gfc_char4_t c, int k)
816{
817 int j;
818 for (j = 0; j < k; j++)
819 *p++ = c;
820}
821
6de9cd9a 822#endif
eaa90d25 823