re PR fortran/31199 (write with "t1" + nonadvancing transfer format gives wrong output)
[gcc.git] / libgfortran / io / io.h
1 /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
2 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
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 2, or (at your option)
10 any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with Libgfortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
28
29 #ifndef GFOR_IO_H
30 #define GFOR_IO_H
31
32 /* IO library include. */
33
34 #include <setjmp.h>
35 #include "libgfortran.h"
36
37 #include <gthr.h>
38
39 /* Basic types used in data transfers. */
40
41 typedef enum
42 { BT_NULL, BT_INTEGER, BT_LOGICAL, BT_CHARACTER, BT_REAL,
43 BT_COMPLEX
44 }
45 bt;
46
47
48 struct st_parameter_dt;
49
50 typedef struct stream
51 {
52 char *(*alloc_w_at) (struct stream *, int *, gfc_offset);
53 char *(*alloc_r_at) (struct stream *, int *, gfc_offset);
54 try (*sfree) (struct stream *);
55 try (*close) (struct stream *);
56 try (*seek) (struct stream *, gfc_offset);
57 try (*truncate) (struct stream *);
58 int (*read) (struct stream *, void *, size_t *);
59 int (*write) (struct stream *, const void *, size_t *);
60 try (*set) (struct stream *, int, size_t);
61 }
62 stream;
63
64
65 /* Macros for doing file I/O given a stream. */
66
67 #define sfree(s) ((s)->sfree)(s)
68 #define sclose(s) ((s)->close)(s)
69
70 #define salloc_r(s, len) ((s)->alloc_r_at)(s, len, -1)
71 #define salloc_w(s, len) ((s)->alloc_w_at)(s, len, -1)
72
73 #define salloc_r_at(s, len, where) ((s)->alloc_r_at)(s, len, where)
74 #define salloc_w_at(s, len, where) ((s)->alloc_w_at)(s, len, where)
75
76 #define sseek(s, pos) ((s)->seek)(s, pos)
77 #define struncate(s) ((s)->truncate)(s)
78 #define sread(s, buf, nbytes) ((s)->read)(s, buf, nbytes)
79 #define swrite(s, buf, nbytes) ((s)->write)(s, buf, nbytes)
80
81 #define sset(s, c, n) ((s)->set)(s, c, n)
82
83 /* The array_loop_spec contains the variables for the loops over index ranges
84 that are encountered. Since the variables can be negative, ssize_t
85 is used. */
86
87 typedef struct array_loop_spec
88 {
89 /* Index counter for this dimension. */
90 ssize_t idx;
91
92 /* Start for the index counter. */
93 ssize_t start;
94
95 /* End for the index counter. */
96 ssize_t end;
97
98 /* Step for the index counter. */
99 ssize_t step;
100 }
101 array_loop_spec;
102
103 /* Representation of a namelist object in libgfortran
104
105 Namelist Records
106 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]].../
107 or
108 &GROUPNAME OBJECT=value[s] [,OBJECT=value[s]]...&END
109
110 The object can be a fully qualified, compound name for an intrinsic
111 type, derived types or derived type components. So, a substring
112 a(:)%b(4)%ch(2:4)(1:7) has to be treated correctly in namelist
113 read. Hence full information about the structure of the object has
114 to be available to list_read.c and write.
115
116 These requirements are met by the following data structures.
117
118 namelist_info type contains all the scalar information about the
119 object and arrays of descriptor_dimension and array_loop_spec types for
120 arrays. */
121
122 typedef struct namelist_type
123 {
124
125 /* Object type, stored as GFC_DTYPE_xxxx. */
126 bt type;
127
128 /* Object name. */
129 char * var_name;
130
131 /* Address for the start of the object's data. */
132 void * mem_pos;
133
134 /* Flag to show that a read is to be attempted for this node. */
135 int touched;
136
137 /* Length of intrinsic type in bytes. */
138 int len;
139
140 /* Rank of the object. */
141 int var_rank;
142
143 /* Overall size of the object in bytes. */
144 index_type size;
145
146 /* Length of character string. */
147 index_type string_length;
148
149 descriptor_dimension * dim;
150 array_loop_spec * ls;
151 struct namelist_type * next;
152 }
153 namelist_info;
154
155 /* Options for the OPEN statement. */
156
157 typedef enum
158 { ACCESS_SEQUENTIAL, ACCESS_DIRECT, ACCESS_APPEND, ACCESS_STREAM,
159 ACCESS_UNSPECIFIED
160 }
161 unit_access;
162
163 typedef enum
164 { ACTION_READ, ACTION_WRITE, ACTION_READWRITE,
165 ACTION_UNSPECIFIED
166 }
167 unit_action;
168
169 typedef enum
170 { BLANK_NULL, BLANK_ZERO, BLANK_UNSPECIFIED }
171 unit_blank;
172
173 typedef enum
174 { DELIM_NONE, DELIM_APOSTROPHE, DELIM_QUOTE,
175 DELIM_UNSPECIFIED
176 }
177 unit_delim;
178
179 typedef enum
180 { FORM_FORMATTED, FORM_UNFORMATTED, FORM_UNSPECIFIED }
181 unit_form;
182
183 typedef enum
184 { POSITION_ASIS, POSITION_REWIND, POSITION_APPEND,
185 POSITION_UNSPECIFIED
186 }
187 unit_position;
188
189 typedef enum
190 { STATUS_UNKNOWN, STATUS_OLD, STATUS_NEW, STATUS_SCRATCH,
191 STATUS_REPLACE, STATUS_UNSPECIFIED
192 }
193 unit_status;
194
195 typedef enum
196 { PAD_YES, PAD_NO, PAD_UNSPECIFIED }
197 unit_pad;
198
199 typedef enum
200 { ADVANCE_YES, ADVANCE_NO, ADVANCE_UNSPECIFIED }
201 unit_advance;
202
203 typedef enum
204 {READING, WRITING}
205 unit_mode;
206
207 #define CHARACTER1(name) \
208 char * name; \
209 gfc_charlen_type name ## _len
210 #define CHARACTER2(name) \
211 gfc_charlen_type name ## _len; \
212 char * name
213
214 typedef struct
215 {
216 st_parameter_common common;
217 GFC_INTEGER_4 recl_in;
218 CHARACTER2 (file);
219 CHARACTER1 (status);
220 CHARACTER2 (access);
221 CHARACTER1 (form);
222 CHARACTER2 (blank);
223 CHARACTER1 (position);
224 CHARACTER2 (action);
225 CHARACTER1 (delim);
226 CHARACTER2 (pad);
227 CHARACTER1 (convert);
228 }
229 st_parameter_open;
230
231 #define IOPARM_CLOSE_HAS_STATUS (1 << 7)
232
233 typedef struct
234 {
235 st_parameter_common common;
236 CHARACTER1 (status);
237 }
238 st_parameter_close;
239
240 typedef struct
241 {
242 st_parameter_common common;
243 }
244 st_parameter_filepos;
245
246 #define IOPARM_INQUIRE_HAS_EXIST (1 << 7)
247 #define IOPARM_INQUIRE_HAS_OPENED (1 << 8)
248 #define IOPARM_INQUIRE_HAS_NUMBER (1 << 9)
249 #define IOPARM_INQUIRE_HAS_NAMED (1 << 10)
250 #define IOPARM_INQUIRE_HAS_NEXTREC (1 << 11)
251 #define IOPARM_INQUIRE_HAS_RECL_OUT (1 << 12)
252 #define IOPARM_INQUIRE_HAS_STRM_POS_OUT (1 << 13)
253 #define IOPARM_INQUIRE_HAS_FILE (1 << 14)
254 #define IOPARM_INQUIRE_HAS_ACCESS (1 << 15)
255 #define IOPARM_INQUIRE_HAS_FORM (1 << 16)
256 #define IOPARM_INQUIRE_HAS_BLANK (1 << 17)
257 #define IOPARM_INQUIRE_HAS_POSITION (1 << 18)
258 #define IOPARM_INQUIRE_HAS_ACTION (1 << 19)
259 #define IOPARM_INQUIRE_HAS_DELIM (1 << 20)
260 #define IOPARM_INQUIRE_HAS_PAD (1 << 21)
261 #define IOPARM_INQUIRE_HAS_NAME (1 << 22)
262 #define IOPARM_INQUIRE_HAS_SEQUENTIAL (1 << 23)
263 #define IOPARM_INQUIRE_HAS_DIRECT (1 << 24)
264 #define IOPARM_INQUIRE_HAS_FORMATTED (1 << 25)
265 #define IOPARM_INQUIRE_HAS_UNFORMATTED (1 << 26)
266 #define IOPARM_INQUIRE_HAS_READ (1 << 27)
267 #define IOPARM_INQUIRE_HAS_WRITE (1 << 28)
268 #define IOPARM_INQUIRE_HAS_READWRITE (1 << 29)
269 #define IOPARM_INQUIRE_HAS_CONVERT (1 << 30)
270
271 typedef struct
272 {
273 st_parameter_common common;
274 GFC_INTEGER_4 *exist, *opened, *number, *named;
275 GFC_INTEGER_4 *nextrec, *recl_out;
276 GFC_IO_INT *strm_pos_out;
277 CHARACTER1 (file);
278 CHARACTER2 (access);
279 CHARACTER1 (form);
280 CHARACTER2 (blank);
281 CHARACTER1 (position);
282 CHARACTER2 (action);
283 CHARACTER1 (delim);
284 CHARACTER2 (pad);
285 CHARACTER1 (name);
286 CHARACTER2 (sequential);
287 CHARACTER1 (direct);
288 CHARACTER2 (formatted);
289 CHARACTER1 (unformatted);
290 CHARACTER2 (read);
291 CHARACTER1 (write);
292 CHARACTER2 (readwrite);
293 CHARACTER1 (convert);
294 }
295 st_parameter_inquire;
296
297 struct gfc_unit;
298 struct format_data;
299
300 #define IOPARM_DT_LIST_FORMAT (1 << 7)
301 #define IOPARM_DT_NAMELIST_READ_MODE (1 << 8)
302 #define IOPARM_DT_HAS_REC (1 << 9)
303 #define IOPARM_DT_HAS_SIZE (1 << 10)
304 #define IOPARM_DT_HAS_IOLENGTH (1 << 11)
305 #define IOPARM_DT_HAS_FORMAT (1 << 12)
306 #define IOPARM_DT_HAS_ADVANCE (1 << 13)
307 #define IOPARM_DT_HAS_INTERNAL_UNIT (1 << 14)
308 #define IOPARM_DT_HAS_NAMELIST_NAME (1 << 15)
309 /* Internal use bit. */
310 #define IOPARM_DT_IONML_SET (1 << 31)
311
312 typedef struct st_parameter_dt
313 {
314 st_parameter_common common;
315 GFC_IO_INT rec;
316 GFC_IO_INT *size, *iolength;
317 gfc_array_char *internal_unit_desc;
318 CHARACTER1 (format);
319 CHARACTER2 (advance);
320 CHARACTER1 (internal_unit);
321 CHARACTER2 (namelist_name);
322 /* Private part of the structure. The compiler just needs
323 to reserve enough space. */
324 union
325 {
326 struct
327 {
328 void (*transfer) (struct st_parameter_dt *, bt, void *, int,
329 size_t, size_t);
330 struct gfc_unit *current_unit;
331 /* Item number in a formatted data transfer. Also used in namelist
332 read_logical as an index into line_buffer. */
333 int item_count;
334 unit_mode mode;
335 unit_blank blank_status;
336 enum {SIGN_S, SIGN_SS, SIGN_SP} sign_status;
337 int scale_factor;
338 int max_pos; /* Maximum righthand column written to. */
339 /* Number of skips + spaces to be done for T and X-editing. */
340 int skips;
341 /* Number of spaces to be done for T and X-editing. */
342 int pending_spaces;
343 /* Whether an EOR condition was encountered. Value is:
344 0 if no EOR was encountered
345 1 if an EOR was encountered due to a 1-byte marker (LF)
346 2 if an EOR was encountered due to a 2-bytes marker (CRLF) */
347 int sf_seen_eor;
348 unit_advance advance_status;
349
350 unsigned reversion_flag : 1; /* Format reversion has occurred. */
351 unsigned first_item : 1;
352 unsigned seen_dollar : 1;
353 unsigned eor_condition : 1;
354 unsigned no_leading_blank : 1;
355 unsigned char_flag : 1;
356 unsigned input_complete : 1;
357 unsigned at_eol : 1;
358 unsigned comma_flag : 1;
359 /* A namelist specific flag used in the list directed library
360 to flag that calls are being made from namelist read (eg. to
361 ignore comments or to treat '/' as a terminator) */
362 unsigned namelist_mode : 1;
363 /* A namelist specific flag used in the list directed library
364 to flag read errors and return, so that an attempt can be
365 made to read a new object name. */
366 unsigned nml_read_error : 1;
367 /* A sequential formatted read specific flag used to signal that a
368 character string is being read so don't use commas to shorten a
369 formatted field width. */
370 unsigned sf_read_comma : 1;
371 /* A namelist specific flag used to enable reading input from
372 line_buffer for logical reads. */
373 unsigned line_buffer_enabled : 1;
374 /* An internal unit specific flag used to identify that the associated
375 unit is internal. */
376 unsigned unit_is_internal : 1;
377 /* An internal unit specific flag to signify an EOF condition for list
378 directed read. */
379 unsigned at_eof : 1;
380 /* 16 unused bits. */
381
382 char last_char;
383 char nml_delim;
384
385 int repeat_count;
386 int saved_length;
387 int saved_used;
388 bt saved_type;
389 char *saved_string;
390 char *scratch;
391 char *line_buffer;
392 struct format_data *fmt;
393 jmp_buf *eof_jump;
394 namelist_info *ionml;
395 /* A flag used to identify when a non-standard expanded namelist read
396 has occurred. */
397 int expanded_read;
398 /* Storage area for values except for strings. Must be large
399 enough to hold a complex value (two reals) of the largest
400 kind. */
401 char value[32];
402 gfc_offset size_used;
403 } p;
404 /* This pad size must be equal to the pad_size declared in
405 trans-io.c (gfc_build_io_library_fndecls). The above structure
406 must be smaller or equal to this array. */
407 char pad[16 * sizeof (char *) + 32 * sizeof (int)];
408 } u;
409 }
410 st_parameter_dt;
411
412 /* Ensure st_parameter_dt's u.pad is bigger or equal to u.p. */
413 extern char check_st_parameter_dt[sizeof (((st_parameter_dt *) 0)->u.pad)
414 >= sizeof (((st_parameter_dt *) 0)->u.p)
415 ? 1 : -1];
416
417 #undef CHARACTER1
418 #undef CHARACTER2
419
420 typedef struct
421 {
422 unit_access access;
423 unit_action action;
424 unit_blank blank;
425 unit_delim delim;
426 unit_form form;
427 int is_notpadded;
428 unit_position position;
429 unit_status status;
430 unit_pad pad;
431 unit_convert convert;
432 int has_recl;
433 }
434 unit_flags;
435
436
437 typedef struct gfc_unit
438 {
439 int unit_number;
440 stream *s;
441
442 /* Treap links. */
443 struct gfc_unit *left, *right;
444 int priority;
445
446 int read_bad, current_record, saved_pos;
447 enum
448 { NO_ENDFILE, AT_ENDFILE, AFTER_ENDFILE }
449 endfile;
450
451 unit_mode mode;
452 unit_flags flags;
453
454 /* recl -- Record length of the file.
455 last_record -- Last record number read or written
456 maxrec -- Maximum record number in a direct access file
457 bytes_left -- Bytes left in current record.
458 strm_pos -- Current position in file for STREAM I/O.
459 recl_subrecord -- Maximum length for subrecord.
460 bytes_left_subrecord -- Bytes left in current subrecord. */
461 gfc_offset recl, last_record, maxrec, bytes_left, strm_pos,
462 recl_subrecord, bytes_left_subrecord;
463
464 /* Set to 1 if we have read a subrecord. */
465
466 int continued;
467
468 __gthread_mutex_t lock;
469 /* Number of threads waiting to acquire this unit's lock.
470 When non-zero, close_unit doesn't only removes the unit
471 from the UNIT_ROOT tree, but doesn't free it and the
472 last of the waiting threads will do that.
473 This must be either atomically increased/decreased, or
474 always guarded by UNIT_LOCK. */
475 int waiting;
476 /* Flag set by close_unit if the unit as been closed.
477 Must be manipulated under unit's lock. */
478 int closed;
479
480 /* For traversing arrays */
481 array_loop_spec *ls;
482 int rank;
483
484 int file_len;
485 char *file;
486 }
487 gfc_unit;
488
489 /* Format tokens. Only about half of these can be stored in the
490 format nodes. */
491
492 typedef enum
493 {
494 FMT_NONE = 0, FMT_UNKNOWN, FMT_SIGNED_INT, FMT_ZERO, FMT_POSINT, FMT_PERIOD,
495 FMT_COMMA, FMT_COLON, FMT_SLASH, FMT_DOLLAR, FMT_T, FMT_TR, FMT_TL,
496 FMT_LPAREN, FMT_RPAREN, FMT_X, FMT_S, FMT_SS, FMT_SP, FMT_STRING,
497 FMT_BADSTRING, FMT_P, FMT_I, FMT_B, FMT_BN, FMT_BZ, FMT_O, FMT_Z, FMT_F,
498 FMT_E, FMT_EN, FMT_ES, FMT_G, FMT_L, FMT_A, FMT_D, FMT_H, FMT_END
499 }
500 format_token;
501
502
503 /* Format nodes. A format string is converted into a tree of these
504 structures, which is traversed as part of a data transfer statement. */
505
506 typedef struct fnode
507 {
508 format_token format;
509 int repeat;
510 struct fnode *next;
511 char *source;
512
513 union
514 {
515 struct
516 {
517 int w, d, e;
518 }
519 real;
520
521 struct
522 {
523 int length;
524 char *p;
525 }
526 string;
527
528 struct
529 {
530 int w, m;
531 }
532 integer;
533
534 int w;
535 int k;
536 int r;
537 int n;
538
539 struct fnode *child;
540 }
541 u;
542
543 /* Members for traversing the tree during data transfer. */
544
545 int count;
546 struct fnode *current;
547
548 }
549 fnode;
550
551
552 /* unix.c */
553
554 extern int move_pos_offset (stream *, int);
555 internal_proto(move_pos_offset);
556
557 extern int compare_files (stream *, stream *);
558 internal_proto(compare_files);
559
560 extern stream *open_external (st_parameter_open *, unit_flags *);
561 internal_proto(open_external);
562
563 extern stream *open_internal (char *, int);
564 internal_proto(open_internal);
565
566 extern stream *input_stream (void);
567 internal_proto(input_stream);
568
569 extern stream *output_stream (void);
570 internal_proto(output_stream);
571
572 extern stream *error_stream (void);
573 internal_proto(error_stream);
574
575 extern int compare_file_filename (gfc_unit *, const char *, int);
576 internal_proto(compare_file_filename);
577
578 extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
579 internal_proto(find_file);
580
581 extern void flush_all_units (void);
582 internal_proto(flush_all_units);
583
584 extern int stream_at_bof (stream *);
585 internal_proto(stream_at_bof);
586
587 extern int stream_at_eof (stream *);
588 internal_proto(stream_at_eof);
589
590 extern int delete_file (gfc_unit *);
591 internal_proto(delete_file);
592
593 extern int file_exists (const char *file, gfc_charlen_type file_len);
594 internal_proto(file_exists);
595
596 extern const char *inquire_sequential (const char *, int);
597 internal_proto(inquire_sequential);
598
599 extern const char *inquire_direct (const char *, int);
600 internal_proto(inquire_direct);
601
602 extern const char *inquire_formatted (const char *, int);
603 internal_proto(inquire_formatted);
604
605 extern const char *inquire_unformatted (const char *, int);
606 internal_proto(inquire_unformatted);
607
608 extern const char *inquire_read (const char *, int);
609 internal_proto(inquire_read);
610
611 extern const char *inquire_write (const char *, int);
612 internal_proto(inquire_write);
613
614 extern const char *inquire_readwrite (const char *, int);
615 internal_proto(inquire_readwrite);
616
617 extern gfc_offset file_length (stream *);
618 internal_proto(file_length);
619
620 extern gfc_offset file_position (stream *);
621 internal_proto(file_position);
622
623 extern int is_seekable (stream *);
624 internal_proto(is_seekable);
625
626 extern int is_special (stream *);
627 internal_proto(is_special);
628
629 extern int is_preconnected (stream *);
630 internal_proto(is_preconnected);
631
632 extern void flush_if_preconnected (stream *);
633 internal_proto(flush_if_preconnected);
634
635 extern void empty_internal_buffer(stream *);
636 internal_proto(empty_internal_buffer);
637
638 extern try flush (stream *);
639 internal_proto(flush);
640
641 extern int stream_isatty (stream *);
642 internal_proto(stream_isatty);
643
644 extern char * stream_ttyname (stream *);
645 internal_proto(stream_ttyname);
646
647 extern gfc_offset stream_offset (stream *s);
648 internal_proto(stream_offset);
649
650 extern int unpack_filename (char *, const char *, int);
651 internal_proto(unpack_filename);
652
653 /* unit.c */
654
655 /* Maximum file offset, computed at library initialization time. */
656 extern gfc_offset max_offset;
657 internal_proto(max_offset);
658
659 /* Unit tree root. */
660 extern gfc_unit *unit_root;
661 internal_proto(unit_root);
662
663 extern __gthread_mutex_t unit_lock;
664 internal_proto(unit_lock);
665
666 extern int close_unit (gfc_unit *);
667 internal_proto(close_unit);
668
669 extern gfc_unit *get_internal_unit (st_parameter_dt *);
670 internal_proto(get_internal_unit);
671
672 extern void free_internal_unit (st_parameter_dt *);
673 internal_proto(free_internal_unit);
674
675 extern int is_internal_unit (st_parameter_dt *);
676 internal_proto(is_internal_unit);
677
678 extern int is_array_io (st_parameter_dt *);
679 internal_proto(is_array_io);
680
681 extern int is_stream_io (st_parameter_dt *);
682 internal_proto(is_stream_io);
683
684 extern gfc_unit *find_unit (int);
685 internal_proto(find_unit);
686
687 extern gfc_unit *find_or_create_unit (int);
688 internal_proto(find_or_create_unit);
689
690 extern gfc_unit *get_unit (st_parameter_dt *, int);
691 internal_proto(get_unit);
692
693 extern void unlock_unit (gfc_unit *);
694 internal_proto(unlock_unit);
695
696 /* open.c */
697
698 extern void test_endfile (gfc_unit *);
699 internal_proto(test_endfile);
700
701 extern gfc_unit *new_unit (st_parameter_open *, gfc_unit *, unit_flags *);
702 internal_proto(new_unit);
703
704 /* format.c */
705
706 extern void parse_format (st_parameter_dt *);
707 internal_proto(parse_format);
708
709 extern const fnode *next_format (st_parameter_dt *);
710 internal_proto(next_format);
711
712 extern void unget_format (st_parameter_dt *, const fnode *);
713 internal_proto(unget_format);
714
715 extern void format_error (st_parameter_dt *, const fnode *, const char *);
716 internal_proto(format_error);
717
718 extern void free_format_data (st_parameter_dt *);
719 internal_proto(free_format_data);
720
721 /* transfer.c */
722
723 #define SCRATCH_SIZE 300
724
725 extern const char *type_name (bt);
726 internal_proto(type_name);
727
728 extern void *read_block (st_parameter_dt *, int *);
729 internal_proto(read_block);
730
731 extern char *read_sf (st_parameter_dt *, int *, int);
732 internal_proto(read_sf);
733
734 extern void *write_block (st_parameter_dt *, int);
735 internal_proto(write_block);
736
737 extern gfc_offset next_array_record (st_parameter_dt *, array_loop_spec *);
738 internal_proto(next_array_record);
739
740 extern gfc_offset init_loop_spec (gfc_array_char *, array_loop_spec *);
741 internal_proto(init_loop_spec);
742
743 extern void next_record (st_parameter_dt *, int);
744 internal_proto(next_record);
745
746 extern void reverse_memcpy (void *, const void *, size_t);
747 internal_proto (reverse_memcpy);
748
749 /* read.c */
750
751 extern void set_integer (void *, GFC_INTEGER_LARGEST, int);
752 internal_proto(set_integer);
753
754 extern GFC_UINTEGER_LARGEST max_value (int, int);
755 internal_proto(max_value);
756
757 extern int convert_real (st_parameter_dt *, void *, const char *, int);
758 internal_proto(convert_real);
759
760 extern void read_a (st_parameter_dt *, const fnode *, char *, int);
761 internal_proto(read_a);
762
763 extern void read_f (st_parameter_dt *, const fnode *, char *, int);
764 internal_proto(read_f);
765
766 extern void read_l (st_parameter_dt *, const fnode *, char *, int);
767 internal_proto(read_l);
768
769 extern void read_x (st_parameter_dt *, int);
770 internal_proto(read_x);
771
772 extern void read_radix (st_parameter_dt *, const fnode *, char *, int, int);
773 internal_proto(read_radix);
774
775 extern void read_decimal (st_parameter_dt *, const fnode *, char *, int);
776 internal_proto(read_decimal);
777
778 /* list_read.c */
779
780 extern void list_formatted_read (st_parameter_dt *, bt, void *, int, size_t,
781 size_t);
782 internal_proto(list_formatted_read);
783
784 extern void finish_list_read (st_parameter_dt *);
785 internal_proto(finish_list_read);
786
787 extern void namelist_read (st_parameter_dt *);
788 internal_proto(namelist_read);
789
790 extern void namelist_write (st_parameter_dt *);
791 internal_proto(namelist_write);
792
793 /* write.c */
794
795 extern void write_a (st_parameter_dt *, const fnode *, const char *, int);
796 internal_proto(write_a);
797
798 extern void write_b (st_parameter_dt *, const fnode *, const char *, int);
799 internal_proto(write_b);
800
801 extern void write_d (st_parameter_dt *, const fnode *, const char *, int);
802 internal_proto(write_d);
803
804 extern void write_e (st_parameter_dt *, const fnode *, const char *, int);
805 internal_proto(write_e);
806
807 extern void write_en (st_parameter_dt *, const fnode *, const char *, int);
808 internal_proto(write_en);
809
810 extern void write_es (st_parameter_dt *, const fnode *, const char *, int);
811 internal_proto(write_es);
812
813 extern void write_f (st_parameter_dt *, const fnode *, const char *, int);
814 internal_proto(write_f);
815
816 extern void write_i (st_parameter_dt *, const fnode *, const char *, int);
817 internal_proto(write_i);
818
819 extern void write_l (st_parameter_dt *, const fnode *, char *, int);
820 internal_proto(write_l);
821
822 extern void write_o (st_parameter_dt *, const fnode *, const char *, int);
823 internal_proto(write_o);
824
825 extern void write_x (st_parameter_dt *, int, int);
826 internal_proto(write_x);
827
828 extern void write_z (st_parameter_dt *, const fnode *, const char *, int);
829 internal_proto(write_z);
830
831 extern void list_formatted_write (st_parameter_dt *, bt, void *, int, size_t,
832 size_t);
833 internal_proto(list_formatted_write);
834
835 /* size_from_kind.c */
836 extern size_t size_from_real_kind (int);
837 internal_proto(size_from_real_kind);
838
839 extern size_t size_from_complex_kind (int);
840 internal_proto(size_from_complex_kind);
841
842 /* lock.c */
843 extern void free_ionml (st_parameter_dt *);
844 internal_proto(free_ionml);
845
846 static inline void
847 inc_waiting_locked (gfc_unit *u)
848 {
849 #ifdef HAVE_SYNC_FETCH_AND_ADD
850 (void) __sync_fetch_and_add (&u->waiting, 1);
851 #else
852 u->waiting++;
853 #endif
854 }
855
856 static inline int
857 predec_waiting_locked (gfc_unit *u)
858 {
859 #ifdef HAVE_SYNC_FETCH_AND_ADD
860 return __sync_add_and_fetch (&u->waiting, -1);
861 #else
862 return --u->waiting;
863 #endif
864 }
865
866 static inline void
867 dec_waiting_unlocked (gfc_unit *u)
868 {
869 #ifdef HAVE_SYNC_FETCH_AND_ADD
870 (void) __sync_fetch_and_add (&u->waiting, -1);
871 #else
872 __gthread_mutex_lock (&unit_lock);
873 u->waiting--;
874 __gthread_mutex_unlock (&unit_lock);
875 #endif
876 }
877
878 #endif
879