* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / include / ruby / io.h
blob9d5407e1f38d4e4be0c8315fc6cc6582a2677ae1
1 /**********************************************************************
3 rubyio.h -
5 $Author$
6 created at: Fri Nov 12 16:47:09 JST 1993
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
10 **********************************************************************/
12 #ifndef RUBY_IO_H
13 #define RUBY_IO_H 1
15 #if defined(__cplusplus)
16 extern "C" {
17 #if 0
18 } /* satisfy cc-mode */
19 #endif
20 #endif
22 #include <stdio.h>
23 #include <errno.h>
24 #include "ruby/encoding.h"
26 #if defined(HAVE_STDIO_EXT_H)
27 #include <stdio_ext.h>
28 #endif
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 */
38 long refcnt;
40 char *wbuf; /* wbuf_off + wbuf_len <= wbuf_capa */
41 int wbuf_off;
42 int wbuf_len;
43 int wbuf_capa;
45 char *rbuf; /* rbuf_off + rbuf_len <= rbuf_capa */
46 int rbuf_off;
47 int rbuf_len;
48 int 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
58 rb_encoding *enc;
59 rb_encoding *enc2;
61 rb_econv_t *readconv;
62 char *crbuf; /* crbuf_off + crbuf_len <= crbuf_capa */
63 int crbuf_off;
64 int crbuf_len;
65 int crbuf_capa;
67 rb_econv_t *writeconv;
68 VALUE writeconv_stateless;
69 int writeconv_initialized;
71 } rb_io_t;
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
81 #define FMODE_SYNC 8
82 #define FMODE_TTY 16
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) {\
91 rb_io_close(obj);\
92 free(RFILE(obj)->fptr);\
93 RFILE(obj)->fptr = 0;\
95 fp = 0;\
96 fp = RFILE(obj)->fptr = ALLOC(rb_io_t);\
97 fp->fd = -1;\
98 fp->stdio_file = NULL;\
99 fp->mode = 0;\
100 fp->pid = 0;\
101 fp->lineno = 0;\
102 fp->path = NULL;\
103 fp->finalize = 0;\
104 fp->refcnt = 1;\
105 fp->wbuf = NULL;\
106 fp->wbuf_off = 0;\
107 fp->wbuf_len = 0;\
108 fp->wbuf_capa = 0;\
109 fp->rbuf = NULL;\
110 fp->rbuf_off = 0;\
111 fp->rbuf_len = 0;\
112 fp->rbuf_capa = 0;\
113 fp->readconv = NULL;\
114 fp->crbuf = NULL;\
115 fp->crbuf_off = 0;\
116 fp->crbuf_len = 0;\
117 fp->crbuf_capa = 0;\
118 fp->writeconv = NULL;\
119 fp->writeconv_stateless = Qnil;\
120 fp->writeconv_initialized = 0;\
121 fp->tied_io_for_writing = 0;\
122 fp->enc = 0;\
123 fp->enc2 = 0;\
124 } while (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)
155 #if 0
156 { /* satisfy cc-mode */
157 #endif
158 } /* extern "C" { */
159 #endif
161 #endif /* RUBY_IO_H */