unix.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
  2. Contributed by Janne Blomqvist
  3. This file is part of the GNU Fortran runtime library (libgfortran).
  4. Libgfortran is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. Libgfortran is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef GFOR_UNIX_H
  20. #define GFOR_UNIX_H
  21. #include "io.h"
  22. struct stream_vtable
  23. {
  24. ssize_t (* const read) (struct stream *, void *, ssize_t);
  25. ssize_t (* const write) (struct stream *, const void *, ssize_t);
  26. gfc_offset (* const seek) (struct stream *, gfc_offset, int);
  27. gfc_offset (* const tell) (struct stream *);
  28. gfc_offset (* const size) (struct stream *);
  29. /* Avoid keyword truncate due to AIX namespace collision. */
  30. int (* const trunc) (struct stream *, gfc_offset);
  31. int (* const flush) (struct stream *);
  32. int (* const close) (struct stream *);
  33. int (* const markeor) (struct stream *);
  34. };
  35. struct stream
  36. {
  37. const struct stream_vtable *vptr;
  38. };
  39. /* Inline functions for doing file I/O given a stream. */
  40. static inline ssize_t
  41. sread (stream * s, void * buf, ssize_t nbyte)
  42. {
  43. return s->vptr->read (s, buf, nbyte);
  44. }
  45. static inline ssize_t
  46. swrite (stream * s, const void * buf, ssize_t nbyte)
  47. {
  48. return s->vptr->write (s, buf, nbyte);
  49. }
  50. static inline gfc_offset
  51. sseek (stream * s, gfc_offset offset, int whence)
  52. {
  53. return s->vptr->seek (s, offset, whence);
  54. }
  55. static inline gfc_offset
  56. stell (stream * s)
  57. {
  58. return s->vptr->tell (s);
  59. }
  60. static inline gfc_offset
  61. ssize (stream * s)
  62. {
  63. return s->vptr->size (s);
  64. }
  65. static inline int
  66. struncate (stream * s, gfc_offset length)
  67. {
  68. return s->vptr->trunc (s, length);
  69. }
  70. static inline int
  71. sflush (stream * s)
  72. {
  73. return s->vptr->flush (s);
  74. }
  75. static inline int
  76. sclose (stream * s)
  77. {
  78. return s->vptr->close (s);
  79. }
  80. static inline int
  81. smarkeor (stream * s)
  82. {
  83. return s->vptr->markeor (s);
  84. }
  85. extern int compare_files (stream *, stream *);
  86. internal_proto(compare_files);
  87. extern stream *open_external (st_parameter_open *, unit_flags *);
  88. internal_proto(open_external);
  89. extern stream *open_internal (char *, int, gfc_offset);
  90. internal_proto(open_internal);
  91. extern stream *open_internal4 (char *, int, gfc_offset);
  92. internal_proto(open_internal4);
  93. extern char * mem_alloc_w (stream *, int *);
  94. internal_proto(mem_alloc_w);
  95. extern char * mem_alloc_r (stream *, int *);
  96. internal_proto(mem_alloc_r);
  97. extern gfc_char4_t * mem_alloc_w4 (stream *, int *);
  98. internal_proto(mem_alloc_w4);
  99. extern char * mem_alloc_r4 (stream *, int *);
  100. internal_proto(mem_alloc_r4);
  101. extern stream *input_stream (void);
  102. internal_proto(input_stream);
  103. extern stream *output_stream (void);
  104. internal_proto(output_stream);
  105. extern stream *error_stream (void);
  106. internal_proto(error_stream);
  107. extern int compare_file_filename (gfc_unit *, const char *, int);
  108. internal_proto(compare_file_filename);
  109. extern gfc_unit *find_file (const char *file, gfc_charlen_type file_len);
  110. internal_proto(find_file);
  111. extern int delete_file (gfc_unit *);
  112. internal_proto(delete_file);
  113. extern int file_exists (const char *file, gfc_charlen_type file_len);
  114. internal_proto(file_exists);
  115. extern GFC_IO_INT file_size (const char *file, gfc_charlen_type file_len);
  116. internal_proto(file_size);
  117. extern const char *inquire_sequential (const char *, int);
  118. internal_proto(inquire_sequential);
  119. extern const char *inquire_direct (const char *, int);
  120. internal_proto(inquire_direct);
  121. extern const char *inquire_formatted (const char *, int);
  122. internal_proto(inquire_formatted);
  123. extern const char *inquire_unformatted (const char *, int);
  124. internal_proto(inquire_unformatted);
  125. extern const char *inquire_read (const char *, int);
  126. internal_proto(inquire_read);
  127. extern const char *inquire_write (const char *, int);
  128. internal_proto(inquire_write);
  129. extern const char *inquire_readwrite (const char *, int);
  130. internal_proto(inquire_readwrite);
  131. extern void flush_if_preconnected (stream *);
  132. internal_proto(flush_if_preconnected);
  133. extern int stream_isatty (stream *);
  134. internal_proto(stream_isatty);
  135. #ifndef TTY_NAME_MAX
  136. #ifdef _POSIX_TTY_NAME_MAX
  137. #define TTY_NAME_MAX _POSIX_TTY_NAME_MAX
  138. #else
  139. /* sysconf(_SC_TTY_NAME_MAX) = 32 which should be enough. */
  140. #define TTY_NAME_MAX 32
  141. #endif
  142. #endif
  143. extern int stream_ttyname (stream *, char *, size_t);
  144. internal_proto(stream_ttyname);
  145. #endif