Ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a25176072e02db9254f0e0c84c805cd)
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)
20extern "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
66typedef 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 {
91
94
100
103
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
137FILE *rb_fdopen(int, const char*);
138int rb_io_modestr_fmode(const char *modestr);
139int rb_io_modestr_oflags(const char *modestr);
153int rb_io_wait_readable(int);
154int rb_io_wait_writable(int);
155int rb_wait_for_single_fd(int fd, int events, struct timeval *tv);
156void rb_io_set_nonblock(rb_io_t *fptr);
157int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p);
158void rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, int *oflags_p, int *fmode_p, rb_io_enc_t *convconfig_p);
159ssize_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
167
170
171struct stat;
172VALUE 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 */
struct RIMemo * ptr
Definition: debug.c:65
int rb_io_oflags_fmode(int oflags)
Definition: io.c:5523
void rb_eof_error(void)
Definition: io.c:697
int rb_io_modestr_fmode(const char *modestr)
Definition: io.c:5469
VALUE rb_io_get_io(VALUE io)
Definition: io.c:733
int rb_io_modestr_oflags(const char *modestr)
Definition: io.c:5599
void rb_io_check_byte_readable(rb_io_t *fptr)
Definition: io.c:890
rb_io_t * rb_io_make_open_file(VALUE obj)
Definition: io.c:8084
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p)
Definition: io.c:5748
struct rb_io_t rb_io_t
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv)
Definition: thread.c:4275
struct rb_io_enc_t rb_io_enc_t
Definition: io.h:104
VALUE rb_io_taint_check(VALUE)
Definition: io.c:703
RUBY_SYMBOL_EXPORT_BEGIN PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t { char *ptr;int off;int len;int capa;})
void rb_io_check_closed(rb_io_t *)
Definition: io.c:718
int rb_io_fptr_finalize(rb_io_t *)
Definition: io.c:4751
void rb_io_check_writable(rb_io_t *)
Definition: io.c:923
NORETURN(void rb_eof_error(void))
FILE * rb_io_stdio_file(rb_io_t *fptr)
Definition: io.c:8036
FILE * rb_fdopen(int, const char *)
Definition: io.c:6057
void rb_io_check_readable(rb_io_t *)
Definition: io.c:899
int rb_io_read_pending(rb_io_t *)
Definition: io.c:935
CONSTFUNC(int rb_io_oflags_fmode(int oflags))
VALUE rb_io_check_io(VALUE io)
Definition: io.c:739
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size)
Definition: io.c:1549
void rb_io_read_check(rb_io_t *)
Definition: io.c:944
void rb_io_check_char_readable(rb_io_t *fptr)
Definition: io.c:871
struct rb_io_buffer_t rb_io_buffer_t
Definition: io.h:64
VALUE rb_io_get_write_io(VALUE io)
Definition: io.c:745
void rb_io_set_nonblock(rb_io_t *fptr)
Definition: io.c:2782
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:5875
VALUE rb_io_set_write_io(VALUE io, VALUE w)
Definition: io.c:756
VALUE rb_stat_new(const struct stat *)
Definition: file.c:492
void rb_io_synchronized(rb_io_t *)
Definition: io.c:6360
int rb_io_wait_readable(int)
Definition: io.c:1204
int rb_io_wait_writable(int)
Definition: io.c:1228
void rb_io_check_initialized(rb_io_t *)
Definition: io.c:710
const VALUE VALUE obj
#define RUBY_SYMBOL_EXPORT_BEGIN
unsigned long VALUE
__inline__ const void *__restrict__ size_t len
#define RUBY_SYMBOL_EXPORT_END
#define rb_pid_t
unsigned int size
struct rb_call_cache buf
_ssize_t ssize_t
__inline__ int
rb_encoding * enc
Definition: io.h:86
rb_encoding * enc2
Definition: io.h:87
VALUE ecopts
Definition: io.h:89
Definition: io.h:66
int fd
Definition: io.h:68
struct rb_io_t::rb_io_enc_t encs
int lineno
Definition: io.h:71
rb_econv_t * writeconv
Definition: io.h:95
rb_pid_t pid
Definition: io.h:70
rb_io_buffer_t wbuf
Definition: io.h:75
rb_econv_t * readconv
Definition: io.h:92
VALUE writeconv_asciicompat
Definition: io.h:96
FILE * stdio_file
Definition: io.h:67
int writeconv_initialized
Definition: io.h:97
VALUE pathv
Definition: io.h:72
int mode
Definition: io.h:69
int writeconv_pre_ecflags
Definition: io.h:98
VALUE write_lock
Definition: io.h:101
rb_io_buffer_t cbuf
Definition: io.h:93
VALUE writeconv_pre_ecopts
Definition: io.h:99
VALUE tied_io_for_writing
Definition: io.h:77
void(* finalize)(struct rb_io_t *, int)
Definition: io.h:73
rb_io_buffer_t rbuf
Definition: io.h:75