2020-04-10 01:11:40 -04:00
|
|
|
#ifndef RUBY_IO_H /*-*-C++-*-vi:se ft=cpp:*/
|
2007-06-09 23:06:15 -04:00
|
|
|
#define RUBY_IO_H 1
|
2020-04-10 01:11:40 -04:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @author $Author$
|
|
|
|
* @date Fri Nov 12 16:47:09 JST 1993
|
|
|
|
* @copyright Copyright (C) 1993-2007 Yukihiro Matsumoto
|
|
|
|
* @copyright This file is a part of the programming language Ruby.
|
|
|
|
* Permission is hereby granted, to either redistribute and/or
|
|
|
|
* modify this file, provided that the conditions mentioned in the
|
|
|
|
* file COPYING are met. Consult the file for details.
|
|
|
|
*/
|
2020-05-08 05:31:09 -04:00
|
|
|
#include "ruby/internal/config.h"
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
#include "ruby/encoding.h"
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2004-11-19 11:59:11 -05:00
|
|
|
#if defined(HAVE_STDIO_EXT_H)
|
|
|
|
#include <stdio_ext.h>
|
|
|
|
#endif
|
|
|
|
|
2018-11-21 15:39:09 -05:00
|
|
|
#include <errno.h>
|
2011-05-03 21:07:03 -04:00
|
|
|
#if defined(HAVE_POLL)
|
2013-03-28 10:10:21 -04:00
|
|
|
# ifdef _AIX
|
|
|
|
# define reqevents events
|
|
|
|
# define rtnevents revents
|
|
|
|
# endif
|
2011-05-03 21:07:03 -04:00
|
|
|
# include <poll.h>
|
2013-03-28 10:10:21 -04:00
|
|
|
# ifdef _AIX
|
|
|
|
# undef reqevents
|
|
|
|
# undef rtnevents
|
2013-03-28 21:24:14 -04:00
|
|
|
# undef events
|
|
|
|
# undef revents
|
2013-03-28 10:10:21 -04:00
|
|
|
# endif
|
2011-05-03 21:07:03 -04:00
|
|
|
# define RB_WAITFD_IN POLLIN
|
|
|
|
# define RB_WAITFD_PRI POLLPRI
|
|
|
|
# define RB_WAITFD_OUT POLLOUT
|
|
|
|
#else
|
|
|
|
# define RB_WAITFD_IN 0x001
|
|
|
|
# define RB_WAITFD_PRI 0x002
|
|
|
|
# define RB_WAITFD_OUT 0x004
|
|
|
|
#endif
|
2011-05-03 20:59:57 -04:00
|
|
|
|
2020-05-08 05:31:09 -04:00
|
|
|
#include "ruby/internal/dllexport.h"
|
2020-05-04 02:52:56 -04:00
|
|
|
RBIMPL_SYMBOL_EXPORT_BEGIN()
|
2010-07-21 17:38:25 -04:00
|
|
|
|
2014-07-24 03:03:38 -04:00
|
|
|
PACKED_STRUCT_UNALIGNED(struct rb_io_buffer_t {
|
2010-11-18 08:58:47 -05:00
|
|
|
char *ptr; /* off + len <= capa */
|
|
|
|
int off;
|
|
|
|
int len;
|
|
|
|
int capa;
|
2014-07-21 12:56:13 -04:00
|
|
|
});
|
|
|
|
typedef struct rb_io_buffer_t rb_io_buffer_t;
|
2010-11-18 08:58:47 -05:00
|
|
|
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
typedef struct rb_io_t {
|
2004-12-08 08:26:27 -05:00
|
|
|
FILE *stdio_file; /* stdio ptr for read/write if available */
|
2014-07-20 00:18:58 -04:00
|
|
|
int fd; /* file descriptor */
|
2008-09-24 08:23:52 -04:00
|
|
|
int mode; /* mode flags: FMODE_XXXs */
|
* configure.in (pid_t, uid_t, gid_t): check if defined.
* intern.h, process.c, rubyio.h, ext/etc/etc.c, ext/pty/pty.c: use
rb_{pid,uid,gid}_t instead of plain int. [ruby-dev:30376]
* ext/etc/extconf.rb (PIDT2NUM, NUM2PIDT, UIDT2NUM, NUM2UIDT, GIDT2NUM,
NUM2GIDT): moved to configure.in.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-17 23:11:57 -05:00
|
|
|
rb_pid_t pid; /* child's pid (for pipes) */
|
1999-08-13 01:45:20 -04:00
|
|
|
int lineno; /* number of lines read */
|
2008-09-24 08:23:52 -04:00
|
|
|
VALUE pathv; /* pathname for file */
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
void (*finalize)(struct rb_io_t*,int); /* finalize proc */
|
2008-08-16 13:06:35 -04:00
|
|
|
|
2010-11-18 08:58:47 -05:00
|
|
|
rb_io_buffer_t wbuf, rbuf;
|
2008-08-16 13:06:35 -04:00
|
|
|
|
2007-11-19 22:16:53 -05:00
|
|
|
VALUE tied_io_for_writing;
|
2008-08-18 04:00:55 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* enc enc2 read action write action
|
|
|
|
* NULL NULL force_encoding(default_external) write the byte sequence of str
|
|
|
|
* e1 NULL force_encoding(e1) convert str.encoding to e1
|
2008-08-18 09:35:55 -04:00
|
|
|
* e1 e2 convert from e2 to e1 convert str.encoding to e2
|
2008-08-18 04:00:55 -04:00
|
|
|
*/
|
2008-08-24 03:49:13 -04:00
|
|
|
struct rb_io_enc_t {
|
|
|
|
rb_encoding *enc;
|
|
|
|
rb_encoding *enc2;
|
2008-09-04 06:22:11 -04:00
|
|
|
int ecflags;
|
2008-09-03 14:18:10 -04:00
|
|
|
VALUE ecopts;
|
2008-08-24 03:49:13 -04:00
|
|
|
} encs;
|
2008-08-16 13:06:35 -04:00
|
|
|
|
|
|
|
rb_econv_t *readconv;
|
2010-11-18 08:58:47 -05:00
|
|
|
rb_io_buffer_t cbuf;
|
2008-08-18 08:06:42 -04:00
|
|
|
|
|
|
|
rb_econv_t *writeconv;
|
2008-09-09 11:02:42 -04:00
|
|
|
VALUE writeconv_asciicompat;
|
2014-07-20 00:18:58 -04:00
|
|
|
int writeconv_initialized;
|
2008-09-04 06:22:11 -04:00
|
|
|
int writeconv_pre_ecflags;
|
2008-09-03 14:18:10 -04:00
|
|
|
VALUE writeconv_pre_ecopts;
|
2008-08-18 08:06:42 -04:00
|
|
|
|
2008-11-07 15:47:02 -05:00
|
|
|
VALUE write_lock;
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
} rb_io_t;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2016-06-09 19:01:39 -04:00
|
|
|
typedef struct rb_io_enc_t rb_io_enc_t;
|
|
|
|
|
2007-02-24 20:16:58 -05:00
|
|
|
#define HAVE_RB_IO_T 1
|
|
|
|
|
2008-08-23 04:41:02 -04:00
|
|
|
#define FMODE_READABLE 0x00000001
|
|
|
|
#define FMODE_WRITABLE 0x00000002
|
|
|
|
#define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)
|
|
|
|
#define FMODE_BINMODE 0x00000004
|
|
|
|
#define FMODE_SYNC 0x00000008
|
|
|
|
#define FMODE_TTY 0x00000010
|
|
|
|
#define FMODE_DUPLEX 0x00000020
|
|
|
|
#define FMODE_APPEND 0x00000040
|
|
|
|
#define FMODE_CREATE 0x00000080
|
|
|
|
/* #define FMODE_NOREVLOOKUP 0x00000100 */
|
2018-08-09 04:49:09 -04:00
|
|
|
#define FMODE_EXCL 0x00000400
|
2008-08-23 04:41:02 -04:00
|
|
|
#define FMODE_TRUNC 0x00000800
|
|
|
|
#define FMODE_TEXTMODE 0x00001000
|
|
|
|
/* #define FMODE_PREP 0x00010000 */
|
2009-08-21 02:17:06 -04:00
|
|
|
#define FMODE_SETENC_BY_BOM 0x00100000
|
2015-07-01 21:58:14 -04:00
|
|
|
/* #define FMODE_UNIX 0x00200000 */
|
|
|
|
/* #define FMODE_INET 0x00400000 */
|
|
|
|
/* #define FMODE_INET6 0x00800000 */
|
1999-08-13 01:45:20 -04:00
|
|
|
|
2000-11-10 02:16:52 -05:00
|
|
|
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
#define MakeOpenFile(obj, fp) do {\
|
2014-10-09 22:34:24 -04:00
|
|
|
(fp) = rb_io_make_open_file(obj);\
|
2010-11-18 08:58:47 -05:00
|
|
|
} while (0)
|
|
|
|
|
2014-10-09 22:34:24 -04:00
|
|
|
rb_io_t *rb_io_make_open_file(VALUE obj);
|
|
|
|
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
FILE *rb_io_stdio_file(rb_io_t *fptr);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
FILE *rb_fdopen(int, const char*);
|
2008-09-05 07:30:35 -04:00
|
|
|
int rb_io_modestr_fmode(const char *modestr);
|
|
|
|
int rb_io_modestr_oflags(const char *modestr);
|
2016-05-08 13:44:51 -04:00
|
|
|
CONSTFUNC(int rb_io_oflags_fmode(int oflags));
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
void rb_io_check_writable(rb_io_t*);
|
|
|
|
void rb_io_check_readable(rb_io_t*);
|
2011-01-14 19:42:14 -05:00
|
|
|
void rb_io_check_char_readable(rb_io_t *fptr);
|
|
|
|
void rb_io_check_byte_readable(rb_io_t *fptr);
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
int rb_io_fptr_finalize(rb_io_t*);
|
|
|
|
void rb_io_synchronized(rb_io_t*);
|
|
|
|
void rb_io_check_initialized(rb_io_t*);
|
|
|
|
void rb_io_check_closed(rb_io_t*);
|
2011-01-14 19:42:14 -05:00
|
|
|
VALUE rb_io_get_io(VALUE io);
|
2012-07-27 05:25:54 -04:00
|
|
|
VALUE rb_io_check_io(VALUE io);
|
2011-01-14 19:42:14 -05:00
|
|
|
VALUE rb_io_get_write_io(VALUE io);
|
|
|
|
VALUE rb_io_set_write_io(VALUE io, VALUE w);
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
int rb_io_wait_readable(int);
|
|
|
|
int rb_io_wait_writable(int);
|
2011-05-03 20:59:57 -04:00
|
|
|
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv);
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
void rb_io_set_nonblock(rb_io_t *fptr);
|
2010-07-21 23:02:40 -04:00
|
|
|
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p);
|
2016-06-09 19:01:39 -04:00
|
|
|
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);
|
2011-01-14 19:42:14 -05:00
|
|
|
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
|
2008-09-05 07:30:35 -04:00
|
|
|
/* compatibility for ruby 1.8 and older */
|
2014-10-09 22:27:41 -04:00
|
|
|
#define rb_io_mode_flags(modestr) [<"rb_io_mode_flags() is obsolete; use rb_io_modestr_fmode()">]
|
|
|
|
#define rb_io_modenum_flags(oflags) [<"rb_io_modenum_flags() is obsolete; use rb_io_oflags_fmode()">]
|
2008-09-05 07:30:35 -04:00
|
|
|
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
VALUE rb_io_taint_check(VALUE);
|
|
|
|
NORETURN(void rb_eof_error(void));
|
|
|
|
|
* file.c, gc.c, io.c, ruby.h, rubyio.h, win32/win32.h (rb_io_t):
renamed from OpenFile.
* ext/dl/cptr.c, ext/io/wait/wait.c, ext/openssl/ossl.h,
ext/openssl/ossl_bio.c, ext/openssl/ossl_ssl.c, ext/pty/pty.c,
ext/readline/readline.c, ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-24 05:30:50 -05:00
|
|
|
void rb_io_read_check(rb_io_t*);
|
|
|
|
int rb_io_read_pending(rb_io_t*);
|
* bignum.c: changed `foo _((boo))' to `foo(boo)`. [ruby-dev:27056]
* defines.h, dir.c, dln.h, enumerator.c, env.h, error.c, eval.c, file.c,
gc.c, hash.c, inits.c, intern.h, io.c, lex.c, marshal.c, missing.h,
node.h, numeric.c, pack.c, process.c, re.h, ruby.c, ruby.h, rubyio.h,
rubysig.h, signal.c, sprintf.c, st.h, string.c, struct.c, time.c,
util.c, util.h, variable.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-14 02:32:32 -04:00
|
|
|
|
2013-10-01 07:54:53 -04:00
|
|
|
struct stat;
|
|
|
|
VALUE rb_stat_new(const struct stat *);
|
|
|
|
|
|
|
|
/* gc.c */
|
|
|
|
|
2020-05-04 02:52:56 -04:00
|
|
|
RBIMPL_SYMBOL_EXPORT_END()
|
2007-06-09 23:06:15 -04:00
|
|
|
|
|
|
|
#endif /* RUBY_IO_H */
|