Ruby  2.5.0dev(2017-10-22revision60238)
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 #if defined(__cplusplus)
16 extern "C" {
17 #if 0
18 } /* satisfy cc-mode */
19 #endif
20 #endif
21 
22 #include <stdio.h>
23 #include <errno.h>
24 #include "ruby/encoding.h"
25 
26 #if defined(HAVE_STDIO_EXT_H)
27 #include <stdio_ext.h>
28 #endif
29 
30 #include "ruby/config.h"
31 #if defined(HAVE_POLL)
32 # ifdef _AIX
33 # define reqevents events
34 # define rtnevents revents
35 # endif
36 # include <poll.h>
37 # ifdef _AIX
38 # undef reqevents
39 # undef rtnevents
40 # undef events
41 # undef revents
42 # endif
43 # define RB_WAITFD_IN POLLIN
44 # define RB_WAITFD_PRI POLLPRI
45 # define RB_WAITFD_OUT POLLOUT
46 #else
47 # define RB_WAITFD_IN 0x001
48 # define RB_WAITFD_PRI 0x002
49 # define RB_WAITFD_OUT 0x004
50 #endif
51 
53 
55  char *ptr; /* off + len <= capa */
56  int off;
57  int len;
58  int capa;
59 });
61 
62 typedef struct rb_io_t {
63  FILE *stdio_file; /* stdio ptr for read/write if available */
64  int fd; /* file descriptor */
65  int mode; /* mode flags: FMODE_XXXs */
66  rb_pid_t pid; /* child's pid (for pipes) */
67  int lineno; /* number of lines read */
68  VALUE pathv; /* pathname for file */
69  void (*finalize)(struct rb_io_t*,int); /* finalize proc */
70 
72 
74 
75  /*
76  * enc enc2 read action write action
77  * NULL NULL force_encoding(default_external) write the byte sequence of str
78  * e1 NULL force_encoding(e1) convert str.encoding to e1
79  * e1 e2 convert from e2 to e1 convert str.encoding to e2
80  */
81  struct rb_io_enc_t {
84  int ecflags;
86  } encs;
87 
90 
96 
98 } rb_io_t;
99 
100 #define HAVE_RB_IO_T 1
101 
102 #define FMODE_READABLE 0x00000001
103 #define FMODE_WRITABLE 0x00000002
104 #define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)
105 #define FMODE_BINMODE 0x00000004
106 #define FMODE_SYNC 0x00000008
107 #define FMODE_TTY 0x00000010
108 #define FMODE_DUPLEX 0x00000020
109 #define FMODE_APPEND 0x00000040
110 #define FMODE_CREATE 0x00000080
111 /* #define FMODE_NOREVLOOKUP 0x00000100 */
112 #define FMODE_TRUNC 0x00000800
113 #define FMODE_TEXTMODE 0x00001000
114 /* #define FMODE_PREP 0x00010000 */
115 #define FMODE_SETENC_BY_BOM 0x00100000
116 /* #define FMODE_UNIX 0x00200000 */
117 /* #define FMODE_INET 0x00400000 */
118 /* #define FMODE_INET6 0x00800000 */
119 
120 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
121 
122 #define MakeOpenFile(obj, fp) do {\
123  (fp) = rb_io_make_open_file(obj);\
124 } while (0)
125 
127 
129 
130 FILE *rb_fdopen(int, const char*);
131 int rb_io_modestr_fmode(const char *modestr);
132 int rb_io_modestr_oflags(const char *modestr);
133 CONSTFUNC(int rb_io_oflags_fmode(int oflags));
146 int rb_io_wait_readable(int);
147 int rb_io_wait_writable(int);
148 int rb_wait_for_single_fd(int fd, int events, struct timeval *tv);
149 void rb_io_set_nonblock(rb_io_t *fptr);
150 int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p);
151 ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
152 
153 /* compatibility for ruby 1.8 and older */
154 #define rb_io_mode_flags(modestr) [<"rb_io_mode_flags() is obsolete; use rb_io_modestr_fmode()">]
155 #define rb_io_modenum_flags(oflags) [<"rb_io_modenum_flags() is obsolete; use rb_io_oflags_fmode()">]
156 
158 NORETURN(void rb_eof_error(void));
159 
162 
163 struct stat;
164 VALUE rb_stat_new(const struct stat *);
165 
166 /* gc.c */
167 
169 
170 #if defined(__cplusplus)
171 #if 0
172 { /* satisfy cc-mode */
173 #endif
174 } /* extern "C" { */
175 #endif
176 
177 #endif /* RUBY_IO_H */
void rb_io_check_readable(rb_io_t *)
Definition: io.c:824
void rb_io_set_nonblock(rb_io_t *fptr)
Definition: io.c:2475
void rb_io_synchronized(rb_io_t *)
Definition: io.c:5996
int rb_io_modestr_oflags(const char *modestr)
Definition: io.c:5262
struct rb_io_t rb_io_t
rb_io_buffer_t cbuf
Definition: io.h:89
VALUE ecopts
Definition: io.h:85
Definition: io.h:62
void rb_io_check_initialized(rb_io_t *)
Definition: io.c:633
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size)
Definition: io.c:1450
void rb_io_check_byte_readable(rb_io_t *fptr)
Definition: io.c:815
int writeconv_pre_ecflags
Definition: io.h:94
int rb_io_modestr_fmode(const char *modestr)
Definition: io.c:5143
int rb_io_fptr_finalize(rb_io_t *)
Definition: io.c:4424
int writeconv_initialized
Definition: io.h:93
VALUE rb_io_taint_check(VALUE)
Definition: io.c:626
VALUE writeconv_pre_ecopts
Definition: io.h:95
rb_encoding * enc2
Definition: io.h:83
void rb_io_read_check(rb_io_t *)
Definition: io.c:869
int mode
Definition: io.h:65
rb_encoding * enc
Definition: io.h:82
VALUE rb_io_get_write_io(VALUE io)
Definition: io.c:670
int rb_io_oflags_fmode(int oflags)
Definition: io.c:5192
VALUE rb_io_check_io(VALUE io)
Definition: io.c:664
int fd
Definition: io.h:64
int rb_io_wait_writable(int)
Definition: io.c:1132
NORETURN(void rb_eof_error(void))
rb_io_t * rb_io_make_open_file(VALUE obj)
Definition: io.c:7724
struct rb_io_t::rb_io_enc_t encs
VALUE writeconv_asciicompat
Definition: io.h:92
rb_pid_t pid
Definition: io.h:66
RUBY_SYMBOL_EXPORT_BEGIN PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t { char *ptr;int off;int len;int capa;})
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
Definition: io.c:5407
rb_io_buffer_t wbuf
Definition: io.h:71
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4309
VALUE tied_io_for_writing
Definition: io.h:73
unsigned long VALUE
Definition: ruby.h:85
VALUE rb_io_get_io(VALUE io)
Definition: io.c:658
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: thread.c:3989
struct rb_io_buffer_t rb_io_buffer_t
Definition: io.h:60
register unsigned int len
Definition: zonetab.h:51
rb_econv_t * readconv
Definition: io.h:88
VALUE write_lock
Definition: io.h:97
int rb_io_read_pending(rb_io_t *)
Definition: io.c:860
void rb_io_check_char_readable(rb_io_t *fptr)
Definition: io.c:796
int size
Definition: encoding.c:57
VALUE pathv
Definition: io.h:68
FILE * rb_fdopen(int, const char *)
Definition: io.c:5716
void(* finalize)(struct rb_io_t *, int)
Definition: io.h:69
FILE * rb_io_stdio_file(rb_io_t *fptr)
Definition: io.c:7676
void rb_io_check_writable(rb_io_t *)
Definition: io.c:848
rb_io_buffer_t rbuf
Definition: io.h:71
VALUE rb_stat_new(const struct stat *)
Definition: file.c:435
FILE * stdio_file
Definition: io.h:63
int lineno
Definition: io.h:67
#define stat(path, st)
Definition: win32.h:183
VALUE rb_io_set_write_io(VALUE io, VALUE w)
Definition: io.c:681
int rb_io_wait_readable(int)
Definition: io.c:1106
void rb_io_check_closed(rb_io_t *)
Definition: io.c:641
CONSTFUNC(int rb_io_oflags_fmode(int oflags))
rb_econv_t * writeconv
Definition: io.h:91
void rb_eof_error(void)
Definition: io.c:620