Merge Ignore and Deprecated in .opt files.
[official-gcc.git] / libgfortran / io / io.h
blobccbaf47ff907ab5aa797c9bff4502df5f3bfc31f
1 /* Copyright (C) 2002-2018 Free Software Foundation, Inc.
2 Contributed by Andy Vaught
3 F2003 I/O support contributed by Jerry DeLisle
5 This file is part of the GNU Fortran runtime library (libgfortran).
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.
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.
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.
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/>. */
26 #ifndef GFOR_IO_H
27 #define GFOR_IO_H
29 /* IO library include. */
31 #include "libgfortran.h"
33 #include <gthr.h>
36 /* POSIX 2008 specifies that the extended locale stuff is found in
37 locale.h, but some systems have them in xlocale.h. */
39 #include <locale.h>
41 #ifdef HAVE_XLOCALE_H
42 #include <xlocale.h>
43 #endif
46 /* Forward declarations. */
47 struct st_parameter_dt;
48 typedef struct stream stream;
49 struct fbuf;
50 struct format_data;
51 typedef struct fnode fnode;
52 struct gfc_unit;
54 #ifdef HAVE_NEWLOCALE
55 /* We have POSIX 2008 extended locale stuff. */
56 extern locale_t c_locale;
57 internal_proto(c_locale);
58 #else
59 extern char* old_locale;
60 internal_proto(old_locale);
61 extern int old_locale_ctr;
62 internal_proto(old_locale_ctr);
63 extern __gthread_mutex_t old_locale_lock;
64 internal_proto(old_locale_lock);
65 #endif
68 /* Macros for testing what kinds of I/O we are doing. */
70 #define is_array_io(dtp) ((dtp)->internal_unit_desc)
72 #define is_internal_unit(dtp) ((dtp)->u.p.unit_is_internal)
74 #define is_stream_io(dtp) ((dtp)->u.p.current_unit->flags.access == ACCESS_STREAM)
76 #define is_char4_unit(dtp) ((dtp)->u.p.current_unit->internal_unit_kind == 4)
78 /* The array_loop_spec contains the variables for the loops over index ranges
79 that are encountered. */
81 typedef struct array_loop_spec
83 /* Index counter for this dimension. */
84 index_type idx;
86 /* Start for the index counter. */
87 index_type start;
89 /* End for the index counter. */
90 index_type end;
92 /* Step for the index counter. */
93 index_type step;
95 array_loop_spec;
97 /* User defined input/output iomsg length. */
99 #define IOMSG_LEN 256
101 /* Subroutine formatted_dtio (struct, unit, iotype, v_list, iostat,
102 iomsg, (_iotype), (_iomsg)) */
103 typedef void (*formatted_dtio)(void *, GFC_INTEGER_4 *, char *, gfc_array_i4 *,
104 GFC_INTEGER_4 *, char *,
105 gfc_charlen_type, gfc_charlen_type);
107 /* Subroutine unformatted_dtio (struct, unit, iostat, iomsg, (_iomsg)) */
108 typedef void (*unformatted_dtio)(void *, GFC_INTEGER_4 *, GFC_INTEGER_4 *,
109 char *, gfc_charlen_type);
111 /* The dtio calls for namelist require a CLASS object to be built. */
112 typedef struct gfc_class
114 void *data;
115 void *vptr;
116 index_type len;
118 gfc_class;
121 /* A structure to build a hash table for format data. */
123 #define FORMAT_HASH_SIZE 16
125 typedef struct format_hash_entry
127 char *key;
128 gfc_charlen_type key_len;
129 struct format_data *hashed_fmt;
131 format_hash_entry;
133 /* Representation of a namelist object in libgfortran
135 Namelist Records
136 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]].../
138 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]]...&END
140 The object can be a fully qualified, compound name for an intrinsic
141 type, derived types or derived type components. So, a substring
142 a(:)%b(4)%ch(2:4)(1:7) has to be treated correctly in namelist
143 read. Hence full information about the structure of the object has
144 to be available to list_read.c and write.
146 These requirements are met by the following data structures.
148 namelist_info type contains all the scalar information about the
149 object and arrays of descriptor_dimension and array_loop_spec types for
150 arrays. */
152 typedef struct namelist_type
154 /* Object type. */
155 bt type;
157 /* Object name. */
158 char * var_name;
160 /* Address for the start of the object's data. */
161 void * mem_pos;
163 /* Address of specific DTIO subroutine. */
164 void * dtio_sub;
166 /* Address of vtable if dtio_sub non-null. */
167 void * vtable;
169 /* Flag to show that a read is to be attempted for this node. */
170 int touched;
172 /* Length of intrinsic type in bytes. */
173 int len;
175 /* Rank of the object. */
176 int var_rank;
178 /* Overall size of the object in bytes. */
179 index_type size;
181 /* Length of character string. */
182 index_type string_length;
184 descriptor_dimension * dim;
185 array_loop_spec * ls;
186 struct namelist_type * next;
188 namelist_info;
190 /* Options for the OPEN statement. */
192 typedef enum
193 { ACCESS_SEQUENTIAL, ACCESS_DIRECT, ACCESS_APPEND, ACCESS_STREAM,
194 ACCESS_UNSPECIFIED
196 unit_access;
198 typedef enum
199 { ACTION_READ, ACTION_WRITE, ACTION_READWRITE,
200 ACTION_UNSPECIFIED
202 unit_action;
204 typedef enum
205 { BLANK_NULL, BLANK_ZERO, BLANK_UNSPECIFIED }
206 unit_blank;
208 typedef enum
209 { DELIM_NONE, DELIM_APOSTROPHE, DELIM_QUOTE,
210 DELIM_UNSPECIFIED
212 unit_delim;
214 typedef enum
215 { FORM_FORMATTED, FORM_UNFORMATTED, FORM_UNSPECIFIED }
216 unit_form;
218 typedef enum
219 { POSITION_ASIS, POSITION_REWIND, POSITION_APPEND,
220 POSITION_UNSPECIFIED
222 unit_position;
224 typedef enum
225 { STATUS_UNKNOWN, STATUS_OLD, STATUS_NEW, STATUS_SCRATCH,
226 STATUS_REPLACE, STATUS_UNSPECIFIED
228 unit_status;
230 typedef enum
231 { PAD_YES, PAD_NO, PAD_UNSPECIFIED }
232 unit_pad;
234 typedef enum
235 { DECIMAL_POINT, DECIMAL_COMMA, DECIMAL_UNSPECIFIED }
236 unit_decimal;
238 typedef enum
239 { ENCODING_UTF8, ENCODING_DEFAULT, ENCODING_UNSPECIFIED }
240 unit_encoding;
242 typedef enum
243 { ROUND_UP = GFC_FPE_UPWARD,
244 ROUND_DOWN = GFC_FPE_DOWNWARD,
245 ROUND_ZERO = GFC_FPE_TOWARDZERO,
246 ROUND_NEAREST = GFC_FPE_TONEAREST,
247 ROUND_COMPATIBLE = 10, /* round away from zero. */
248 ROUND_PROCDEFINED, /* Here as ROUND_NEAREST. */
249 ROUND_UNSPECIFIED /* Should never occur. */
251 unit_round;
253 /* NOTE: unit_sign must correspond with the sign_status enumerator in
254 st_parameter_dt to not break the ABI. */
255 typedef enum
256 { SIGN_PROCDEFINED, SIGN_SUPPRESS, SIGN_PLUS, SIGN_UNSPECIFIED }
257 unit_sign;
259 typedef enum
260 { ADVANCE_YES, ADVANCE_NO, ADVANCE_UNSPECIFIED }
261 unit_advance;
263 typedef enum
264 {READING, WRITING, LIST_READING, LIST_WRITING}
265 unit_mode;
267 typedef enum
268 { ASYNC_YES, ASYNC_NO, ASYNC_UNSPECIFIED }
269 unit_async;
271 typedef enum
272 { SHARE_DENYRW, SHARE_DENYNONE,
273 SHARE_UNSPECIFIED
275 unit_share;
277 typedef enum
278 { CC_LIST, CC_FORTRAN, CC_NONE,
279 CC_UNSPECIFIED
281 unit_cc;
283 /* End-of-record types for CC_FORTRAN. */
284 typedef enum
285 { CCF_DEFAULT=0x0,
286 CCF_OVERPRINT=0x1,
287 CCF_ONE_LF=0x2,
288 CCF_TWO_LF=0x4,
289 CCF_PAGE_FEED=0x8,
290 CCF_PROMPT=0x10,
291 CCF_OVERPRINT_NOA=0x20,
292 } /* 6 bits */
293 cc_fortran;
295 typedef enum
296 { SIGN_S, SIGN_SS, SIGN_SP }
297 unit_sign_s;
299 /* Make sure to keep st_parameter_* in sync with gcc/fortran/ioparm.def. */
301 #define CHARACTER1(name) \
302 char * name; \
303 gfc_charlen_type name ## _len
304 #define CHARACTER2(name) \
305 gfc_charlen_type name ## _len; \
306 char * name
308 typedef struct
310 st_parameter_common common;
311 GFC_IO_INT recl_in;
312 CHARACTER2 (file);
313 CHARACTER1 (status);
314 CHARACTER2 (access);
315 CHARACTER1 (form);
316 CHARACTER2 (blank);
317 CHARACTER1 (position);
318 CHARACTER2 (action);
319 CHARACTER1 (delim);
320 CHARACTER2 (pad);
321 CHARACTER1 (convert);
322 CHARACTER2 (decimal);
323 CHARACTER1 (encoding);
324 CHARACTER2 (round);
325 CHARACTER1 (sign);
326 CHARACTER2 (asynchronous);
327 GFC_INTEGER_4 *newunit;
328 GFC_INTEGER_4 readonly;
329 CHARACTER2 (cc);
330 CHARACTER1 (share);
332 st_parameter_open;
334 #define IOPARM_CLOSE_HAS_STATUS (1 << 7)
336 typedef struct
338 st_parameter_common common;
339 CHARACTER1 (status);
341 st_parameter_close;
343 typedef struct
345 st_parameter_common common;
347 st_parameter_filepos;
349 #define IOPARM_INQUIRE_HAS_EXIST (1 << 7)
350 #define IOPARM_INQUIRE_HAS_OPENED (1 << 8)
351 #define IOPARM_INQUIRE_HAS_NUMBER (1 << 9)
352 #define IOPARM_INQUIRE_HAS_NAMED (1 << 10)
353 #define IOPARM_INQUIRE_HAS_NEXTREC (1 << 11)
354 #define IOPARM_INQUIRE_HAS_RECL_OUT (1 << 12)
355 #define IOPARM_INQUIRE_HAS_STRM_POS_OUT (1 << 13)
356 #define IOPARM_INQUIRE_HAS_FILE (1 << 14)
357 #define IOPARM_INQUIRE_HAS_ACCESS (1 << 15)
358 #define IOPARM_INQUIRE_HAS_FORM (1 << 16)
359 #define IOPARM_INQUIRE_HAS_BLANK (1 << 17)
360 #define IOPARM_INQUIRE_HAS_POSITION (1 << 18)
361 #define IOPARM_INQUIRE_HAS_ACTION (1 << 19)
362 #define IOPARM_INQUIRE_HAS_DELIM (1 << 20)
363 #define IOPARM_INQUIRE_HAS_PAD (1 << 21)
364 #define IOPARM_INQUIRE_HAS_NAME (1 << 22)
365 #define IOPARM_INQUIRE_HAS_SEQUENTIAL (1 << 23)
366 #define IOPARM_INQUIRE_HAS_DIRECT (1 << 24)
367 #define IOPARM_INQUIRE_HAS_FORMATTED (1 << 25)
368 #define IOPARM_INQUIRE_HAS_UNFORMATTED (1 << 26)
369 #define IOPARM_INQUIRE_HAS_READ (1 << 27)
370 #define IOPARM_INQUIRE_HAS_WRITE (1 << 28)
371 #define IOPARM_INQUIRE_HAS_READWRITE (1 << 29)
372 #define IOPARM_INQUIRE_HAS_CONVERT (1 << 30)
373 #define IOPARM_INQUIRE_HAS_FLAGS2 (1u << 31)
375 #define IOPARM_INQUIRE_HAS_ASYNCHRONOUS (1 << 0)
376 #define IOPARM_INQUIRE_HAS_DECIMAL (1 << 1)
377 #define IOPARM_INQUIRE_HAS_ENCODING (1 << 2)
378 #define IOPARM_INQUIRE_HAS_ROUND (1 << 3)
379 #define IOPARM_INQUIRE_HAS_SIGN (1 << 4)
380 #define IOPARM_INQUIRE_HAS_PENDING (1 << 5)
381 #define IOPARM_INQUIRE_HAS_SIZE (1 << 6)
382 #define IOPARM_INQUIRE_HAS_ID (1 << 7)
383 #define IOPARM_INQUIRE_HAS_IQSTREAM (1 << 8)
384 #define IOPARM_INQUIRE_HAS_SHARE (1 << 9)
385 #define IOPARM_INQUIRE_HAS_CC (1 << 10)
387 typedef struct
389 st_parameter_common common;
390 GFC_INTEGER_4 *exist, *opened, *number, *named;
391 GFC_IO_INT *nextrec, *recl_out, *strm_pos_out;
392 CHARACTER1 (file);
393 CHARACTER2 (access);
394 CHARACTER1 (form);
395 CHARACTER2 (blank);
396 CHARACTER1 (position);
397 CHARACTER2 (action);
398 CHARACTER1 (delim);
399 CHARACTER2 (pad);
400 CHARACTER1 (name);
401 CHARACTER2 (sequential);
402 CHARACTER1 (direct);
403 CHARACTER2 (formatted);
404 CHARACTER1 (unformatted);
405 CHARACTER2 (read);
406 CHARACTER1 (write);
407 CHARACTER2 (readwrite);
408 CHARACTER1 (convert);
409 GFC_INTEGER_4 flags2;
410 CHARACTER1 (asynchronous);
411 CHARACTER2 (decimal);
412 CHARACTER1 (encoding);
413 CHARACTER2 (round);
414 CHARACTER1 (sign);
415 GFC_INTEGER_4 *pending;
416 GFC_IO_INT *size;
417 GFC_INTEGER_4 *id;
418 CHARACTER1 (iqstream);
419 CHARACTER2 (share);
420 CHARACTER1 (cc);
422 st_parameter_inquire;
425 #define IOPARM_DT_LIST_FORMAT (1 << 7)
426 #define IOPARM_DT_NAMELIST_READ_MODE (1 << 8)
427 #define IOPARM_DT_HAS_REC (1 << 9)
428 #define IOPARM_DT_HAS_SIZE (1 << 10)
429 #define IOPARM_DT_HAS_IOLENGTH (1 << 11)
430 #define IOPARM_DT_HAS_FORMAT (1 << 12)
431 #define IOPARM_DT_HAS_ADVANCE (1 << 13)
432 #define IOPARM_DT_HAS_INTERNAL_UNIT (1 << 14)
433 #define IOPARM_DT_HAS_NAMELIST_NAME (1 << 15)
434 #define IOPARM_DT_HAS_ID (1 << 16)
435 #define IOPARM_DT_HAS_POS (1 << 17)
436 #define IOPARM_DT_HAS_ASYNCHRONOUS (1 << 18)
437 #define IOPARM_DT_HAS_BLANK (1 << 19)
438 #define IOPARM_DT_HAS_DECIMAL (1 << 20)
439 #define IOPARM_DT_HAS_DELIM (1 << 21)
440 #define IOPARM_DT_HAS_PAD (1 << 22)
441 #define IOPARM_DT_HAS_ROUND (1 << 23)
442 #define IOPARM_DT_HAS_SIGN (1 << 24)
443 #define IOPARM_DT_HAS_F2003 (1 << 25)
444 #define IOPARM_DT_HAS_UDTIO (1 << 26)
445 #define IOPARM_DT_DEC_EXT (1 << 27)
446 /* Internal use bit. */
447 #define IOPARM_DT_IONML_SET (1u << 31)
450 typedef struct st_parameter_dt
452 st_parameter_common common;
453 GFC_IO_INT rec;
454 GFC_IO_INT *size, *iolength;
455 gfc_array_char *internal_unit_desc;
456 CHARACTER1 (format);
457 CHARACTER2 (advance);
458 CHARACTER1 (internal_unit);
459 CHARACTER2 (namelist_name);
460 GFC_INTEGER_4 *id;
461 GFC_IO_INT pos;
462 CHARACTER1 (asynchronous);
463 CHARACTER2 (blank);
464 CHARACTER1 (decimal);
465 CHARACTER2 (delim);
466 CHARACTER1 (pad);
467 CHARACTER2 (round);
468 CHARACTER1 (sign);
469 /* Private part of the structure. The compiler just needs
470 to reserve enough space. */
471 union
473 struct
475 void (*transfer) (struct st_parameter_dt *, bt, void *, int,
476 size_t, size_t);
477 struct gfc_unit *current_unit;
478 /* Item number in a formatted data transfer. Also used in namelist
479 read_logical as an index into line_buffer. */
480 int item_count;
481 unit_mode mode;
482 unit_blank blank_status;
483 unit_sign sign_status;
484 int scale_factor;
485 /* Maximum righthand column written to. */
486 int max_pos;
487 /* Number of skips + spaces to be done for T and X-editing. */
488 int skips;
489 /* Number of spaces to be done for T and X-editing. */
490 int pending_spaces;
491 /* Whether an EOR condition was encountered. Value is:
492 0 if no EOR was encountered
493 1 if an EOR was encountered due to a 1-byte marker (LF)
494 2 if an EOR was encountered due to a 2-bytes marker (CRLF) */
495 int sf_seen_eor;
496 unit_advance advance_status;
497 unsigned reversion_flag : 1; /* Format reversion has occurred. */
498 unsigned first_item : 1;
499 unsigned seen_dollar : 1;
500 unsigned eor_condition : 1;
501 unsigned no_leading_blank : 1;
502 unsigned char_flag : 1;
503 unsigned input_complete : 1;
504 unsigned at_eol : 1;
505 unsigned comma_flag : 1;
506 /* A namelist specific flag used in the list directed library
507 to flag that calls are being made from namelist read (e.g. to
508 ignore comments or to treat '/' as a terminator) */
509 unsigned namelist_mode : 1;
510 /* A namelist specific flag used in the list directed library
511 to flag read errors and return, so that an attempt can be
512 made to read a new object name. */
513 unsigned nml_read_error : 1;
514 /* A sequential formatted read specific flag used to signal that a
515 character string is being read so don't use commas to shorten a
516 formatted field width. */
517 unsigned sf_read_comma : 1;
518 /* A namelist specific flag used to enable reading input from
519 line_buffer for logical reads. */
520 unsigned line_buffer_enabled : 1;
521 /* An internal unit specific flag used to identify that the associated
522 unit is internal. */
523 unsigned unit_is_internal : 1;
524 /* An internal unit specific flag to signify an EOF condition for list
525 directed read. */
526 unsigned at_eof : 1;
527 /* Used for g0 floating point output. */
528 unsigned g0_no_blanks : 1;
529 /* Used to signal use of free_format_data. */
530 unsigned format_not_saved : 1;
531 /* A flag used to identify when a non-standard expanded namelist read
532 has occurred. */
533 unsigned expanded_read : 1;
534 /* 13 unused bits. */
536 int child_saved_iostat;
537 int nml_delim;
538 int repeat_count;
539 int saved_length;
540 int saved_used;
541 bt saved_type;
542 char *saved_string;
543 char *scratch;
544 char *line_buffer;
545 struct format_data *fmt;
546 namelist_info *ionml;
547 #ifdef HAVE_NEWLOCALE
548 locale_t old_locale;
549 #endif
550 /* Current position within the look-ahead line buffer. */
551 int line_buffer_pos;
552 /* Storage area for values except for strings. Must be
553 large enough to hold a complex value (two reals) of the
554 largest kind. */
555 char value[32];
556 GFC_IO_INT not_used; /* Needed for alignment. */
557 formatted_dtio fdtio_ptr;
558 unformatted_dtio ufdtio_ptr;
559 /* With CC_FORTRAN, the first character of a record determines the
560 style of record end (and start) to use. We must mark down the type
561 when we write first in write_a so we remember the end type later in
562 next_record_w. */
563 struct
565 unsigned type : 6; /* See enum cc_fortran. */
566 unsigned len : 2; /* Always 0, 1, or 2. */
567 /* The union is updated after start-of-record is written. */
568 union
570 char start; /* Output character for start of record. */
571 char end; /* Output character for end of record. */
572 } u;
573 } cc;
574 } p;
575 /* This pad size must be equal to the pad_size declared in
576 trans-io.c (gfc_build_io_library_fndecls). The above structure
577 must be smaller or equal to this array. */
578 char pad[16 * sizeof (char *) + 32 * sizeof (int)];
579 } u;
581 st_parameter_dt;
583 /* Ensure st_parameter_dt's u.pad is bigger or equal to u.p. */
584 extern char check_st_parameter_dt[sizeof (((st_parameter_dt *) 0)->u.pad)
585 >= sizeof (((st_parameter_dt *) 0)->u.p)
586 ? 1 : -1];
588 #define IOPARM_WAIT_HAS_ID (1 << 7)
590 typedef struct
592 st_parameter_common common;
593 CHARACTER1 (id);
595 st_parameter_wait;
598 #undef CHARACTER1
599 #undef CHARACTER2
601 typedef struct
603 unit_access access;
604 unit_action action;
605 unit_blank blank;
606 unit_delim delim;
607 unit_form form;
608 int is_notpadded;
609 unit_position position;
610 unit_status status;
611 unit_pad pad;
612 unit_convert convert;
613 int has_recl;
614 unit_decimal decimal;
615 unit_encoding encoding;
616 unit_round round;
617 unit_sign sign;
618 unit_async async;
619 unit_share share;
620 unit_cc cc;
621 int readonly;
623 unit_flags;
626 typedef struct gfc_unit
628 int unit_number;
629 stream *s;
631 /* Treap links. */
632 struct gfc_unit *left, *right;
633 int priority;
635 int read_bad, current_record, saved_pos, previous_nonadvancing_write;
637 enum
638 { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE }
639 endfile;
641 unit_mode mode;
642 unit_flags flags;
643 unit_pad pad_status;
644 unit_decimal decimal_status;
645 unit_delim delim_status;
646 unit_round round_status;
648 /* recl -- Record length of the file.
649 last_record -- Last record number read or written
650 maxrec -- Maximum record number in a direct access file
651 bytes_left -- Bytes left in current record.
652 strm_pos -- Current position in file for STREAM I/O.
653 recl_subrecord -- Maximum length for subrecord.
654 bytes_left_subrecord -- Bytes left in current subrecord. */
655 gfc_offset recl, last_record, maxrec, bytes_left, strm_pos,
656 recl_subrecord, bytes_left_subrecord;
658 /* Set to 1 if we have read a subrecord. */
660 int continued;
662 __gthread_mutex_t lock;
663 /* Number of threads waiting to acquire this unit's lock.
664 When non-zero, close_unit doesn't only removes the unit
665 from the UNIT_ROOT tree, but doesn't free it and the
666 last of the waiting threads will do that.
667 This must be either atomically increased/decreased, or
668 always guarded by UNIT_LOCK. */
669 int waiting;
670 /* Flag set by close_unit if the unit as been closed.
671 Must be manipulated under unit's lock. */
672 int closed;
674 /* For traversing arrays */
675 array_loop_spec *ls;
676 int rank;
678 /* Name of the file at the time OPEN was executed, as a
679 null-terminated C string. */
680 char *filename;
682 /* The format hash table. */
683 struct format_hash_entry format_hash_table[FORMAT_HASH_SIZE];
685 /* Formatting buffer. */
686 struct fbuf *fbuf;
688 /* Function pointer, points to list_read worker functions. */
689 int (*next_char_fn_ptr) (st_parameter_dt *);
690 void (*push_char_fn_ptr) (st_parameter_dt *, int);
692 /* Internal unit char string data. */
693 char * internal_unit;
694 gfc_charlen_type internal_unit_len;
695 gfc_array_char *string_unit_desc;
696 int internal_unit_kind;
698 /* DTIO Parent/Child procedure, 0 = parent, >0 = child level. */
699 int child_dtio;
701 /* Used for ungetc() style functionality. Possible values
702 are an unsigned char, EOF, or EOF - 1 used to mark the
703 field as not valid. */
704 int last_char;
705 bool has_size;
706 GFC_IO_INT size_used;
708 gfc_unit;
710 typedef struct gfc_saved_unit
712 GFC_INTEGER_4 unit_number;
713 gfc_unit *unit;
715 gfc_saved_unit;
717 /* TEMP_FAILURE_RETRY macro from glibc. */
719 #ifndef TEMP_FAILURE_RETRY
720 /* Evaluate EXPRESSION, and repeat as long as it returns -1 with `errno'
721 set to EINTR. */
723 # define TEMP_FAILURE_RETRY(expression) \
724 (__extension__ \
725 ({ long int __result; \
726 do __result = (long int) (expression); \
727 while (__result == -1L && errno == EINTR); \
728 __result; }))
729 #endif
732 /* unit.c */
734 /* Maximum file offset, computed at library initialization time. */
735 extern gfc_offset max_offset;
736 internal_proto(max_offset);
738 /* Default RECL for sequential access if not given in OPEN statement,
739 computed at library initialization time. */
740 extern gfc_offset default_recl;
741 internal_proto(default_recl);
743 /* Unit tree root. */
744 extern gfc_unit *unit_root;
745 internal_proto(unit_root);
747 extern __gthread_mutex_t unit_lock;
748 internal_proto(unit_lock);
750 extern int close_unit (gfc_unit *);
751 internal_proto(close_unit);
753 extern gfc_unit *set_internal_unit (st_parameter_dt *, gfc_unit *, int);
754 internal_proto(set_internal_unit);
756 extern void stash_internal_unit (st_parameter_dt *);
757 internal_proto(stash_internal_unit);
759 extern gfc_unit *find_unit (int);
760 internal_proto(find_unit);
762 extern gfc_unit *find_or_create_unit (int);
763 internal_proto(find_or_create_unit);
765 extern gfc_unit *get_unit (st_parameter_dt *, int);
766 internal_proto(get_unit);
768 extern void unlock_unit(gfc_unit *);
769 internal_proto(unlock_unit);
771 extern void finish_last_advance_record (gfc_unit *u);
772 internal_proto(finish_last_advance_record);
774 extern int unit_truncate(gfc_unit *, gfc_offset, st_parameter_common *);
775 internal_proto(unit_truncate);
777 extern int newunit_alloc (void);
778 internal_proto(newunit_alloc);
780 extern void newunit_free (int);
781 internal_proto(newunit_free);
784 /* open.c */
786 extern gfc_unit *new_unit (st_parameter_open *, gfc_unit *, unit_flags *);
787 internal_proto(new_unit);
790 /* transfer.c */
792 #define SCRATCH_SIZE 300
794 extern const char *type_name (bt);
795 internal_proto(type_name);
797 extern void * read_block_form (st_parameter_dt *, size_t *);
798 internal_proto(read_block_form);
800 extern void * read_block_form4 (st_parameter_dt *, size_t *);
801 internal_proto(read_block_form4);
803 extern void *write_block (st_parameter_dt *, size_t);
804 internal_proto(write_block);
806 extern gfc_offset next_array_record (st_parameter_dt *, array_loop_spec *,
807 int*);
808 internal_proto(next_array_record);
810 extern gfc_offset init_loop_spec (gfc_array_char *, array_loop_spec *,
811 gfc_offset *);
812 internal_proto(init_loop_spec);
814 extern void next_record (st_parameter_dt *, int);
815 internal_proto(next_record);
817 extern void st_wait (st_parameter_wait *);
818 export_proto(st_wait);
820 extern void hit_eof (st_parameter_dt *);
821 internal_proto(hit_eof);
823 /* read.c */
825 extern void set_integer (void *, GFC_INTEGER_LARGEST, int);
826 internal_proto(set_integer);
828 extern GFC_UINTEGER_LARGEST si_max (int);
829 internal_proto(si_max);
831 extern int convert_real (st_parameter_dt *, void *, const char *, int);
832 internal_proto(convert_real);
834 extern int convert_infnan (st_parameter_dt *, void *, const char *, int);
835 internal_proto(convert_infnan);
837 extern void read_a (st_parameter_dt *, const fnode *, char *, size_t);
838 internal_proto(read_a);
840 extern void read_a_char4 (st_parameter_dt *, const fnode *, char *, size_t);
841 internal_proto(read_a);
843 extern void read_f (st_parameter_dt *, const fnode *, char *, int);
844 internal_proto(read_f);
846 extern void read_l (st_parameter_dt *, const fnode *, char *, int);
847 internal_proto(read_l);
849 extern void read_x (st_parameter_dt *, size_t);
850 internal_proto(read_x);
852 extern void read_radix (st_parameter_dt *, const fnode *, char *, int, int);
853 internal_proto(read_radix);
855 extern void read_decimal (st_parameter_dt *, const fnode *, char *, int);
856 internal_proto(read_decimal);
858 extern void read_user_defined (st_parameter_dt *, void *);
859 internal_proto(read_user_defined);
861 extern void read_user_defined (st_parameter_dt *, void *);
862 internal_proto(read_user_defined);
864 /* list_read.c */
866 extern void list_formatted_read (st_parameter_dt *, bt, void *, int, size_t,
867 size_t);
868 internal_proto(list_formatted_read);
870 extern void finish_list_read (st_parameter_dt *);
871 internal_proto(finish_list_read);
873 extern void namelist_read (st_parameter_dt *);
874 internal_proto(namelist_read);
876 extern void namelist_write (st_parameter_dt *);
877 internal_proto(namelist_write);
879 /* write.c */
881 extern void write_a (st_parameter_dt *, const fnode *, const char *, size_t);
882 internal_proto(write_a);
884 extern void write_a_char4 (st_parameter_dt *, const fnode *, const char *, size_t);
885 internal_proto(write_a_char4);
887 extern void write_b (st_parameter_dt *, const fnode *, const char *, int);
888 internal_proto(write_b);
890 extern void write_d (st_parameter_dt *, const fnode *, const char *, int);
891 internal_proto(write_d);
893 extern void write_e (st_parameter_dt *, const fnode *, const char *, int);
894 internal_proto(write_e);
896 extern void write_en (st_parameter_dt *, const fnode *, const char *, int);
897 internal_proto(write_en);
899 extern void write_es (st_parameter_dt *, const fnode *, const char *, int);
900 internal_proto(write_es);
902 extern void write_f (st_parameter_dt *, const fnode *, const char *, int);
903 internal_proto(write_f);
905 extern void write_i (st_parameter_dt *, const fnode *, const char *, int);
906 internal_proto(write_i);
908 extern void write_l (st_parameter_dt *, const fnode *, char *, int);
909 internal_proto(write_l);
911 extern void write_o (st_parameter_dt *, const fnode *, const char *, int);
912 internal_proto(write_o);
914 extern void write_real (st_parameter_dt *, const char *, int);
915 internal_proto(write_real);
917 extern void write_real_g0 (st_parameter_dt *, const char *, int, int);
918 internal_proto(write_real_g0);
920 extern void write_x (st_parameter_dt *, int, int);
921 internal_proto(write_x);
923 extern void write_z (st_parameter_dt *, const fnode *, const char *, int);
924 internal_proto(write_z);
926 extern void write_user_defined (st_parameter_dt *, void *);
927 internal_proto(write_user_defined);
929 extern void write_user_defined (st_parameter_dt *, void *);
930 internal_proto(write_user_defined);
932 extern void list_formatted_write (st_parameter_dt *, bt, void *, int, size_t,
933 size_t);
934 internal_proto(list_formatted_write);
936 /* size_from_kind.c */
937 extern size_t size_from_real_kind (int);
938 internal_proto(size_from_real_kind);
940 extern size_t size_from_complex_kind (int);
941 internal_proto(size_from_complex_kind);
944 /* lock.c */
945 extern void free_ionml (st_parameter_dt *);
946 internal_proto(free_ionml);
948 static inline void
949 inc_waiting_locked (gfc_unit *u)
951 #ifdef HAVE_SYNC_FETCH_AND_ADD
952 (void) __sync_fetch_and_add (&u->waiting, 1);
953 #else
954 u->waiting++;
955 #endif
958 static inline int
959 predec_waiting_locked (gfc_unit *u)
961 #ifdef HAVE_SYNC_FETCH_AND_ADD
962 return __sync_add_and_fetch (&u->waiting, -1);
963 #else
964 return --u->waiting;
965 #endif
968 static inline void
969 dec_waiting_unlocked (gfc_unit *u)
971 #ifdef HAVE_SYNC_FETCH_AND_ADD
972 (void) __sync_fetch_and_add (&u->waiting, -1);
973 #else
974 __gthread_mutex_lock (&unit_lock);
975 u->waiting--;
976 __gthread_mutex_unlock (&unit_lock);
977 #endif
981 static inline void
982 memset4 (gfc_char4_t *p, gfc_char4_t c, int k)
984 int j;
985 for (j = 0; j < k; j++)
986 *p++ = c;
989 #endif