Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
io.h
Go to the documentation of this file.
1#ifndef RUBY_IO_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RUBY_IO_H 1
14
15#include <stdio.h>
16#include "ruby/encoding.h"
17
18#if defined(HAVE_STDIO_EXT_H)
19#include <stdio_ext.h>
20#endif
21
22#include <errno.h>
23#if defined(HAVE_POLL)
24# ifdef _AIX
25# define reqevents events
26# define rtnevents revents
27# endif
28# include <poll.h>
29# ifdef _AIX
30# undef reqevents
31# undef rtnevents
32# undef events
33# undef revents
34# endif
35# define RB_WAITFD_IN POLLIN
36# define RB_WAITFD_PRI POLLPRI
37# define RB_WAITFD_OUT POLLOUT
38#else
39# define RB_WAITFD_IN 0x001
40# define RB_WAITFD_PRI 0x002
41# define RB_WAITFD_OUT 0x004
42#endif
43
44typedef enum {
49
52
54 char *ptr; /* off + len <= capa */
55 int off;
56 int len;
57 int capa;
58});
60
61typedef struct rb_io_t {
63
64 FILE *stdio_file; /* stdio ptr for read/write if available */
65 int fd; /* file descriptor */
66 int mode; /* mode flags: FMODE_XXXs */
67 rb_pid_t pid; /* child's pid (for pipes) */
68 int lineno; /* number of lines read */
69 VALUE pathv; /* pathname for file */
70 void (*finalize)(struct rb_io_t*,int); /* finalize proc */
71
73
75
76 /*
77 * enc enc2 read action write action
78 * NULL NULL force_encoding(default_external) write the byte sequence of str
79 * e1 NULL force_encoding(e1) convert str.encoding to e1
80 * e1 e2 convert from e2 to e1 convert str.encoding to e2
81 */
82 struct rb_io_enc_t {
88
91
97
100
102
103#define HAVE_RB_IO_T 1
104
105#define FMODE_READABLE 0x00000001
106#define FMODE_WRITABLE 0x00000002
107#define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)
108#define FMODE_BINMODE 0x00000004
109#define FMODE_SYNC 0x00000008
110#define FMODE_TTY 0x00000010
111#define FMODE_DUPLEX 0x00000020
112#define FMODE_APPEND 0x00000040
113#define FMODE_CREATE 0x00000080
114/* #define FMODE_NOREVLOOKUP 0x00000100 */
115#define FMODE_EXCL 0x00000400
116#define FMODE_TRUNC 0x00000800
117#define FMODE_TEXTMODE 0x00001000
118/* #define FMODE_PREP 0x00010000 */
119#define FMODE_SETENC_BY_BOM 0x00100000
120/* #define FMODE_UNIX 0x00200000 */
121/* #define FMODE_INET 0x00400000 */
122/* #define FMODE_INET6 0x00800000 */
123
124#define RB_IO_POINTER(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
125#define GetOpenFile RB_IO_POINTER
126
127#define RB_IO_OPEN(obj, fp) do {\
128 (fp) = rb_io_make_open_file(obj);\
129} while (0)
130#define MakeOpenFile RB_IO_OPEN
131
133
135
136FILE *rb_fdopen(int, const char*);
137int rb_io_modestr_fmode(const char *modestr);
138int rb_io_modestr_oflags(const char *modestr);
139CONSTFUNC(int rb_io_oflags_fmode(int oflags));
152void rb_io_set_nonblock(rb_io_t *fptr);
153int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p);
154void rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, rb_io_enc_t *convconfig_p);
155ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
156
157int rb_io_wait_readable(int fd);
158int rb_io_wait_writable(int fd);
159int rb_wait_for_single_fd(int fd, int events, struct timeval *tv);
160
161VALUE rb_io_wait(VALUE io, VALUE events, VALUE timeout);
162
163/* compatibility for ruby 1.8 and older */
164#define rb_io_mode_flags(modestr) [<"rb_io_mode_flags() is obsolete; use rb_io_modestr_fmode()">]
165#define rb_io_modenum_flags(oflags) [<"rb_io_modenum_flags() is obsolete; use rb_io_oflags_fmode()">]
166
168NORETURN(void rb_eof_error(void));
169
172
173struct stat;
174VALUE rb_stat_new(const struct stat *);
175
176/* gc.c */
177
179
180#endif /* RUBY_IO_H */
#define CONSTFUNC(x)
Definition: attributes.h:51
#define NORETURN(x)
Definition: attributes.h:152
#define PACKED_STRUCT_UNALIGNED(x)
Definition: attributes.h:163
struct RIMemo * ptr
Definition: debug.c:88
Tewaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
uint8_t len
Definition: escape.c:17
Thin wrapper to ruby/config.h.
int rb_io_modestr_fmode(const char *modestr)
Definition: io.c:5580
VALUE rb_io_get_io(VALUE io)
Definition: io.c:790
int rb_io_modestr_oflags(const char *modestr)
Definition: io.c:5713
void rb_io_check_byte_readable(rb_io_t *fptr)
Definition: io.c:947
rb_io_t * rb_io_make_open_file(VALUE obj)
Definition: io.c:8278
#define RB_WAITFD_OUT
Definition: io.h:41
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
Definition: io.c:5862
int rb_io_oflags_fmode(int oflags)
Definition: io.c:5637
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: io.c:1384
struct rb_io_enc_t rb_io_enc_t
Definition: io.h:101
#define RB_WAITFD_PRI
Definition: io.h:40
VALUE rb_io_taint_check(VALUE)
Definition: io.c:760
void rb_io_check_closed(rb_io_t *)
Definition: io.c:775
void rb_io_check_writable(rb_io_t *)
Definition: io.c:980
FILE * rb_io_stdio_file(rb_io_t *fptr)
Definition: io.c:8229
FILE * rb_fdopen(int, const char *)
Definition: io.c:6183
void rb_io_check_readable(rb_io_t *)
Definition: io.c:956
int rb_io_read_pending(rb_io_t *)
Definition: io.c:992
#define RB_WAITFD_IN
Definition: io.h:39
VALUE rb_io_check_io(VALUE io)
Definition: io.c:796
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size)
Definition: io.c:1698
void rb_io_read_check(rb_io_t *)
Definition: io.c:1001
void rb_io_check_char_readable(rb_io_t *fptr)
Definition: io.c:928
struct rb_io_buffer_t rb_io_buffer_t
Definition: io.h:59
VALUE rb_io_get_write_io(VALUE io)
Definition: io.c:802
void rb_io_set_nonblock(rb_io_t *fptr)
Definition: io.c:2942
int rb_io_wait_writable(int fd)
Definition: io.c:1341
VALUE rb_io_set_write_io(VALUE io, VALUE w)
Definition: io.c:813
VALUE rb_stat_new(const struct stat *)
Definition: file.c:547
void rb_io_synchronized(rb_io_t *)
Definition: io.c:6486
void rb_eof_error(void)
Definition: io.c:754
rb_io_event_t
Definition: io.h:44
@ RUBY_IO_READABLE
Definition: io.h:45
@ RUBY_IO_PRIORITY
Definition: io.h:47
@ RUBY_IO_WRITABLE
Definition: io.h:46
void rb_io_check_initialized(rb_io_t *)
Definition: io.c:767
int rb_io_wait_readable(int fd)
Definition: io.c:1307
VALUE rb_io_wait(VALUE io, VALUE events, VALUE timeout)
Definition: io.c:1265
#define rb_io_fptr_finalize(...)
Definition: internal.h:68
voidpf void uLong size
Definition: ioapi.h:138
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
voidpf void * buf
Definition: ioapi.h:138
#define rb_io_extract_modeenc
Definition: stringio.c:36
rb_encoding * enc
Definition: io.h:83
rb_encoding * enc2
Definition: io.h:84
VALUE ecopts
Definition: io.h:86
Definition: io.h:61
int fd
Definition: io.h:65
struct rb_io_t::rb_io_enc_t encs
int lineno
Definition: io.h:68
rb_econv_t * writeconv
Definition: io.h:92
rb_pid_t pid
Definition: io.h:67
rb_io_buffer_t wbuf
Definition: io.h:72
rb_econv_t * readconv
Definition: io.h:89
VALUE writeconv_asciicompat
Definition: io.h:93
FILE * stdio_file
Definition: io.h:64
int writeconv_initialized
Definition: io.h:94
VALUE pathv
Definition: io.h:69
int mode
Definition: io.h:66
int writeconv_pre_ecflags
Definition: io.h:95
VALUE write_lock
Definition: io.h:98
rb_io_buffer_t cbuf
Definition: io.h:90
VALUE self
Definition: io.h:62
VALUE writeconv_pre_ecopts
Definition: io.h:96
VALUE tied_io_for_writing
Definition: io.h:74
void(* finalize)(struct rb_io_t *, int)
Definition: io.h:70
rb_io_buffer_t rbuf
Definition: io.h:72
unsigned long VALUE
Definition: value.h:38
#define stat
Definition: win32.h:195