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