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