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