1 /**********************************************************************
6 created at: Fri Nov 12 16:47:09 JST 1993
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
10 **********************************************************************/
15 #if defined(__cplusplus)
18 } /* satisfy cc-mode */
24 #include "ruby/encoding.h"
26 #if defined(HAVE_STDIO_EXT_H)
27 #include <stdio_ext.h>
30 typedef struct rb_io_t
{
31 int fd
; /* file descriptor */
32 FILE *stdio_file
; /* stdio ptr for read/write if available */
33 int mode
; /* mode flags */
34 rb_pid_t pid
; /* child's pid (for pipes) */
35 int lineno
; /* number of lines read */
36 char *path
; /* pathname for file */
37 void (*finalize
)(struct rb_io_t
*,int); /* finalize proc */
40 char *wbuf
; /* wbuf_off + wbuf_len <= wbuf_capa */
45 char *rbuf
; /* rbuf_off + rbuf_len <= rbuf_capa */
50 VALUE tied_io_for_writing
;
53 * enc enc2 read action write action
54 * NULL NULL force_encoding(default_external) write the byte sequence of str
55 * e1 NULL force_encoding(e1) convert str.encoding to e1
56 * e1 e2 convert from e2 to e1 convert str.encoding to e2
62 char *crbuf
; /* crbuf_off + crbuf_len <= crbuf_capa */
67 rb_econv_t
*writeconv
;
68 VALUE writeconv_stateless
;
69 int writeconv_initialized
;
73 #define HAVE_RB_IO_T 1
75 #define FMODE_READABLE 1
76 #define FMODE_WRITABLE 2
77 #define FMODE_READWRITE 3
78 #define FMODE_APPEND 64
79 #define FMODE_CREATE 128
80 #define FMODE_BINMODE 4
83 #define FMODE_DUPLEX 32
84 #define FMODE_WSPLIT 0x200
85 #define FMODE_WSPLIT_INITIALIZED 0x400
87 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
89 #define MakeOpenFile(obj, fp) do {\
90 if (RFILE(obj)->fptr) {\
92 free(RFILE(obj)->fptr);\
93 RFILE(obj)->fptr = 0;\
96 fp = RFILE(obj)->fptr = ALLOC(rb_io_t);\
98 fp->stdio_file = NULL;\
113 fp->readconv = NULL;\
118 fp->writeconv = NULL;\
119 fp->writeconv_stateless = Qnil;\
120 fp->writeconv_initialized = 0;\
121 fp->tied_io_for_writing = 0;\
126 FILE *rb_io_stdio_file(rb_io_t
*fptr
);
128 FILE *rb_fopen(const char*, const char*);
129 FILE *rb_fdopen(int, const char*);
130 int rb_io_mode_flags(const char*);
131 int rb_io_modenum_flags(int);
132 void rb_io_check_writable(rb_io_t
*);
133 void rb_io_check_readable(rb_io_t
*);
134 int rb_io_fptr_finalize(rb_io_t
*);
135 void rb_io_synchronized(rb_io_t
*);
136 void rb_io_check_initialized(rb_io_t
*);
137 void rb_io_check_closed(rb_io_t
*);
138 int rb_io_wait_readable(int);
139 int rb_io_wait_writable(int);
140 void rb_io_set_nonblock(rb_io_t
*fptr
);
142 VALUE
rb_io_taint_check(VALUE
);
143 NORETURN(void rb_eof_error(void));
145 void rb_io_read_check(rb_io_t
*);
146 int rb_io_read_pending(rb_io_t
*);
147 void rb_read_check(FILE*);
149 DEPRECATED(int rb_getc(FILE*));
150 DEPRECATED(long rb_io_fread(char *, long, FILE *));
151 DEPRECATED(long rb_io_fwrite(const char *, long, FILE *));
152 DEPRECATED(int rb_read_pending(FILE*));
154 #if defined(__cplusplus)
156 { /* satisfy cc-mode */
161 #endif /* RUBY_IO_H */