Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
io.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  rubyio.h -
4 
5  $Author$
6  created at: Fri Nov 12 16:47:09 JST 1993
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9 
10 **********************************************************************/
11 
12 #ifndef RUBY_IO_H
13 #define RUBY_IO_H 1
14 
15 #ifdef RUBY_INTERNAL_H
16 #error "Include this file before internal.h"
17 #endif
18 
19 #if defined(__cplusplus)
20 extern "C" {
21 #if 0
22 } /* satisfy cc-mode */
23 #endif
24 #endif
25 
26 #include <stdio.h>
27 #include "ruby/encoding.h"
28 
29 #if defined(HAVE_STDIO_EXT_H)
30 #include <stdio_ext.h>
31 #endif
32 
33 #include "ruby/config.h"
34 #include <errno.h>
35 #if defined(HAVE_POLL)
36 # ifdef _AIX
37 # define reqevents events
38 # define rtnevents revents
39 # endif
40 # include <poll.h>
41 # ifdef _AIX
42 # undef reqevents
43 # undef rtnevents
44 # undef events
45 # undef revents
46 # endif
47 # define RB_WAITFD_IN POLLIN
48 # define RB_WAITFD_PRI POLLPRI
49 # define RB_WAITFD_OUT POLLOUT
50 #else
51 # define RB_WAITFD_IN 0x001
52 # define RB_WAITFD_PRI 0x002
53 # define RB_WAITFD_OUT 0x004
54 #endif
55 
57 
59  char *ptr; /* off + len <= capa */
60  int off;
61  int len;
62  int capa;
63 });
65 
66 typedef struct rb_io_t {
67  FILE *stdio_file; /* stdio ptr for read/write if available */
68  int fd; /* file descriptor */
69  int mode; /* mode flags: FMODE_XXXs */
70  rb_pid_t pid; /* child's pid (for pipes) */
71  int lineno; /* number of lines read */
72  VALUE pathv; /* pathname for file */
73  void (*finalize)(struct rb_io_t*,int); /* finalize proc */
74 
76 
78 
79  /*
80  * enc enc2 read action write action
81  * NULL NULL force_encoding(default_external) write the byte sequence of str
82  * e1 NULL force_encoding(e1) convert str.encoding to e1
83  * e1 e2 convert from e2 to e1 convert str.encoding to e2
84  */
85  struct rb_io_enc_t {
88  int ecflags;
90  } encs;
91 
94 
100 
102 } rb_io_t;
103 
104 typedef struct rb_io_enc_t rb_io_enc_t;
105 
106 #define HAVE_RB_IO_T 1
107 
108 #define FMODE_READABLE 0x00000001
109 #define FMODE_WRITABLE 0x00000002
110 #define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)
111 #define FMODE_BINMODE 0x00000004
112 #define FMODE_SYNC 0x00000008
113 #define FMODE_TTY 0x00000010
114 #define FMODE_DUPLEX 0x00000020
115 #define FMODE_APPEND 0x00000040
116 #define FMODE_CREATE 0x00000080
117 /* #define FMODE_NOREVLOOKUP 0x00000100 */
118 #define FMODE_EXCL 0x00000400
119 #define FMODE_TRUNC 0x00000800
120 #define FMODE_TEXTMODE 0x00001000
121 /* #define FMODE_PREP 0x00010000 */
122 #define FMODE_SETENC_BY_BOM 0x00100000
123 /* #define FMODE_UNIX 0x00200000 */
124 /* #define FMODE_INET 0x00400000 */
125 /* #define FMODE_INET6 0x00800000 */
126 
127 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
128 
129 #define MakeOpenFile(obj, fp) do {\
130  (fp) = rb_io_make_open_file(obj);\
131 } while (0)
132 
134 
136 
137 FILE *rb_fdopen(int, const char*);
138 int rb_io_modestr_fmode(const char *modestr);
139 int rb_io_modestr_oflags(const char *modestr);
140 CONSTFUNC(int rb_io_oflags_fmode(int oflags));
153 int rb_io_wait_readable(int);
154 int rb_io_wait_writable(int);
155 int rb_wait_for_single_fd(int fd, int events, struct timeval *tv);
156 void rb_io_set_nonblock(rb_io_t *fptr);
157 int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p);
158 void rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, rb_io_enc_t *convconfig_p);
159 ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
160 
161 /* compatibility for ruby 1.8 and older */
162 #define rb_io_mode_flags(modestr) [<"rb_io_mode_flags() is obsolete; use rb_io_modestr_fmode()">]
163 #define rb_io_modenum_flags(oflags) [<"rb_io_modenum_flags() is obsolete; use rb_io_oflags_fmode()">]
164 
166 NORETURN(void rb_eof_error(void));
167 
170 
171 struct stat;
172 VALUE rb_stat_new(const struct stat *);
173 
174 /* gc.c */
175 
177 
178 #if defined(__cplusplus)
179 #if 0
180 { /* satisfy cc-mode */
181 #endif
182 } /* extern "C" { */
183 #endif
184 
185 #endif /* RUBY_IO_H */
rb_io_t::writeconv_pre_ecopts
VALUE writeconv_pre_ecopts
Definition: io.h:99
RUBY_SYMBOL_EXPORT_END
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.1.h:5703
stat
Definition: rb_mjit_min_header-2.7.1.h:2352
rb_io_t::writeconv_initialized
int writeconv_initialized
Definition: io.h:97
rb_io_t::write_lock
VALUE write_lock
Definition: io.h:101
rb_io_oflags_fmode
int rb_io_oflags_fmode(int oflags)
Definition: io.c:5519
rb_io_read_check
void rb_io_read_check(rb_io_t *)
Definition: io.c:944
rb_io_t::pathv
VALUE pathv
Definition: io.h:72
rb_io_buffer_t
struct rb_io_buffer_t rb_io_buffer_t
Definition: io.h:64
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_io_t::finalize
void(* finalize)(struct rb_io_t *, int)
Definition: io.h:73
encoding.h
rb_io_t::wbuf
rb_io_buffer_t wbuf
Definition: io.h:75
rb_io_make_open_file
rb_io_t * rb_io_make_open_file(VALUE obj)
Definition: io.c:8080
rb_io_check_closed
void rb_io_check_closed(rb_io_t *)
Definition: io.c:718
rb_econv_t
Definition: transcode.c:111
ptr
struct RIMemo * ptr
Definition: debug.c:74
rb_io_enc_t
struct rb_io_enc_t rb_io_enc_t
Definition: io.h:104
rb_io_fptr_finalize
int rb_io_fptr_finalize(rb_io_t *)
Definition: io.c:4747
rb_io_taint_check
VALUE rb_io_taint_check(VALUE)
Definition: io.c:703
rb_io_t::fd
int fd
Definition: io.h:68
rb_io_t::rbuf
rb_io_buffer_t rbuf
Definition: io.h:75
rb_pid_t
#define rb_pid_t
Definition: rb_mjit_min_header-2.7.1.h:99
rb_eof_error
void rb_eof_error(void)
Definition: io.c:697
rb_io_t::pid
rb_pid_t pid
Definition: io.h:70
rb_io_t::rb_io_enc_t::ecflags
int ecflags
Definition: io.h:88
rb_io_stdio_file
FILE * rb_io_stdio_file(rb_io_t *fptr)
Definition: io.c:8032
rb_io_check_io
VALUE rb_io_check_io(VALUE io)
Definition: io.c:739
rb_io_extract_modeenc
void rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, rb_io_enc_t *convconfig_p)
Definition: io.c:5871
void
void
Definition: rb_mjit_min_header-2.7.1.h:13198
rb_io_check_initialized
void rb_io_check_initialized(rb_io_t *)
Definition: io.c:710
rb_encoding
const typedef OnigEncodingType rb_encoding
Definition: encoding.h:115
rb_io_t::writeconv
rb_econv_t * writeconv
Definition: io.h:95
PACKED_STRUCT_UNALIGNED
RUBY_SYMBOL_EXPORT_BEGIN PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t { char *ptr;int off;int len;int capa;})
rb_io_t::readconv
rb_econv_t * readconv
Definition: io.h:92
rb_io_t::cbuf
rb_io_buffer_t cbuf
Definition: io.h:93
rb_io_t
struct rb_io_t rb_io_t
rb_io_get_write_io
VALUE rb_io_get_write_io(VALUE io)
Definition: io.c:745
rb_fdopen
FILE * rb_fdopen(int, const char *)
Definition: io.c:6053
NORETURN
NORETURN(void rb_eof_error(void))
size
int size
Definition: encoding.c:58
rb_io_get_io
VALUE rb_io_get_io(VALUE io)
Definition: io.c:733
rb_io_check_readable
void rb_io_check_readable(rb_io_t *)
Definition: io.c:899
rb_io_check_char_readable
void rb_io_check_char_readable(rb_io_t *fptr)
Definition: io.c:871
rb_io_t::writeconv_asciicompat
VALUE writeconv_asciicompat
Definition: io.h:96
rb_io_t::lineno
int lineno
Definition: io.h:71
CONSTFUNC
CONSTFUNC(int rb_io_oflags_fmode(int oflags))
rb_io_set_write_io
VALUE rb_io_set_write_io(VALUE io, VALUE w)
Definition: io.c:756
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4322
rb_io_t::rb_io_enc_t::ecopts
VALUE ecopts
Definition: io.h:89
rb_io_t::mode
int mode
Definition: io.h:69
RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
rb_io_extract_encoding_option
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
Definition: io.c:5744
rb_io_check_byte_readable
void rb_io_check_byte_readable(rb_io_t *fptr)
Definition: io.c:890
timeval
Definition: missing.h:53
ssize_t
_ssize_t ssize_t
Definition: rb_mjit_min_header-2.7.1.h:1324
rb_io_t::stdio_file
FILE * stdio_file
Definition: io.h:67
rb_wait_for_single_fd
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: thread.c:4276
rb_io_check_writable
void rb_io_check_writable(rb_io_t *)
Definition: io.c:923
rb_io_modestr_fmode
int rb_io_modestr_fmode(const char *modestr)
Definition: io.c:5465
int
__inline__ int
Definition: rb_mjit_min_header-2.7.1.h:2807
rb_io_set_nonblock
void rb_io_set_nonblock(rb_io_t *fptr)
Definition: io.c:2782
rb_io_t::rb_io_enc_t
Definition: io.h:85
rb_io_t::rb_io_enc_t::enc
rb_encoding * enc
Definition: io.h:86
rb_io_wait_readable
int rb_io_wait_readable(int)
Definition: io.c:1204
len
uint8_t len
Definition: escape.c:17
rb_io_t::tied_io_for_writing
VALUE tied_io_for_writing
Definition: io.h:77
rb_io_read_pending
int rb_io_read_pending(rb_io_t *)
Definition: io.c:935
rb_io_t::encs
struct rb_io_t::rb_io_enc_t encs
rb_io_bufwrite
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size)
Definition: io.c:1549
rb_io_t
Definition: io.h:66
rb_io_t::rb_io_enc_t::enc2
rb_encoding * enc2
Definition: io.h:87
rb_io_t::writeconv_pre_ecflags
int writeconv_pre_ecflags
Definition: io.h:98
rb_io_synchronized
void rb_io_synchronized(rb_io_t *)
Definition: io.c:6356
__sFILE
Definition: vsnprintf.c:169
rb_io_wait_writable
int rb_io_wait_writable(int)
Definition: io.c:1228
rb_stat_new
VALUE rb_stat_new(const struct stat *)
Definition: file.c:492
rb_io_modestr_oflags
int rb_io_modestr_oflags(const char *modestr)
Definition: io.c:5595