2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
io.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Fri Oct 15 18:08:59 JST 1993
|
|
|
|
|
* 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-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
2000-05-01 13:42:38 +04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 08:53:16 +04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/io.h"
|
2008-12-20 12:28:29 +03:00
|
|
|
#include "dln.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
#define free(x) xfree(x)
|
|
|
|
|
2007-08-25 10:20:48 +04:00
|
|
|
#if defined(DOSISH) || defined(__CYGWIN__)
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
#include <sys/types.h>
|
2008-08-08 12:03:19 +04:00
|
|
|
#if defined HAVE_NET_SOCKET_H
|
|
|
|
# include <net/socket.h>
|
|
|
|
#elif defined HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
2004-12-06 14:19:27 +03:00
|
|
|
#endif
|
2003-12-26 04:47:12 +03:00
|
|
|
|
2008-10-04 17:33:22 +04:00
|
|
|
#if defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__EMX__) || defined(__BEOS__)
|
2000-08-25 12:26:06 +04:00
|
|
|
# define NO_SAFE_RENAME
|
|
|
|
#endif
|
|
|
|
|
2008-10-04 17:33:22 +04:00
|
|
|
#if defined(__CYGWIN__) || defined(_WIN32)
|
2000-08-25 12:26:06 +04:00
|
|
|
# define NO_LONG_FNAME
|
|
|
|
#endif
|
|
|
|
|
2005-09-17 18:40:06 +04:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(sun) || defined(_nec_ews)
|
2001-05-02 08:22:21 +04:00
|
|
|
# define USE_SETVBUF
|
|
|
|
#endif
|
|
|
|
|
2001-08-06 07:05:23 +04:00
|
|
|
#ifdef __QNXNTO__
|
|
|
|
#include "unix.h"
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <sys/types.h>
|
2008-10-04 17:25:12 +04:00
|
|
|
#if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32)
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
* configure.in, defines.h, dir.c, dir.h, dln.c, error.c,
eval.c, file.c, hash.c, io.c, main.c, missing.c,
process.c, ruby.c, rubysig.h, signal.c, st.c, util.c, util.h,
bcc/Makefile.sub, win32/Makefile.sub, win32/win32.h,
ext/Win32API/Win32API.c, ext/socket/getaddrinfo.c,
ext/socket/getnameinfo.c, ext/socket/socket.c,
ext/tcltklib/stubs.c
: replace "NT" with "_WIN32", add DOSISH_DRIVE_LETTER
* wince/exe.mak : delete \r at the end of lines.
* wince/mswince-ruby17.def : delete rb_obj_become
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-15 06:18:08 +03:00
|
|
|
#if defined(HAVE_FCNTL_H) || defined(_WIN32)
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <fcntl.h>
|
1999-08-13 09:45:20 +04:00
|
|
|
#elif defined(HAVE_SYS_FCNTL_H)
|
|
|
|
#include <sys/fcntl.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
2002-03-14 09:23:46 +03:00
|
|
|
#if !HAVE_OFF_T && !defined(off_t)
|
|
|
|
# define off_t long
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2002-05-02 11:50:36 +04:00
|
|
|
/* EMX has sys/param.h, but.. */
|
2004-01-02 19:21:26 +03:00
|
|
|
#if defined(HAVE_SYS_PARAM_H) && !(defined(__EMX__) || defined(__HIUX_MPP__))
|
1998-01-16 15:13:05 +03:00
|
|
|
# include <sys/param.h>
|
2002-08-16 11:23:04 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined NOFILE
|
1998-01-16 15:13:05 +03:00
|
|
|
# define NOFILE 64
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-13 18:30:54 +04:00
|
|
|
#ifdef HAVE_SYSCALL_H
|
|
|
|
#include <syscall.h>
|
2005-10-24 16:15:26 +04:00
|
|
|
#elif defined HAVE_SYS_SYSCALL_H
|
|
|
|
#include <sys/syscall.h>
|
2005-10-13 18:30:54 +04:00
|
|
|
#endif
|
|
|
|
|
* 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 10:32:32 +04:00
|
|
|
extern void Init_File(void);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
#ifdef __BEOS__
|
2000-05-16 06:46:57 +04:00
|
|
|
# ifndef NOFILE
|
1999-08-13 09:45:20 +04:00
|
|
|
# define NOFILE (OPEN_MAX)
|
|
|
|
# endif
|
1999-01-20 07:59:39 +03:00
|
|
|
#endif
|
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/util.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-12-22 05:15:35 +03:00
|
|
|
#ifndef O_ACCMODE
|
|
|
|
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
|
|
|
|
#endif
|
|
|
|
|
2002-03-27 08:28:00 +03:00
|
|
|
#if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG)
|
|
|
|
# error off_t is bigger than long, but you have no long long...
|
|
|
|
#endif
|
|
|
|
|
2005-09-20 12:14:56 +04:00
|
|
|
#ifndef PIPE_BUF
|
|
|
|
# ifdef _POSIX_PIPE_BUF
|
|
|
|
# define PIPE_BUF _POSIX_PIPE_BUF
|
|
|
|
# else
|
|
|
|
# define PIPE_BUF 512 /* is this ok? */
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2009-04-26 13:46:41 +04:00
|
|
|
#define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_cIO;
|
|
|
|
VALUE rb_eEOFError;
|
|
|
|
VALUE rb_eIOError;
|
2009-03-19 14:40:38 +03:00
|
|
|
VALUE rb_mWaitReadable;
|
|
|
|
VALUE rb_mWaitWritable;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-07-29 22:26:55 +04:00
|
|
|
VALUE rb_stdin, rb_stdout, rb_stderr;
|
2003-07-31 12:42:44 +04:00
|
|
|
VALUE rb_deferr; /* rescue VIM plugin */
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
static VALUE orig_stdout, orig_stderr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_output_fs;
|
|
|
|
VALUE rb_rs;
|
|
|
|
VALUE rb_output_rs;
|
|
|
|
VALUE rb_default_rs;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
static VALUE argf;
|
|
|
|
|
2008-08-18 17:42:09 +04:00
|
|
|
static ID id_write, id_read, id_getc, id_flush, id_readpartial;
|
2008-06-17 01:31:56 +04:00
|
|
|
static VALUE sym_mode, sym_perm, sym_extenc, sym_intenc, sym_encoding, sym_open_args;
|
2008-08-23 06:23:42 +04:00
|
|
|
static VALUE sym_textmode, sym_binmode;
|
1998-01-16 15:13:05 +03: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 10:32:32 +04:00
|
|
|
struct timeval rb_time_interval(VALUE);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
struct argf {
|
|
|
|
VALUE filename, current_file;
|
2009-06-26 22:10:12 +04:00
|
|
|
int last_lineno; /* $. */
|
|
|
|
int lineno;
|
2008-03-01 11:59:04 +03:00
|
|
|
int init_p, next_p;
|
|
|
|
VALUE argv;
|
|
|
|
char *inplace;
|
|
|
|
int binmode;
|
2008-08-24 13:03:04 +04:00
|
|
|
struct rb_io_enc_t encs;
|
2008-03-01 11:59:04 +03:00
|
|
|
};
|
|
|
|
|
2008-04-24 18:46:39 +04:00
|
|
|
static int max_file_descriptor = NOFILE;
|
|
|
|
#define UPDATE_MAXFD(fd) \
|
|
|
|
do { \
|
|
|
|
if (max_file_descriptor < (fd)) max_file_descriptor = (fd); \
|
|
|
|
} while (0)
|
|
|
|
|
2008-03-19 18:21:15 +03:00
|
|
|
#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
|
|
|
|
#define ARGF argf_of(argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-12-30 16:49:56 +03:00
|
|
|
#ifdef _STDIO_USES_IOSTREAM /* GNU libc */
|
|
|
|
# ifdef _IO_fpos_t
|
|
|
|
# define STDIO_READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
|
|
|
|
# else
|
|
|
|
# define STDIO_READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
|
|
|
|
# endif
|
|
|
|
#elif defined(FILE_COUNT)
|
|
|
|
# define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
|
|
|
|
#elif defined(FILE_READEND)
|
|
|
|
# define STDIO_READ_DATA_PENDING(fp) ((fp)->FILE_READPTR < (fp)->FILE_READEND)
|
|
|
|
#elif defined(__BEOS__)
|
|
|
|
# define STDIO_READ_DATA_PENDING(fp) (fp->_state._eof == 0)
|
|
|
|
#else
|
|
|
|
# define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
|
|
|
|
#endif
|
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
#define GetWriteIO(io) rb_io_get_write_io(io)
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
#define READ_DATA_PENDING(fptr) ((fptr)->rbuf_len)
|
|
|
|
#define READ_DATA_PENDING_COUNT(fptr) ((fptr)->rbuf_len)
|
|
|
|
#define READ_DATA_PENDING_PTR(fptr) ((fptr)->rbuf+(fptr)->rbuf_off)
|
|
|
|
#define READ_DATA_BUFFERED(fptr) READ_DATA_PENDING(fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
#define READ_CHECK(fptr) do {\
|
|
|
|
if (!READ_DATA_PENDING(fptr)) {\
|
|
|
|
rb_thread_wait_fd((fptr)->fd);\
|
2004-06-23 17:18:32 +04:00
|
|
|
rb_io_check_closed(fptr);\
|
1999-08-13 09:45:20 +04:00
|
|
|
}\
|
1998-01-16 15:13:05 +03:00
|
|
|
} while(0)
|
|
|
|
|
2005-11-11 14:08:17 +03:00
|
|
|
#ifndef S_ISSOCK
|
|
|
|
# ifdef _S_ISSOCK
|
|
|
|
# define S_ISSOCK(m) _S_ISSOCK(m)
|
|
|
|
# else
|
|
|
|
# ifdef _S_IFSOCK
|
|
|
|
# define S_ISSOCK(m) ((m & S_IFMT) == _S_IFSOCK)
|
|
|
|
# else
|
|
|
|
# ifdef S_IFSOCK
|
|
|
|
# define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2008-08-08 18:27:25 +04:00
|
|
|
#if !defined HAVE_SHUTDOWN && !defined shutdown
|
2008-08-07 00:52:44 +04:00
|
|
|
#define shutdown(a,b) 0
|
|
|
|
#endif
|
|
|
|
|
2008-08-23 04:47:54 +04:00
|
|
|
#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
|
|
|
|
|
2004-12-06 14:19:27 +03:00
|
|
|
#if defined(_WIN32)
|
2004-12-06 15:20:29 +03:00
|
|
|
#define is_socket(fd, path) rb_w32_is_socket(fd)
|
2005-11-11 14:08:17 +03:00
|
|
|
#elif !defined(S_ISSOCK)
|
2004-12-06 17:04:05 +03:00
|
|
|
#define is_socket(fd, path) 0
|
2004-12-06 14:19:27 +03:00
|
|
|
#else
|
|
|
|
static int
|
2008-08-23 04:47:54 +04:00
|
|
|
is_socket(int fd, VALUE path)
|
2004-12-06 14:19:27 +03:00
|
|
|
{
|
2004-12-06 15:20:29 +03:00
|
|
|
struct stat sbuf;
|
|
|
|
if (fstat(fd, &sbuf) < 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(path);
|
2004-12-06 14:19:27 +03:00
|
|
|
return S_ISSOCK(sbuf.st_mode);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_eof_error(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_raise(rb_eEOFError, "end of file reached");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2000-11-10 10:16:52 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_taint_check(VALUE io)
|
2000-11-10 10:16:52 +03:00
|
|
|
{
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (!OBJ_UNTRUSTED(io) && rb_safe_level() >= 4)
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: operation on trusted IO");
|
2002-09-03 09:20:14 +04:00
|
|
|
rb_check_frozen(io);
|
2000-11-10 10:16:52 +03:00
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_check_initialized(rb_io_t *fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
if (!fptr) {
|
|
|
|
rb_raise(rb_eIOError, "uninitialized stream");
|
|
|
|
}
|
2004-10-29 16:28:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_check_closed(rb_io_t *fptr)
|
2004-10-29 16:28:32 +04:00
|
|
|
{
|
|
|
|
rb_io_check_initialized(fptr);
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->fd < 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eIOError, "closed stream");
|
2000-07-06 11:21:26 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
static int io_fflush(rb_io_t *);
|
2002-10-02 18:59:25 +04:00
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_get_io(VALUE io)
|
2004-04-07 06:51:05 +04:00
|
|
|
{
|
|
|
|
return rb_convert_type(io, T_FILE, "IO", "to_io");
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_check_io(VALUE io)
|
2004-04-07 06:51:05 +04:00
|
|
|
{
|
|
|
|
return rb_check_convert_type(io, T_FILE, "IO", "to_io");
|
|
|
|
}
|
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE
|
|
|
|
rb_io_get_write_io(VALUE io)
|
|
|
|
{
|
|
|
|
VALUE write_io;
|
2008-06-02 16:45:42 +04:00
|
|
|
rb_io_check_initialized(RFILE(io)->fptr);
|
2007-11-20 06:16:53 +03:00
|
|
|
write_io = RFILE(io)->fptr->tied_io_for_writing;
|
|
|
|
if (write_io) {
|
|
|
|
return write_io;
|
|
|
|
}
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2007-08-24 21:47:09 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.try_convert(obj) -> io or nil
|
|
|
|
*
|
|
|
|
* Try to convert <i>obj</i> into an IO, using to_io method.
|
|
|
|
* Returns converted IO or nil if <i>obj</i> cannot be converted
|
|
|
|
* for any reason.
|
|
|
|
*
|
|
|
|
* IO.try_convert(STDOUT) # => STDOUT
|
|
|
|
* IO.try_convert("STDOUT") # => nil
|
2008-12-31 12:06:09 +03:00
|
|
|
*
|
2008-12-31 14:09:27 +03:00
|
|
|
* require 'zlib'
|
2008-12-31 12:06:09 +03:00
|
|
|
* f = open("/tmp/zz.gz") # => #<File:/tmp/zz.gz>
|
|
|
|
* z = Zlib::GzipReader.open(f) # => #<Zlib::GzipReader:0x81d8744>
|
|
|
|
* IO.try_convert(z) # => #<File:/tmp/zz.gz>
|
|
|
|
*
|
2007-08-24 21:47:09 +04:00
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_io_s_try_convert(VALUE dummy, VALUE io)
|
|
|
|
{
|
|
|
|
return rb_io_check_io(io);
|
|
|
|
}
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
static 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 13:30:50 +03:00
|
|
|
io_unread(rb_io_t *fptr)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
{
|
|
|
|
off_t r;
|
|
|
|
rb_io_check_closed(fptr);
|
2004-12-23 13:12:35 +03:00
|
|
|
if (fptr->rbuf_len == 0 || fptr->mode & FMODE_DUPLEX)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
return;
|
|
|
|
/* xxx: target position may be negative if buffer is filled by ungetc */
|
2007-12-28 21:10:31 +03:00
|
|
|
r = lseek(fptr->fd, -fptr->rbuf_len, SEEK_CUR);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (r < 0) {
|
|
|
|
if (errno == ESPIPE)
|
2004-12-23 13:12:35 +03:00
|
|
|
fptr->mode |= FMODE_DUPLEX;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fptr->rbuf_off = 0;
|
|
|
|
fptr->rbuf_len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-29 18:38:44 +04:00
|
|
|
static rb_encoding *io_input_encoding(rb_io_t *fptr);
|
|
|
|
|
* 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-25 07:29:39 +04:00
|
|
|
static void
|
2008-08-18 18:28:45 +04:00
|
|
|
io_ungetbyte(VALUE str, rb_io_t *fptr)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
{
|
2009-04-26 13:46:41 +04:00
|
|
|
long len = RSTRING_LEN(str);
|
* 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-25 07:29:39 +04:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->rbuf == NULL) {
|
|
|
|
fptr->rbuf_off = 0;
|
|
|
|
fptr->rbuf_len = 0;
|
2009-04-26 13:46:41 +04:00
|
|
|
#if SIZEOF_LONG > SIZEOF_INT
|
|
|
|
if (len > INT_MAX)
|
|
|
|
rb_raise(rb_eIOError, "ungetbyte failed");
|
|
|
|
#endif
|
* 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-25 07:29:39 +04:00
|
|
|
if (len > 8192)
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->rbuf_capa = (int)len;
|
* 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-25 07:29:39 +04:00
|
|
|
else
|
|
|
|
fptr->rbuf_capa = 8192;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa);
|
|
|
|
}
|
2008-01-03 18:40:45 +03:00
|
|
|
if (fptr->rbuf_capa < len + fptr->rbuf_len) {
|
2008-08-18 18:28:45 +04:00
|
|
|
rb_raise(rb_eIOError, "ungetbyte failed");
|
* 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-25 07:29:39 +04:00
|
|
|
}
|
2008-01-03 18:40:45 +03:00
|
|
|
if (fptr->rbuf_off < len) {
|
|
|
|
MEMMOVE(fptr->rbuf+fptr->rbuf_capa-fptr->rbuf_len,
|
|
|
|
fptr->rbuf+fptr->rbuf_off,
|
|
|
|
char, fptr->rbuf_len);
|
|
|
|
fptr->rbuf_off = fptr->rbuf_capa-fptr->rbuf_len;
|
|
|
|
}
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->rbuf_off-=(int)len;
|
|
|
|
fptr->rbuf_len+=(int)len;
|
* 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-25 07:29:39 +04:00
|
|
|
MEMMOVE(fptr->rbuf+fptr->rbuf_off, RSTRING_PTR(str), char, len);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03: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 13:30:50 +03:00
|
|
|
static rb_io_t *
|
|
|
|
flush_before_seek(rb_io_t *fptr)
|
2002-10-02 18:59:25 +04:00
|
|
|
{
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
io_unread(fptr);
|
2007-10-25 09:19:33 +04:00
|
|
|
errno = 0;
|
2002-10-02 18:59:25 +04:00
|
|
|
return fptr;
|
|
|
|
}
|
|
|
|
|
2009-01-21 07:56:06 +03:00
|
|
|
#define io_set_eof(fptr) (void)(((fptr)->mode & FMODE_TTY) && ((fptr)->mode |= FMODE_EOF))
|
2009-01-21 09:31:03 +03:00
|
|
|
#define io_unset_eof(fptr) (fptr->mode &= ~FMODE_EOF)
|
|
|
|
#define io_seek(fptr, ofs, whence) (io_unset_eof(fptr), lseek(flush_before_seek(fptr)->fd, ofs, whence))
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
#define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
|
2002-10-02 18:59:25 +04:00
|
|
|
|
2003-01-09 11:05:32 +03:00
|
|
|
#ifndef SEEK_CUR
|
|
|
|
# define SEEK_SET 0
|
|
|
|
# define SEEK_CUR 1
|
|
|
|
# define SEEK_END 2
|
|
|
|
#endif
|
|
|
|
|
2003-01-10 19:47:03 +03:00
|
|
|
#define FMODE_SYNCWRITE (FMODE_SYNC|FMODE_WRITABLE)
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_check_readable(rb_io_t *fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-08-01 11:23:00 +04:00
|
|
|
rb_io_check_closed(fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (!(fptr->mode & FMODE_READABLE)) {
|
|
|
|
rb_raise(rb_eIOError, "not opened for reading");
|
|
|
|
}
|
|
|
|
if (fptr->wbuf_len) {
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
2002-10-02 18:59:25 +04:00
|
|
|
}
|
2008-01-17 18:49:33 +03:00
|
|
|
if (fptr->tied_io_for_writing) {
|
|
|
|
rb_io_t *wfptr;
|
|
|
|
GetOpenFile(fptr->tied_io_for_writing, wfptr);
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(wfptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
2008-01-17 18:49:33 +03:00
|
|
|
}
|
2007-12-23 21:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static rb_encoding*
|
|
|
|
io_read_encoding(rb_io_t *fptr)
|
|
|
|
{
|
2008-08-24 11:49:13 +04:00
|
|
|
if (fptr->encs.enc) {
|
|
|
|
return fptr->encs.enc;
|
2007-12-12 10:39:43 +03:00
|
|
|
}
|
2008-01-09 20:44:13 +03:00
|
|
|
return rb_default_external_encoding();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2007-12-24 19:36:14 +03:00
|
|
|
static rb_encoding*
|
|
|
|
io_input_encoding(rb_io_t *fptr)
|
|
|
|
{
|
2008-08-24 11:49:13 +04:00
|
|
|
if (fptr->encs.enc2) {
|
|
|
|
return fptr->encs.enc2;
|
2007-12-24 19:36:14 +03:00
|
|
|
}
|
|
|
|
return io_read_encoding(fptr);
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_check_writable(rb_io_t *fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-08-01 11:23:00 +04:00
|
|
|
rb_io_check_closed(fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!(fptr->mode & FMODE_WRITABLE)) {
|
|
|
|
rb_raise(rb_eIOError, "not opened for writing");
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->rbuf_len) {
|
|
|
|
io_unread(fptr);
|
2003-12-24 11:47:36 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
int
|
* 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 13:30:50 +03:00
|
|
|
rb_io_read_pending(rb_io_t *fptr)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
{
|
|
|
|
return READ_DATA_PENDING(fptr);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2000-02-01 06:18:03 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_read_check(FILE *fp)
|
2000-02-01 06:18:03 +03:00
|
|
|
{
|
2004-12-30 16:49:56 +03:00
|
|
|
if (!STDIO_READ_DATA_PENDING(fp)) {
|
2000-02-01 06:18:03 +03:00
|
|
|
rb_thread_wait_fd(fileno(fp));
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_read_check(rb_io_t *fptr)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
{
|
|
|
|
if (!READ_DATA_PENDING(fptr)) {
|
|
|
|
rb_thread_wait_fd(fptr->fd);
|
|
|
|
}
|
|
|
|
return;
|
2000-02-01 06:18:03 +03:00
|
|
|
}
|
|
|
|
|
2000-05-12 13:07:57 +04:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ruby_dup(int orig)
|
2000-05-12 13:07:57 +04:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = dup(orig);
|
|
|
|
if (fd < 0) {
|
2007-01-03 07:03:47 +03:00
|
|
|
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
|
2000-05-12 13:07:57 +04:00
|
|
|
rb_gc();
|
|
|
|
fd = dup(orig);
|
|
|
|
}
|
|
|
|
if (fd < 0) {
|
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2002-12-20 11:33:17 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_alloc(VALUE klass)
|
2002-12-20 11:33:17 +03:00
|
|
|
{
|
|
|
|
NEWOBJ(io, struct RFile);
|
|
|
|
OBJSETUP(io, klass, T_FILE);
|
|
|
|
|
|
|
|
io->fptr = 0;
|
|
|
|
|
|
|
|
return (VALUE)io;
|
|
|
|
}
|
|
|
|
|
2005-07-20 14:21:16 +04:00
|
|
|
#ifndef S_ISREG
|
|
|
|
# define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
2005-07-18 05:00:23 +04:00
|
|
|
static int
|
* 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 13:30:50 +03:00
|
|
|
wsplit_p(rb_io_t *fptr)
|
2005-07-18 05:00:23 +04:00
|
|
|
{
|
2008-04-26 13:36:35 +04:00
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
|
2005-07-18 05:00:23 +04:00
|
|
|
int r;
|
2008-04-26 13:36:35 +04:00
|
|
|
#endif
|
|
|
|
|
2005-07-18 05:00:23 +04:00
|
|
|
if (!(fptr->mode & FMODE_WSPLIT_INITIALIZED)) {
|
|
|
|
struct stat buf;
|
|
|
|
if (fstat(fptr->fd, &buf) == 0 &&
|
2005-07-20 14:08:41 +04:00
|
|
|
!S_ISREG(buf.st_mode)
|
2005-07-20 13:46:57 +04:00
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
|
2005-07-20 14:08:41 +04:00
|
|
|
&& (r = fcntl(fptr->fd, F_GETFL)) != -1 &&
|
2005-07-20 13:46:57 +04:00
|
|
|
!(r & O_NONBLOCK)
|
|
|
|
#endif
|
|
|
|
) {
|
2005-07-18 05:00:23 +04:00
|
|
|
fptr->mode |= FMODE_WSPLIT;
|
|
|
|
}
|
|
|
|
fptr->mode |= FMODE_WSPLIT_INITIALIZED;
|
|
|
|
}
|
|
|
|
return fptr->mode & FMODE_WSPLIT;
|
|
|
|
}
|
|
|
|
|
2007-12-21 12:43:49 +03:00
|
|
|
struct io_internal_struct {
|
|
|
|
int fd;
|
|
|
|
void *buf;
|
|
|
|
size_t capa;
|
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
2008-05-02 18:59:28 +04:00
|
|
|
internal_read_func(void *ptr)
|
2007-12-21 12:43:49 +03:00
|
|
|
{
|
|
|
|
struct io_internal_struct *iis = (struct io_internal_struct*)ptr;
|
2008-05-02 18:59:28 +04:00
|
|
|
return read(iis->fd, iis->buf, iis->capa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
internal_write_func(void *ptr)
|
|
|
|
{
|
|
|
|
struct io_internal_struct *iis = (struct io_internal_struct*)ptr;
|
|
|
|
return write(iis->fd, iis->buf, iis->capa);
|
2007-12-21 12:43:49 +03:00
|
|
|
}
|
|
|
|
|
2009-04-26 13:46:41 +04:00
|
|
|
static ssize_t
|
2007-12-21 12:43:49 +03:00
|
|
|
rb_read_internal(int fd, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct io_internal_struct iis;
|
|
|
|
iis.fd = fd;
|
|
|
|
iis.buf = buf;
|
|
|
|
iis.capa = count;
|
|
|
|
|
2009-04-26 13:46:41 +04:00
|
|
|
return (ssize_t)rb_thread_blocking_region(internal_read_func, &iis, RUBY_UBF_IO, 0);
|
2007-12-21 12:43:49 +03:00
|
|
|
}
|
|
|
|
|
2009-04-26 13:46:41 +04:00
|
|
|
static ssize_t
|
2007-12-21 12:43:49 +03:00
|
|
|
rb_write_internal(int fd, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct io_internal_struct iis;
|
|
|
|
iis.fd = fd;
|
|
|
|
iis.buf = buf;
|
|
|
|
iis.capa = count;
|
|
|
|
|
2009-04-26 13:46:41 +04:00
|
|
|
return (ssize_t)rb_thread_blocking_region(internal_write_func, &iis, RUBY_UBF_IO, 0);
|
2007-12-21 12:43:49 +03:00
|
|
|
}
|
|
|
|
|
2008-11-07 23:47:02 +03:00
|
|
|
static long
|
|
|
|
io_writable_length(rb_io_t *fptr, long l)
|
|
|
|
{
|
|
|
|
if (PIPE_BUF < l &&
|
|
|
|
!rb_thread_alone() &&
|
|
|
|
wsplit_p(fptr)) {
|
|
|
|
l = PIPE_BUF;
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
io_flush_buffer(VALUE arg)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr = (rb_io_t *)arg;
|
|
|
|
long l = io_writable_length(fptr, fptr->wbuf_len);
|
|
|
|
return rb_write_internal(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
|
|
|
|
}
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
static int
|
* 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 13:30:50 +03:00
|
|
|
io_fflush(rb_io_t *fptr)
|
2000-11-08 08:29:37 +03:00
|
|
|
{
|
2008-11-07 23:47:02 +03:00
|
|
|
long r;
|
2000-11-17 07:41:19 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_io_check_closed(fptr);
|
|
|
|
if (fptr->wbuf_len == 0)
|
|
|
|
return 0;
|
|
|
|
if (!rb_thread_fd_writable(fptr->fd)) {
|
2003-06-26 22:24:58 +04:00
|
|
|
rb_io_check_closed(fptr);
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
retry:
|
|
|
|
if (fptr->wbuf_len == 0)
|
|
|
|
return 0;
|
2008-12-25 09:55:38 +03:00
|
|
|
if (fptr->write_lock) {
|
|
|
|
r = rb_mutex_synchronize(fptr->write_lock, io_flush_buffer, (VALUE)fptr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
long l = io_writable_length(fptr, fptr->wbuf_len);
|
|
|
|
r = rb_write_internal(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
|
|
|
|
}
|
2007-12-29 17:52:32 +03:00
|
|
|
/* xxx: Other threads may modify wbuf.
|
2007-12-29 17:49:11 +03:00
|
|
|
* A lock is required, definitely. */
|
2007-12-26 11:33:38 +03:00
|
|
|
rb_io_check_closed(fptr);
|
2007-12-27 08:36:02 +03:00
|
|
|
if (fptr->wbuf_len <= r) {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->wbuf_off = 0;
|
|
|
|
fptr->wbuf_len = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (0 <= r) {
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->wbuf_off += (int)r;
|
|
|
|
fptr->wbuf_len -= (int)r;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
errno = EAGAIN;
|
|
|
|
}
|
|
|
|
if (rb_io_wait_writable(fptr->fd)) {
|
2004-11-29 09:09:40 +03:00
|
|
|
rb_io_check_closed(fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
goto retry;
|
2002-10-09 10:12:54 +04:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
return -1;
|
2000-11-08 08:29:37 +03:00
|
|
|
}
|
|
|
|
|
2005-06-03 18:23:17 +04:00
|
|
|
#ifdef HAVE_RB_FD_INIT
|
|
|
|
static VALUE
|
2006-03-01 13:06:03 +03:00
|
|
|
wait_readable(VALUE p)
|
2005-06-03 18:23:17 +04:00
|
|
|
{
|
|
|
|
rb_fdset_t *rfds = (rb_fdset_t *)p;
|
|
|
|
|
|
|
|
return rb_thread_select(rb_fd_max(rfds), rb_fd_ptr(rfds), NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-02 18:13:58 +04:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_wait_readable(int f)
|
2002-09-11 05:09:04 +04:00
|
|
|
{
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fdset_t rfds;
|
2002-10-02 18:13:58 +04:00
|
|
|
|
2008-07-11 15:51:39 +04:00
|
|
|
if (f < 0) {
|
|
|
|
rb_raise(rb_eIOError, "closed stream");
|
|
|
|
}
|
2002-10-02 18:13:58 +04:00
|
|
|
switch (errno) {
|
|
|
|
case EINTR:
|
|
|
|
#if defined(ERESTART)
|
|
|
|
case ERESTART:
|
|
|
|
#endif
|
|
|
|
rb_thread_wait_fd(f);
|
|
|
|
return Qtrue;
|
|
|
|
|
|
|
|
case EAGAIN:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
#endif
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_init(&rfds);
|
|
|
|
rb_fd_set(f, &rfds);
|
|
|
|
#ifdef HAVE_RB_FD_INIT
|
|
|
|
rb_ensure(wait_readable, (VALUE)&rfds,
|
2005-09-14 12:30:16 +04:00
|
|
|
(VALUE (*)(VALUE))rb_fd_term, (VALUE)&rfds);
|
2005-06-03 18:23:17 +04:00
|
|
|
#else
|
2009-01-14 06:39:20 +03:00
|
|
|
rb_thread_select(f + 1, rb_fd_ptr(&rfds), NULL, NULL, NULL);
|
2005-06-03 18:23:17 +04:00
|
|
|
#endif
|
2002-10-02 18:13:58 +04:00
|
|
|
return Qtrue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Qfalse;
|
|
|
|
}
|
2002-09-11 05:09:04 +04:00
|
|
|
}
|
|
|
|
|
2005-06-03 18:23:17 +04:00
|
|
|
#ifdef HAVE_RB_FD_INIT
|
|
|
|
static VALUE
|
2006-03-01 13:06:03 +03:00
|
|
|
wait_writable(VALUE p)
|
2005-06-03 18:23:17 +04:00
|
|
|
{
|
|
|
|
rb_fdset_t *wfds = (rb_fdset_t *)p;
|
|
|
|
|
|
|
|
return rb_thread_select(rb_fd_max(wfds), NULL, rb_fd_ptr(wfds), NULL, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-02 18:13:58 +04:00
|
|
|
int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_wait_writable(int f)
|
2002-09-11 05:09:04 +04:00
|
|
|
{
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fdset_t wfds;
|
2002-10-02 18:13:58 +04:00
|
|
|
|
2008-07-11 15:51:39 +04:00
|
|
|
if (f < 0) {
|
|
|
|
rb_raise(rb_eIOError, "closed stream");
|
|
|
|
}
|
2002-10-02 18:13:58 +04:00
|
|
|
switch (errno) {
|
|
|
|
case EINTR:
|
|
|
|
#if defined(ERESTART)
|
|
|
|
case ERESTART:
|
|
|
|
#endif
|
|
|
|
rb_thread_fd_writable(f);
|
|
|
|
return Qtrue;
|
|
|
|
|
|
|
|
case EAGAIN:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
#endif
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_init(&wfds);
|
|
|
|
rb_fd_set(f, &wfds);
|
|
|
|
#ifdef HAVE_RB_FD_INIT
|
|
|
|
rb_ensure(wait_writable, (VALUE)&wfds,
|
2005-09-14 12:30:16 +04:00
|
|
|
(VALUE (*)(VALUE))rb_fd_term, (VALUE)&wfds);
|
2005-06-03 18:23:17 +04:00
|
|
|
#else
|
2009-01-14 06:39:20 +03:00
|
|
|
rb_thread_select(f + 1, NULL, rb_fd_ptr(&wfds), NULL, NULL);
|
2005-06-03 18:23:17 +04:00
|
|
|
#endif
|
2002-10-02 18:13:58 +04:00
|
|
|
return Qtrue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Qfalse;
|
|
|
|
}
|
2002-09-11 05:09:04 +04:00
|
|
|
}
|
|
|
|
|
2008-08-25 20:49:31 +04:00
|
|
|
#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
|
2008-08-22 20:44:00 +04:00
|
|
|
/* Windows */
|
2008-09-09 16:22:43 +04:00
|
|
|
# define NEED_NEWLINE_DECORATOR_ON_READ(fptr) (!(fptr->mode & FMODE_BINMODE))
|
|
|
|
# define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) (!(fptr->mode & FMODE_BINMODE))
|
|
|
|
# define TEXTMODE_NEWLINE_DECORATOR_ON_WRITE ECONV_CRLF_NEWLINE_DECORATOR
|
2008-08-22 20:44:00 +04:00
|
|
|
#else
|
|
|
|
/* Unix */
|
2008-09-09 16:22:43 +04:00
|
|
|
# define NEED_NEWLINE_DECORATOR_ON_READ(fptr) (fptr->mode & FMODE_TEXTMODE)
|
|
|
|
# define NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) 0
|
2008-08-22 20:44:00 +04:00
|
|
|
#endif
|
2008-09-09 16:22:43 +04:00
|
|
|
#define NEED_READCONV(fptr) (fptr->encs.enc2 != NULL || NEED_NEWLINE_DECORATOR_ON_READ(fptr))
|
2008-10-20 20:57:19 +04:00
|
|
|
#define NEED_WRITECONV(fptr) ((fptr->encs.enc != NULL && fptr->encs.enc != rb_ascii8bit_encoding()) || NEED_NEWLINE_DECORATOR_ON_WRITE(fptr) || (fptr->encs.ecflags & (ECONV_DECORATOR_MASK|ECONV_STATEFUL_DECORATOR_MASK)))
|
2008-08-22 20:44:00 +04:00
|
|
|
|
2008-08-18 16:06:42 +04:00
|
|
|
static void
|
|
|
|
make_writeconv(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
if (!fptr->writeconv_initialized) {
|
|
|
|
const char *senc, *denc;
|
2008-08-18 17:35:55 +04:00
|
|
|
rb_encoding *enc;
|
2008-09-03 19:11:46 +04:00
|
|
|
int ecflags;
|
2008-09-03 22:18:10 +04:00
|
|
|
VALUE ecopts;
|
2008-08-22 20:44:00 +04:00
|
|
|
|
|
|
|
fptr->writeconv_initialized = 1;
|
|
|
|
|
2008-09-04 14:22:11 +04:00
|
|
|
ecflags = fptr->encs.ecflags;
|
2008-09-03 22:18:10 +04:00
|
|
|
ecopts = fptr->encs.ecopts;
|
2008-09-09 16:22:43 +04:00
|
|
|
#ifdef TEXTMODE_NEWLINE_DECORATOR_ON_WRITE
|
|
|
|
if (NEED_NEWLINE_DECORATOR_ON_WRITE(fptr))
|
|
|
|
ecflags |= TEXTMODE_NEWLINE_DECORATOR_ON_WRITE;
|
2008-09-07 07:13:29 +04:00
|
|
|
#endif
|
|
|
|
|
2008-10-20 20:57:19 +04:00
|
|
|
if (!fptr->encs.enc || (fptr->encs.enc == rb_ascii8bit_encoding() && !fptr->encs.enc2)) {
|
2008-09-07 07:13:29 +04:00
|
|
|
/* no encoding conversion */
|
|
|
|
fptr->writeconv_pre_ecflags = 0;
|
|
|
|
fptr->writeconv_pre_ecopts = Qnil;
|
2008-09-03 22:18:10 +04:00
|
|
|
fptr->writeconv = rb_econv_open_opts("", "", ecflags, ecopts);
|
2008-08-24 06:42:37 +04:00
|
|
|
if (!fptr->writeconv)
|
2008-09-03 19:11:46 +04:00
|
|
|
rb_exc_raise(rb_econv_open_exc("", "", ecflags));
|
2008-09-09 19:02:42 +04:00
|
|
|
fptr->writeconv_asciicompat = Qnil;
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-07 07:13:29 +04:00
|
|
|
enc = fptr->encs.enc2 ? fptr->encs.enc2 : fptr->encs.enc;
|
2008-09-13 13:06:51 +04:00
|
|
|
senc = rb_econv_asciicompat_encoding(rb_enc_name(enc));
|
2008-09-09 16:22:43 +04:00
|
|
|
if (!senc && !(fptr->encs.ecflags & ECONV_STATEFUL_DECORATOR_MASK)) {
|
2008-09-07 07:13:29 +04:00
|
|
|
/* single conversion */
|
|
|
|
fptr->writeconv_pre_ecflags = ecflags;
|
|
|
|
fptr->writeconv_pre_ecopts = ecopts;
|
|
|
|
fptr->writeconv = NULL;
|
2008-09-09 19:02:42 +04:00
|
|
|
fptr->writeconv_asciicompat = Qnil;
|
2008-09-07 07:13:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* double conversion */
|
2008-09-09 16:22:43 +04:00
|
|
|
fptr->writeconv_pre_ecflags = ecflags & ~ECONV_STATEFUL_DECORATOR_MASK;
|
2008-09-07 07:13:29 +04:00
|
|
|
fptr->writeconv_pre_ecopts = ecopts;
|
|
|
|
if (senc) {
|
2008-09-13 13:06:51 +04:00
|
|
|
denc = rb_enc_name(enc);
|
2008-09-09 19:02:42 +04:00
|
|
|
fptr->writeconv_asciicompat = rb_str_new2(senc);
|
2008-09-07 07:13:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
senc = denc = "";
|
2008-09-13 13:06:51 +04:00
|
|
|
fptr->writeconv_asciicompat = rb_str_new2(rb_enc_name(enc));
|
2008-09-07 07:13:29 +04:00
|
|
|
}
|
2008-09-09 16:22:43 +04:00
|
|
|
ecflags = fptr->encs.ecflags & (ECONV_ERROR_HANDLER_MASK|ECONV_STATEFUL_DECORATOR_MASK);
|
2008-09-07 07:13:29 +04:00
|
|
|
ecopts = fptr->encs.ecopts;
|
|
|
|
fptr->writeconv = rb_econv_open_opts(senc, denc, ecflags, ecopts);
|
|
|
|
if (!fptr->writeconv)
|
|
|
|
rb_exc_raise(rb_econv_open_exc(senc, denc, ecflags));
|
|
|
|
}
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/* writing functions */
|
2008-11-07 23:47:02 +03:00
|
|
|
struct binwrite_arg {
|
|
|
|
rb_io_t *fptr;
|
|
|
|
VALUE str;
|
|
|
|
long offset;
|
|
|
|
long length;
|
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
io_binwrite_string(VALUE arg)
|
|
|
|
{
|
|
|
|
struct binwrite_arg *p = (struct binwrite_arg *)arg;
|
|
|
|
long l = io_writable_length(p->fptr, p->length);
|
|
|
|
return rb_write_internal(p->fptr->fd, RSTRING_PTR(p->str)+p->offset, l);
|
|
|
|
}
|
2008-09-10 22:00:36 +04:00
|
|
|
|
2004-12-06 18:31:26 +03:00
|
|
|
static long
|
2008-09-23 15:55:48 +04:00
|
|
|
io_binwrite(VALUE str, rb_io_t *fptr, int nosync)
|
2002-12-20 12:29:41 +03:00
|
|
|
{
|
2008-11-07 23:47:02 +03:00
|
|
|
long len, n, r, offset = 0;
|
2002-12-20 12:29:41 +03:00
|
|
|
|
2006-08-31 14:47:44 +04:00
|
|
|
len = RSTRING_LEN(str);
|
2002-12-20 12:29:41 +03:00
|
|
|
if ((n = len) <= 0) return n;
|
2008-09-23 16:51:39 +04:00
|
|
|
if (fptr->wbuf == NULL && !(!nosync && (fptr->mode & FMODE_SYNC))) {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->wbuf_off = 0;
|
|
|
|
fptr->wbuf_len = 0;
|
|
|
|
fptr->wbuf_capa = 8192;
|
|
|
|
fptr->wbuf = ALLOC_N(char, fptr->wbuf_capa);
|
2008-11-07 23:47:02 +03:00
|
|
|
fptr->write_lock = rb_mutex_new();
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
2008-09-23 15:55:48 +04:00
|
|
|
if ((!nosync && (fptr->mode & (FMODE_SYNC|FMODE_TTY))) ||
|
2008-03-01 11:59:04 +03:00
|
|
|
(fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len)) {
|
2008-11-07 23:47:02 +03:00
|
|
|
struct binwrite_arg arg;
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
/* xxx: use writev to avoid double write if available */
|
2004-12-07 09:44:42 +03:00
|
|
|
if (fptr->wbuf_len && fptr->wbuf_len+len <= fptr->wbuf_capa) {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->wbuf_capa < fptr->wbuf_off+fptr->wbuf_len+len) {
|
|
|
|
MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len);
|
|
|
|
fptr->wbuf_off = 0;
|
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, RSTRING_PTR(str)+offset, char, len);
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->wbuf_len += (int)len;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
return -1L;
|
|
|
|
if (n == 0)
|
|
|
|
return len;
|
2004-12-07 09:44:42 +03:00
|
|
|
/* avoid context switch between "a" and "\n" in STDERR.puts "a".
|
|
|
|
[ruby-dev:25080] */
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->stdio_file != stderr && !rb_thread_fd_writable(fptr->fd)) {
|
2004-11-27 16:05:46 +03:00
|
|
|
rb_io_check_closed(fptr);
|
|
|
|
}
|
2008-11-07 23:47:02 +03:00
|
|
|
arg.fptr = fptr;
|
|
|
|
arg.str = str;
|
2004-11-27 16:05:46 +03:00
|
|
|
retry:
|
2008-12-05 01:59:25 +03:00
|
|
|
arg.offset = offset;
|
2008-11-07 23:47:02 +03:00
|
|
|
arg.length = n;
|
|
|
|
if (fptr->write_lock) {
|
|
|
|
r = rb_mutex_synchronize(fptr->write_lock, io_binwrite_string, (VALUE)&arg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
long l = io_writable_length(fptr, n);
|
|
|
|
r = rb_write_internal(fptr->fd, RSTRING_PTR(str)+offset, l);
|
|
|
|
}
|
2007-12-27 08:36:02 +03:00
|
|
|
/* xxx: other threads may modify given string. */
|
2004-11-27 16:05:46 +03:00
|
|
|
if (r == n) return len;
|
|
|
|
if (0 <= r) {
|
2004-12-06 18:31:26 +03:00
|
|
|
offset += r;
|
2004-11-27 16:05:46 +03:00
|
|
|
n -= r;
|
|
|
|
errno = EAGAIN;
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (rb_io_wait_writable(fptr->fd)) {
|
2004-11-27 16:05:46 +03:00
|
|
|
rb_io_check_closed(fptr);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (offset < RSTRING_LEN(str))
|
2004-12-06 18:31:26 +03:00
|
|
|
goto retry;
|
2004-11-27 16:05:46 +03:00
|
|
|
}
|
|
|
|
return -1L;
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
|
|
|
|
if (fptr->wbuf_off) {
|
|
|
|
if (fptr->wbuf_len)
|
|
|
|
MEMMOVE(fptr->wbuf, fptr->wbuf+fptr->wbuf_off, char, fptr->wbuf_len);
|
|
|
|
fptr->wbuf_off = 0;
|
2002-12-20 12:29:41 +03:00
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, RSTRING_PTR(str)+offset, char, len);
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->wbuf_len += (int)len;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
return len;
|
2002-12-20 12:29:41 +03:00
|
|
|
}
|
|
|
|
|
2008-09-23 15:55:48 +04:00
|
|
|
static VALUE
|
|
|
|
do_writeconv(VALUE str, rb_io_t *fptr)
|
2008-09-10 22:00:36 +04:00
|
|
|
{
|
|
|
|
if (NEED_WRITECONV(fptr)) {
|
|
|
|
VALUE common_encoding = Qnil;
|
2008-10-20 20:57:19 +04:00
|
|
|
|
2008-09-10 22:00:36 +04:00
|
|
|
make_writeconv(fptr);
|
|
|
|
|
|
|
|
if (fptr->writeconv) {
|
|
|
|
if (!NIL_P(fptr->writeconv_asciicompat))
|
|
|
|
common_encoding = fptr->writeconv_asciicompat;
|
|
|
|
else if (!rb_enc_asciicompat(rb_enc_get(str))) {
|
|
|
|
rb_raise(rb_eArgError, "ASCII incompatible string written for text mode IO without encoding conversion: %s",
|
|
|
|
rb_enc_name(rb_enc_get(str)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fptr->encs.enc2)
|
|
|
|
common_encoding = rb_enc_from_encoding(fptr->encs.enc2);
|
2008-10-20 20:57:19 +04:00
|
|
|
else if (fptr->encs.enc != rb_ascii8bit_encoding())
|
2008-09-10 22:00:36 +04:00
|
|
|
common_encoding = rb_enc_from_encoding(fptr->encs.enc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NIL_P(common_encoding)) {
|
2008-09-26 14:35:00 +04:00
|
|
|
str = rb_str_encode(str, common_encoding,
|
2008-09-10 22:00:36 +04:00
|
|
|
fptr->writeconv_pre_ecflags, fptr->writeconv_pre_ecopts);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fptr->writeconv) {
|
|
|
|
str = rb_econv_str_convert(fptr->writeconv, str, ECONV_PARTIAL_INPUT);
|
|
|
|
}
|
|
|
|
}
|
2008-09-23 15:55:48 +04:00
|
|
|
return str;
|
|
|
|
}
|
2008-09-10 22:00:36 +04:00
|
|
|
|
2008-09-23 15:55:48 +04:00
|
|
|
static long
|
|
|
|
io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
|
|
|
|
{
|
|
|
|
str = do_writeconv(str, fptr);
|
|
|
|
return io_binwrite(str, fptr, nosync);
|
2008-09-10 22:00:36 +04:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
2008-09-23 15:55:48 +04:00
|
|
|
io_write(VALUE io, VALUE str, int nosync)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-12-20 12:29:41 +03:00
|
|
|
long n;
|
2004-04-07 06:51:05 +04:00
|
|
|
VALUE tmp;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_secure(4);
|
2007-11-20 06:16:53 +03:00
|
|
|
io = GetWriteIO(io);
|
2004-04-07 06:51:05 +04:00
|
|
|
str = rb_obj_as_string(str);
|
|
|
|
tmp = rb_io_check_io(io);
|
|
|
|
if (NIL_P(tmp)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
/* port is not IO, call write method for it. */
|
1998-01-16 15:13:05 +03:00
|
|
|
return rb_funcall(io, id_write, 1, str);
|
|
|
|
}
|
2004-04-07 06:51:05 +04:00
|
|
|
io = tmp;
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) == 0) return INT2FIX(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_check_writable(fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-23 15:55:48 +04:00
|
|
|
n = io_fwrite(str, fptr, nosync);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (n == -1L) rb_sys_fail_path(fptr->pathv);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
return LONG2FIX(n);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-09-23 15:55:48 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.write(string) => integer
|
|
|
|
*
|
|
|
|
* Writes the given string to <em>ios</em>. The stream must be opened
|
|
|
|
* for writing. If the argument is not a string, it will be converted
|
|
|
|
* to a string using <code>to_s</code>. Returns the number of bytes
|
|
|
|
* written.
|
|
|
|
*
|
|
|
|
* count = $stdout.write( "This is a test\n" )
|
|
|
|
* puts "That was #{count} bytes of data"
|
|
|
|
*
|
|
|
|
* <em>produces:</em>
|
|
|
|
*
|
|
|
|
* This is a test
|
|
|
|
* That was 15 bytes of data
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
io_write_m(VALUE io, VALUE str)
|
|
|
|
{
|
|
|
|
return io_write(io, str, 0);
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_write(VALUE io, VALUE str)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
return rb_funcall(io, id_write, 1, str);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios << obj => ios
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* String Output---Writes <i>obj</i> to <em>ios</em>.
|
|
|
|
* <i>obj</i> will be converted to a string using
|
|
|
|
* <code>to_s</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* $stdout << "Hello " << "world!\n"
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Hello world!
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-02-20 09:35:37 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_addstr(VALUE io, VALUE str)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(io, str);
|
1998-01-16 15:13:05 +03:00
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.flush => ios
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Flushes any buffered data within <em>ios</em> to the underlying
|
|
|
|
* operating system (note that this is Ruby internal buffering only;
|
|
|
|
* the OS may buffer the data as well).
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* $stdout.print "no newline"
|
|
|
|
* $stdout.flush
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* no newline
|
|
|
|
*/
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_flush(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
|
|
|
|
if (TYPE(io) != T_FILE) {
|
|
|
|
return rb_funcall(io, id_flush, 0);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
io = GetWriteIO(io);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2002-03-29 17:50:09 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
2008-12-25 07:29:30 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
fsync(fptr->fd);
|
|
|
|
#endif
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
|
|
|
if (fptr->mode & FMODE_READABLE) {
|
|
|
|
io_unread(fptr);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.pos => integer
|
|
|
|
* ios.tell => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns the current offset (in bytes) of <em>ios</em>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.pos #=> 0
|
|
|
|
* f.gets #=> "This is line one\n"
|
|
|
|
* f.pos #=> 17
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_tell(VALUE io)
|
1999-01-20 07:59:39 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-03-14 09:23:46 +03:00
|
|
|
off_t pos;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
2002-10-02 18:59:25 +04:00
|
|
|
pos = io_tell(fptr);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (pos < 0 && errno) rb_sys_fail_path(fptr->pathv);
|
2002-03-27 08:28:00 +03:00
|
|
|
return OFFT2NUM(pos);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_seek(VALUE io, VALUE offset, int whence)
|
2001-03-13 08:45:13 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-04-18 12:46:18 +04:00
|
|
|
off_t pos;
|
2001-03-13 08:45:13 +03:00
|
|
|
|
2004-11-23 20:37:51 +03:00
|
|
|
pos = NUM2OFFT(offset);
|
2001-03-13 08:45:13 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2004-11-23 20:37:51 +03:00
|
|
|
pos = io_seek(fptr, pos, whence);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (pos < 0 && errno) rb_sys_fail_path(fptr->pathv);
|
2001-03-13 08:45:13 +03:00
|
|
|
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.seek(amount, whence=SEEK_SET) -> 0
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Seeks to a given offset <i>anInteger</i> in the stream according to
|
|
|
|
* the value of <i>whence</i>:
|
|
|
|
*
|
|
|
|
* IO::SEEK_CUR | Seeks to _amount_ plus current position
|
|
|
|
* --------------+----------------------------------------------------
|
2004-06-29 05:17:39 +04:00
|
|
|
* IO::SEEK_END | Seeks to _amount_ plus end of stream (you probably
|
2003-12-27 03:44:05 +03:00
|
|
|
* | want a negative value for _amount_)
|
|
|
|
* --------------+----------------------------------------------------
|
|
|
|
* IO::SEEK_SET | Seeks to the absolute location given by _amount_
|
|
|
|
*
|
|
|
|
* Example:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.seek(-13, IO::SEEK_END) #=> 0
|
|
|
|
* f.readline #=> "And so on...\n"
|
|
|
|
*/
|
|
|
|
|
2001-03-13 08:45:13 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_seek_m(int argc, VALUE *argv, VALUE io)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2000-06-12 11:48:31 +04:00
|
|
|
VALUE offset, ptrname;
|
2002-04-18 12:46:18 +04:00
|
|
|
int whence = SEEK_SET;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2002-04-18 12:46:18 +04:00
|
|
|
if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
|
|
|
|
whence = NUM2INT(ptrname);
|
|
|
|
}
|
2000-06-12 11:48:31 +04:00
|
|
|
|
2001-03-13 08:45:13 +03:00
|
|
|
return rb_io_seek(io, offset, whence);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2005-01-25 07:03:02 +03:00
|
|
|
* ios.pos = integer => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Seeks to the given position (in bytes) in <em>ios</em>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.pos = 17
|
|
|
|
* f.gets #=> "This is line two\n"
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_set_pos(VALUE io, VALUE offset)
|
1999-01-20 07:59:39 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-04-18 12:46:18 +04:00
|
|
|
off_t pos;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2004-11-23 20:37:51 +03:00
|
|
|
pos = NUM2OFFT(offset);
|
1999-01-20 07:59:39 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2004-11-23 20:37:51 +03:00
|
|
|
pos = io_seek(fptr, pos, SEEK_SET);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (pos < 0) rb_sys_fail_path(fptr->pathv);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2002-04-18 12:46:18 +04:00
|
|
|
return OFFT2NUM(pos);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2008-10-29 19:40:05 +03:00
|
|
|
static void clear_readconv(rb_io_t *fptr);
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.rewind => 0
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Positions <em>ios</em> to the beginning of input, resetting
|
|
|
|
* <code>lineno</code> to zero.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.readline #=> "This is line one\n"
|
|
|
|
* f.rewind #=> 0
|
|
|
|
* f.lineno #=> 0
|
|
|
|
* f.readline #=> "This is line one\n"
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_rewind(VALUE io)
|
1999-01-20 07:59:39 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail_path(fptr->pathv);
|
2008-03-01 11:59:04 +03:00
|
|
|
if (io == ARGF.current_file) {
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.lineno -= fptr->lineno;
|
2000-06-19 12:38:11 +04:00
|
|
|
}
|
|
|
|
fptr->lineno = 0;
|
2008-10-29 19:40:05 +03:00
|
|
|
if (fptr->readconv) {
|
|
|
|
clear_readconv(fptr);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
static int
|
* 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-25 07:29:39 +04:00
|
|
|
io_fillbuf(rb_io_t *fptr)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
{
|
2009-04-26 13:46:41 +04:00
|
|
|
ssize_t r;
|
* 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-25 07:29:39 +04:00
|
|
|
|
2009-01-21 07:56:06 +03:00
|
|
|
if (fptr->mode & FMODE_EOF) {
|
|
|
|
return -1;
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->rbuf == NULL) {
|
|
|
|
fptr->rbuf_off = 0;
|
|
|
|
fptr->rbuf_len = 0;
|
|
|
|
fptr->rbuf_capa = 8192;
|
|
|
|
fptr->rbuf = ALLOC_N(char, fptr->rbuf_capa);
|
|
|
|
}
|
|
|
|
if (fptr->rbuf_len == 0) {
|
|
|
|
retry:
|
2007-11-23 11:35:29 +03:00
|
|
|
{
|
|
|
|
r = rb_read_internal(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (r < 0) {
|
|
|
|
if (rb_io_wait_readable(fptr->fd))
|
|
|
|
goto retry;
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
|
|
|
fptr->rbuf_off = 0;
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->rbuf_len = (int)r; /* r should be <= rbuf_capa */
|
2009-01-21 07:56:06 +03:00
|
|
|
if (r == 0) {
|
|
|
|
io_set_eof(fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
return -1; /* EOF */
|
2009-01-21 07:56:06 +03:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
* 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-25 07:29:39 +04:00
|
|
|
return 0;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.eof => true or false
|
|
|
|
* ios.eof? => true or false
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2005-09-05 19:02:10 +04:00
|
|
|
* Returns true if <em>ios</em> is at end of file that means
|
|
|
|
* there are no more data to read.
|
|
|
|
* The stream must be opened for reading or an <code>IOError</code> will be
|
|
|
|
* raised.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* dummy = f.readlines
|
|
|
|
* f.eof #=> true
|
2005-09-05 19:02:10 +04:00
|
|
|
*
|
|
|
|
* If <em>ios</em> is a stream such as pipe or socket, <code>IO#eof?</code>
|
|
|
|
* blocks until the other end sends some data or closes it.
|
|
|
|
*
|
|
|
|
* r, w = IO.pipe
|
|
|
|
* Thread.new { sleep 1; w.close }
|
|
|
|
* r.eof? #=> true after 1 second blocking
|
|
|
|
*
|
|
|
|
* r, w = IO.pipe
|
|
|
|
* Thread.new { sleep 1; w.puts "a" }
|
|
|
|
* r.eof? #=> false after 1 second blocking
|
|
|
|
*
|
|
|
|
* r, w = IO.pipe
|
|
|
|
* r.eof? # blocks forever
|
|
|
|
*
|
|
|
|
* Note that <code>IO#eof?</code> reads data to a input buffer.
|
|
|
|
* So <code>IO#sysread</code> doesn't work with <code>IO#eof?</code>.
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_eof(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_check_readable(fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (READ_DATA_PENDING(fptr)) return Qfalse;
|
|
|
|
READ_CHECK(fptr);
|
* 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-25 07:29:39 +04:00
|
|
|
if (io_fillbuf(fptr) < 0) {
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
* 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-25 07:29:39 +04:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.sync => true or false
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns the current ``sync mode'' of <em>ios</em>. When sync mode is
|
|
|
|
* true, all output is immediately flushed to the underlying operating
|
|
|
|
* system and is not buffered by Ruby internally. See also
|
|
|
|
* <code>IO#fsync</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.sync #=> false
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_sync(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
io = GetWriteIO(io);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(io, fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
return (fptr->mode & FMODE_SYNC) ? Qtrue : Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.sync = boolean => boolean
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Sets the ``sync mode'' to <code>true</code> or <code>false</code>.
|
|
|
|
* When sync mode is true, all output is immediately flushed to the
|
|
|
|
* underlying operating system and is not buffered internally. Returns
|
|
|
|
* the new state. See also <code>IO#fsync</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.sync = true
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>(produces no output)</em>
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2008-09-04 15:20:53 +04:00
|
|
|
rb_io_set_sync(VALUE io, VALUE sync)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
io = GetWriteIO(io);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2008-09-04 15:20:53 +04:00
|
|
|
if (RTEST(sync)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->mode |= FMODE_SYNC;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fptr->mode &= ~FMODE_SYNC;
|
|
|
|
}
|
2008-09-04 15:20:53 +04:00
|
|
|
return sync;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2009-04-16 20:58:06 +04:00
|
|
|
#ifdef HAVE_FSYNC
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.fsync => 0 or nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Immediately writes all buffered data in <em>ios</em> to disk.
|
2009-06-22 20:25:50 +04:00
|
|
|
* Note that <code>fsync</code> differs from
|
2003-12-27 03:44:05 +03:00
|
|
|
* using <code>IO#sync=</code>. The latter ensures that data is flushed
|
|
|
|
* from Ruby's buffers, but doesn't not guarantee that the underlying
|
|
|
|
* operating system actually writes it to disk.
|
2009-06-22 20:25:50 +04:00
|
|
|
*
|
|
|
|
* <code>NotImplementedError</code> is raised
|
|
|
|
* if the underlying operating system does not support <em>fsync(2)</em>.
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
2002-01-23 10:30:43 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_fsync(VALUE io)
|
2002-01-23 10:30:43 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-01-23 10:30:43 +03:00
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
io = GetWriteIO(io);
|
2002-01-23 10:30:43 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2002-03-29 17:50:09 +03:00
|
|
|
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fsync(fptr->fd) < 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2002-01-23 10:30:43 +03:00
|
|
|
return INT2FIX(0);
|
2009-04-16 20:58:06 +04:00
|
|
|
}
|
2002-01-23 10:30:43 +03:00
|
|
|
#else
|
2009-04-16 20:58:06 +04:00
|
|
|
#define rb_io_fsync rb_f_notimplement
|
2002-01-23 10:30:43 +03:00
|
|
|
#endif
|
|
|
|
|
2009-06-22 08:50:29 +04:00
|
|
|
#ifdef HAVE_FDATASYNC
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.fdatasync => 0 or nil
|
|
|
|
*
|
|
|
|
* Immediately writes all buffered data in <em>ios</em> to disk.
|
2009-06-22 20:25:50 +04:00
|
|
|
*
|
|
|
|
* <code>NotImplementedError</code> is raised
|
|
|
|
* if the underlying operating system does not support <em>fdatasync(2)</em>.
|
2009-06-22 08:50:29 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_fdatasync(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
|
|
|
|
io = GetWriteIO(io);
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
|
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
|
|
|
if (fdatasync(fptr->fd) < 0)
|
|
|
|
rb_sys_fail_path(fptr->pathv);
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define rb_io_fdatasync rb_f_notimplement
|
|
|
|
#endif
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.fileno => fixnum
|
|
|
|
* ios.to_i => fixnum
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns an integer representing the numeric file descriptor for
|
|
|
|
* <em>ios</em>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* $stdin.fileno #=> 0
|
|
|
|
* $stdout.fileno #=> 1
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_fileno(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fd = fptr->fd;
|
1998-01-16 15:13:05 +03:00
|
|
|
return INT2FIX(fd);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.pid => fixnum
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns the process ID of a child process associated with
|
2008-12-03 18:02:49 +03:00
|
|
|
* <em>ios</em>. This will be set by <code>IO.popen</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* pipe = IO.popen("-")
|
|
|
|
* if pipe
|
|
|
|
* $stderr.puts "In parent, child pid is #{pipe.pid}"
|
|
|
|
* else
|
|
|
|
* $stderr.puts "In child, pid is #{$$}"
|
|
|
|
* end
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* In child, pid is 26209
|
|
|
|
* In parent, child pid is 26209
|
|
|
|
*/
|
|
|
|
|
2000-05-24 08:34:26 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_pid(VALUE io)
|
2000-05-24 08:34:26 +04: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2000-05-24 08:34:26 +04:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
if (!fptr->pid)
|
|
|
|
return Qnil;
|
2008-08-22 07:42:09 +04:00
|
|
|
return PIDT2NUM(fptr->pid);
|
2000-05-24 08:34:26 +04:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.inspect => string
|
|
|
|
*
|
|
|
|
* Return a string describing this IO object.
|
|
|
|
*/
|
|
|
|
|
2002-02-22 13:28:47 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_inspect(VALUE obj)
|
2002-02-22 13:28:47 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *cname;
|
2008-12-23 10:24:13 +03:00
|
|
|
char fd_desc[256];
|
|
|
|
const char *path;
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
const char *st = "";
|
2002-02-22 13:28:47 +03:00
|
|
|
|
2002-09-30 15:31:28 +04:00
|
|
|
fptr = RFILE(rb_io_taint_check(obj))->fptr;
|
2009-03-24 11:11:01 +03:00
|
|
|
if (!fptr) return rb_any_to_s(obj);
|
2003-01-31 07:00:17 +03:00
|
|
|
cname = rb_obj_classname(obj);
|
2009-03-24 11:11:01 +03:00
|
|
|
if (NIL_P(fptr->pathv)) {
|
2008-12-23 10:24:13 +03:00
|
|
|
if (fptr->fd < 0) {
|
|
|
|
path = "";
|
|
|
|
st = "(closed)";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
snprintf(fd_desc, sizeof(fd_desc), "fd %d", fptr->fd);
|
|
|
|
path = fd_desc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
path = RSTRING_PTR(fptr->pathv);
|
|
|
|
if (fptr->fd < 0) {
|
|
|
|
st = " (closed)";
|
|
|
|
}
|
2003-11-06 12:05:11 +03:00
|
|
|
}
|
2008-12-23 10:24:13 +03:00
|
|
|
return rb_sprintf("#<%s:%s%s>", cname, path, st);
|
2002-02-22 13:28:47 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.to_io -> ios
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns <em>ios</em>.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_to_io(VALUE io)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/* reading functions */
|
2004-08-11 20:57:14 +04:00
|
|
|
static long
|
* 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 13:30:50 +03:00
|
|
|
read_buffered_data(char *ptr, long len, rb_io_t *fptr)
|
2004-08-11 20:57:14 +04:00
|
|
|
{
|
2009-04-26 13:46:41 +04:00
|
|
|
int n;
|
2004-08-11 20:57:14 +04:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
n = READ_DATA_PENDING_COUNT(fptr);
|
2004-08-11 20:57:14 +04:00
|
|
|
if (n <= 0) return 0;
|
2009-04-26 13:46:41 +04:00
|
|
|
if (n > len) n = (int)len;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
MEMMOVE(ptr, fptr->rbuf+fptr->rbuf_off, char, n);
|
|
|
|
fptr->rbuf_off += n;
|
|
|
|
fptr->rbuf_len -= n;
|
2004-08-11 20:57:14 +04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2004-12-06 18:31:26 +03:00
|
|
|
static long
|
* 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 13:30:50 +03:00
|
|
|
io_fread(VALUE str, long offset, rb_io_t *fptr)
|
2000-07-14 11:18:58 +04:00
|
|
|
{
|
2006-08-31 14:47:44 +04:00
|
|
|
long len = RSTRING_LEN(str) - offset;
|
2000-11-20 10:31:55 +03:00
|
|
|
long n = len;
|
2009-04-26 13:46:41 +04:00
|
|
|
long c;
|
2000-07-14 11:18:58 +04:00
|
|
|
|
2008-06-11 18:54:23 +04:00
|
|
|
if (READ_DATA_PENDING(fptr) == 0) {
|
|
|
|
while (n > 0) {
|
2009-02-06 17:46:21 +03:00
|
|
|
again:
|
2008-06-11 18:54:23 +04:00
|
|
|
c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n);
|
2009-01-21 07:56:06 +03:00
|
|
|
if (c == 0) {
|
|
|
|
io_set_eof(fptr);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-11 18:54:23 +04:00
|
|
|
if (c < 0) {
|
2009-02-06 17:46:21 +03:00
|
|
|
if (rb_io_wait_readable(fptr->fd))
|
|
|
|
goto again;
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2008-06-11 18:54:23 +04:00
|
|
|
}
|
|
|
|
offset += c;
|
|
|
|
if ((n -= c) <= 0) break;
|
|
|
|
rb_thread_wait_fd(fptr->fd);
|
|
|
|
}
|
|
|
|
return len - n;
|
|
|
|
}
|
|
|
|
|
2001-07-24 13:07:33 +04:00
|
|
|
while (n > 0) {
|
2006-08-31 14:47:44 +04:00
|
|
|
c = read_buffered_data(RSTRING_PTR(str)+offset, n, fptr);
|
2004-08-11 20:57:14 +04:00
|
|
|
if (c > 0) {
|
2004-12-06 18:31:26 +03:00
|
|
|
offset += c;
|
2004-08-11 20:57:14 +04:00
|
|
|
if ((n -= c) <= 0) break;
|
2001-07-24 13:07:33 +04:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_thread_wait_fd(fptr->fd);
|
2004-11-27 05:21:53 +03:00
|
|
|
rb_io_check_closed(fptr);
|
* 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-25 07:29:39 +04:00
|
|
|
if (io_fillbuf(fptr) < 0) {
|
2000-07-14 11:18:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-07-24 13:07:33 +04:00
|
|
|
return len - n;
|
2000-07-14 11:18:58 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
#define SMALLBUF 100
|
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
static long
|
* 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 13:30:50 +03:00
|
|
|
remain_size(rb_io_t *fptr)
|
2002-03-25 17:50:40 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
struct stat st;
|
2005-01-11 14:59:00 +03:00
|
|
|
off_t siz = READ_DATA_PENDING_COUNT(fptr);
|
2002-04-24 08:54:16 +04:00
|
|
|
off_t pos;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fstat(fptr->fd, &st) == 0 && S_ISREG(st.st_mode)
|
1999-01-20 07:59:39 +03:00
|
|
|
#ifdef __BEOS__
|
|
|
|
&& (st.st_dev > 3)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
2005-01-11 14:59:00 +03:00
|
|
|
pos = lseek(fptr->fd, 0, SEEK_CUR);
|
2003-12-05 00:57:35 +03:00
|
|
|
if (st.st_size >= pos && pos >= 0) {
|
2008-06-11 18:54:23 +04:00
|
|
|
siz += st.st_size - pos;
|
2002-03-25 09:18:07 +03:00
|
|
|
if (siz > LONG_MAX) {
|
|
|
|
rb_raise(rb_eIOError, "file too big for single read");
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-11 14:59:00 +03:00
|
|
|
else {
|
|
|
|
siz += BUFSIZ;
|
|
|
|
}
|
2002-03-25 17:50:40 +03:00
|
|
|
return (long)siz;
|
|
|
|
}
|
|
|
|
|
2007-12-13 02:46:58 +03:00
|
|
|
static VALUE
|
|
|
|
io_enc_str(VALUE str, rb_io_t *fptr)
|
2008-08-18 05:40:01 +04:00
|
|
|
{
|
|
|
|
OBJ_TAINT(str);
|
|
|
|
rb_enc_associate(str, io_read_encoding(fptr));
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2008-08-18 07:13:53 +04:00
|
|
|
static void
|
2008-10-28 14:18:28 +03:00
|
|
|
make_readconv(rb_io_t *fptr, int size)
|
2008-08-18 07:13:53 +04:00
|
|
|
{
|
|
|
|
if (!fptr->readconv) {
|
2008-09-03 19:11:46 +04:00
|
|
|
int ecflags;
|
2008-09-03 22:18:10 +04:00
|
|
|
VALUE ecopts;
|
2008-08-22 20:44:00 +04:00
|
|
|
const char *sname, *dname;
|
2008-09-04 14:22:11 +04:00
|
|
|
ecflags = fptr->encs.ecflags;
|
2008-09-03 22:18:10 +04:00
|
|
|
ecopts = fptr->encs.ecopts;
|
2008-09-09 16:22:43 +04:00
|
|
|
if (NEED_NEWLINE_DECORATOR_ON_READ(fptr))
|
|
|
|
ecflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;
|
2008-08-24 11:49:13 +04:00
|
|
|
if (fptr->encs.enc2) {
|
2008-09-13 13:06:51 +04:00
|
|
|
sname = rb_enc_name(fptr->encs.enc2);
|
|
|
|
dname = rb_enc_name(fptr->encs.enc);
|
2008-08-22 20:44:00 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sname = dname = "";
|
|
|
|
}
|
2008-09-03 22:18:10 +04:00
|
|
|
fptr->readconv = rb_econv_open_opts(sname, dname, ecflags, ecopts);
|
2008-08-18 07:13:53 +04:00
|
|
|
if (!fptr->readconv)
|
2008-09-03 19:11:46 +04:00
|
|
|
rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags));
|
2008-08-26 19:06:28 +04:00
|
|
|
fptr->cbuf_off = 0;
|
|
|
|
fptr->cbuf_len = 0;
|
2008-10-28 14:18:28 +03:00
|
|
|
fptr->cbuf_capa = size < 1024 ? 1024 : size;
|
2008-08-26 19:06:28 +04:00
|
|
|
fptr->cbuf = ALLOC_N(char, fptr->cbuf_capa);
|
2008-08-18 07:13:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
more_char(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
const unsigned char *ss, *sp, *se;
|
|
|
|
unsigned char *ds, *dp, *de;
|
|
|
|
rb_econv_result_t res;
|
|
|
|
int putbackable;
|
2008-08-26 19:06:28 +04:00
|
|
|
int cbuf_len0;
|
2008-08-18 07:13:53 +04:00
|
|
|
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_len == fptr->cbuf_capa)
|
|
|
|
return 0; /* cbuf full */
|
|
|
|
if (fptr->cbuf_len == 0)
|
|
|
|
fptr->cbuf_off = 0;
|
|
|
|
else if (fptr->cbuf_off + fptr->cbuf_len == fptr->cbuf_capa) {
|
|
|
|
memmove(fptr->cbuf, fptr->cbuf+fptr->cbuf_off, fptr->cbuf_len);
|
|
|
|
fptr->cbuf_off = 0;
|
2008-08-18 07:13:53 +04:00
|
|
|
}
|
|
|
|
|
2008-08-26 19:06:28 +04:00
|
|
|
cbuf_len0 = fptr->cbuf_len;
|
2008-08-18 07:13:53 +04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ss = sp = (const unsigned char *)fptr->rbuf + fptr->rbuf_off;
|
|
|
|
se = sp + fptr->rbuf_len;
|
2008-08-26 19:06:28 +04:00
|
|
|
ds = dp = (unsigned char *)fptr->cbuf + fptr->cbuf_off + fptr->cbuf_len;
|
|
|
|
de = (unsigned char *)fptr->cbuf + fptr->cbuf_capa;
|
2008-09-09 20:27:02 +04:00
|
|
|
res = rb_econv_convert(fptr->readconv, &sp, se, &dp, de, ECONV_PARTIAL_INPUT|ECONV_AFTER_OUTPUT);
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->rbuf_off += (int)(sp - ss);
|
|
|
|
fptr->rbuf_len -= (int)(sp - ss);
|
|
|
|
fptr->cbuf_len += (int)(dp - ds);
|
2008-08-18 07:13:53 +04:00
|
|
|
|
|
|
|
putbackable = rb_econv_putbackable(fptr->readconv);
|
|
|
|
if (putbackable) {
|
|
|
|
rb_econv_putback(fptr->readconv, (unsigned char *)fptr->rbuf + fptr->rbuf_off - putbackable, putbackable);
|
|
|
|
fptr->rbuf_off -= putbackable;
|
|
|
|
fptr->rbuf_len += putbackable;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_econv_check_error(fptr->readconv);
|
|
|
|
|
2008-08-26 19:06:28 +04:00
|
|
|
if (cbuf_len0 != fptr->cbuf_len)
|
2008-08-18 07:13:53 +04:00
|
|
|
return 0;
|
|
|
|
|
2008-10-29 19:40:05 +03:00
|
|
|
if (res == econv_finished) {
|
|
|
|
clear_readconv(fptr);
|
2008-08-18 07:13:53 +04:00
|
|
|
return -1;
|
2008-10-29 19:40:05 +03:00
|
|
|
}
|
2008-08-18 07:13:53 +04:00
|
|
|
|
|
|
|
if (res == econv_source_buffer_empty) {
|
|
|
|
if (fptr->rbuf_len == 0) {
|
|
|
|
rb_thread_wait_fd(fptr->fd);
|
|
|
|
rb_io_check_closed(fptr);
|
|
|
|
if (io_fillbuf(fptr) == -1) {
|
2008-08-26 19:06:28 +04:00
|
|
|
ds = dp = (unsigned char *)fptr->cbuf + fptr->cbuf_off + fptr->cbuf_len;
|
|
|
|
de = (unsigned char *)fptr->cbuf + fptr->cbuf_capa;
|
2008-08-18 07:13:53 +04:00
|
|
|
res = rb_econv_convert(fptr->readconv, NULL, NULL, &dp, de, 0);
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->cbuf_len += (int)(dp - ds);
|
2008-08-18 07:13:53 +04:00
|
|
|
rb_econv_check_error(fptr->readconv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-08-26 19:06:28 +04:00
|
|
|
io_shift_cbuf(rb_io_t *fptr, int len, VALUE *strp)
|
2008-08-18 07:13:53 +04:00
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
if (NIL_P(*strp)) {
|
2008-08-26 19:06:28 +04:00
|
|
|
*strp = str = rb_str_new(fptr->cbuf+fptr->cbuf_off, len);
|
2008-08-18 07:13:53 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
size_t slen;
|
|
|
|
str = *strp;
|
|
|
|
slen = RSTRING_LEN(str);
|
|
|
|
rb_str_resize(str, RSTRING_LEN(str) + len);
|
2008-08-26 19:06:28 +04:00
|
|
|
memcpy(RSTRING_PTR(str)+slen, fptr->cbuf+fptr->cbuf_off, len);
|
2008-08-18 07:13:53 +04:00
|
|
|
}
|
2008-08-26 19:06:28 +04:00
|
|
|
fptr->cbuf_off += len;
|
|
|
|
fptr->cbuf_len -= len;
|
2008-08-18 07:13:53 +04:00
|
|
|
OBJ_TAINT(str);
|
2008-08-24 11:49:13 +04:00
|
|
|
rb_enc_associate(str, fptr->encs.enc);
|
2008-08-18 07:13:53 +04:00
|
|
|
/* xxx: set coderange */
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_len == 0)
|
|
|
|
fptr->cbuf_off = 0;
|
|
|
|
if (fptr->cbuf_off < fptr->cbuf_capa/2) {
|
|
|
|
memmove(fptr->cbuf, fptr->cbuf+fptr->cbuf_off, fptr->cbuf_len);
|
|
|
|
fptr->cbuf_off = 0;
|
2008-08-18 07:13:53 +04:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
static VALUE
|
* 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 13:30:50 +03:00
|
|
|
read_all(rb_io_t *fptr, long siz, VALUE str)
|
2002-12-11 12:32:41 +03:00
|
|
|
{
|
2008-08-18 07:13:53 +04:00
|
|
|
long bytes;
|
2002-04-24 08:54:16 +04:00
|
|
|
long n;
|
2008-08-18 07:13:53 +04:00
|
|
|
long pos;
|
|
|
|
rb_encoding *enc;
|
|
|
|
int cr;
|
|
|
|
|
2008-08-22 20:44:00 +04:00
|
|
|
if (NEED_READCONV(fptr)) {
|
2008-10-27 04:03:22 +03:00
|
|
|
if (NIL_P(str)) str = rb_str_new(NULL, 0);
|
|
|
|
else rb_str_set_len(str, 0);
|
2008-10-28 14:18:28 +03:00
|
|
|
make_readconv(fptr, 0);
|
2008-08-18 07:13:53 +04:00
|
|
|
while (1) {
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_len) {
|
|
|
|
io_shift_cbuf(fptr, fptr->cbuf_len, &str);
|
2008-08-18 07:13:53 +04:00
|
|
|
}
|
|
|
|
if (more_char(fptr) == -1) {
|
2008-08-18 07:47:15 +04:00
|
|
|
return io_enc_str(str, fptr);
|
2008-08-18 07:13:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes = 0;
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
enc = io_read_encoding(fptr);
|
2008-08-23 05:14:33 +04:00
|
|
|
cr = 0;
|
2002-03-25 17:50:40 +03:00
|
|
|
|
2003-12-05 00:57:35 +03:00
|
|
|
if (siz == 0) siz = BUFSIZ;
|
2002-12-11 12:32:41 +03:00
|
|
|
if (NIL_P(str)) {
|
2004-11-25 04:58:31 +03:00
|
|
|
str = rb_str_new(0, siz);
|
2002-12-11 12:32:41 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_str_resize(str, siz);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
for (;;) {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
READ_CHECK(fptr);
|
2004-12-06 18:31:26 +03:00
|
|
|
n = io_fread(str, bytes, fptr);
|
2003-12-05 00:57:35 +03:00
|
|
|
if (n == 0 && bytes == 0) {
|
2008-02-27 18:19:22 +03:00
|
|
|
break;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
bytes += n;
|
2008-02-27 18:19:22 +03:00
|
|
|
if (cr != ENC_CODERANGE_BROKEN)
|
|
|
|
pos = rb_str_coderange_scan_restartable(RSTRING_PTR(str) + pos, RSTRING_PTR(str) + bytes, enc, &cr);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (bytes < siz) break;
|
1998-01-16 15:19:22 +03:00
|
|
|
siz += BUFSIZ;
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_str_resize(str, siz);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (bytes != siz) rb_str_resize(str, bytes);
|
2008-02-27 18:19:22 +03:00
|
|
|
str = io_enc_str(str, fptr);
|
2008-08-23 05:14:33 +04:00
|
|
|
ENC_CODERANGE_SET(str, cr);
|
2008-02-27 18:19:22 +03:00
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2007-12-25 08:11:59 +03:00
|
|
|
void
|
|
|
|
rb_io_set_nonblock(rb_io_t *fptr)
|
2006-05-22 11:38:42 +04:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags;
|
2006-05-22 11:38:42 +04:00
|
|
|
#ifdef F_GETFL
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = fcntl(fptr->fd, F_GETFL);
|
|
|
|
if (oflags == -1) {
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2006-05-22 11:38:42 +04:00
|
|
|
}
|
|
|
|
#else
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = 0;
|
2006-05-22 11:38:42 +04:00
|
|
|
#endif
|
2008-09-05 15:30:35 +04:00
|
|
|
if ((oflags & O_NONBLOCK) == 0) {
|
|
|
|
oflags |= O_NONBLOCK;
|
|
|
|
if (fcntl(fptr->fd, F_SETFL, oflags) == -1) {
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2006-05-23 02:12:57 +04:00
|
|
|
}
|
2006-05-22 11:38:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-01 14:25:43 +03:00
|
|
|
static VALUE
|
2006-05-22 11:38:42 +04:00
|
|
|
io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
|
2005-01-01 14:25:43 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2005-01-01 14:25:43 +03:00
|
|
|
VALUE length, str;
|
|
|
|
long n, len;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &length, &str);
|
|
|
|
|
|
|
|
if ((len = NUM2LONG(length)) < 0) {
|
|
|
|
rb_raise(rb_eArgError, "negative length %ld given", len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NIL_P(str)) {
|
|
|
|
str = rb_str_new(0, len);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StringValue(str);
|
|
|
|
rb_str_modify(str);
|
|
|
|
rb_str_resize(str, len);
|
|
|
|
}
|
|
|
|
OBJ_TAINT(str);
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
return str;
|
|
|
|
|
2006-05-22 11:38:42 +04:00
|
|
|
if (!nonblock)
|
|
|
|
READ_CHECK(fptr);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) != len) {
|
2005-01-01 14:25:43 +03:00
|
|
|
modified:
|
|
|
|
rb_raise(rb_eRuntimeError, "buffer string modified");
|
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
n = read_buffered_data(RSTRING_PTR(str), len, fptr);
|
2005-01-01 14:25:43 +03:00
|
|
|
if (n <= 0) {
|
|
|
|
again:
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) != len) goto modified;
|
2006-05-22 11:38:42 +04:00
|
|
|
if (nonblock) {
|
|
|
|
rb_io_set_nonblock(fptr);
|
|
|
|
}
|
2008-07-11 15:51:39 +04:00
|
|
|
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len);
|
2005-01-01 14:25:43 +03:00
|
|
|
if (n < 0) {
|
2006-05-22 11:38:42 +04:00
|
|
|
if (!nonblock && rb_io_wait_readable(fptr->fd))
|
2005-01-01 14:25:43 +03:00
|
|
|
goto again;
|
2009-03-19 14:40:38 +03:00
|
|
|
if (nonblock && (errno == EWOULDBLOCK || errno == EAGAIN))
|
|
|
|
rb_mod_sys_fail(rb_mWaitReadable, "read would block");
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2005-01-01 14:25:43 +03:00
|
|
|
}
|
2009-01-21 07:56:06 +03:00
|
|
|
else if (n == 0) {
|
|
|
|
io_set_eof(fptr);
|
|
|
|
}
|
2005-01-01 14:25:43 +03:00
|
|
|
}
|
|
|
|
rb_str_resize(str, n);
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
return Qnil;
|
|
|
|
else
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2004-08-11 20:57:14 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-05-13 11:43:41 +04:00
|
|
|
* ios.readpartial(maxlen) => string
|
|
|
|
* ios.readpartial(maxlen, outbuf) => outbuf
|
2004-08-11 20:57:14 +04:00
|
|
|
*
|
2006-05-13 11:43:41 +04:00
|
|
|
* Reads at most <i>maxlen</i> bytes from the I/O stream.
|
|
|
|
* It blocks only if <em>ios</em> has no data immediately available.
|
|
|
|
* It doesn't block if some data available.
|
2004-08-11 20:57:14 +04:00
|
|
|
* If the optional <i>outbuf</i> argument is present,
|
|
|
|
* it must reference a String, which will receive the data.
|
|
|
|
* It raises <code>EOFError</code> on end of file.
|
|
|
|
*
|
2004-09-19 22:42:32 +04:00
|
|
|
* readpartial is designed for streams such as pipe, socket, tty, etc.
|
2004-08-11 20:57:14 +04:00
|
|
|
* It blocks only when no data immediately available.
|
|
|
|
* This means that it blocks only when following all conditions hold.
|
2005-01-08 21:18:36 +03:00
|
|
|
* * the buffer in the IO object is empty.
|
2004-08-11 20:57:14 +04:00
|
|
|
* * the content of the stream is empty.
|
|
|
|
* * the stream is not reached to EOF.
|
|
|
|
*
|
|
|
|
* When readpartial blocks, it waits data or EOF on the stream.
|
|
|
|
* If some data is reached, readpartial returns with the data.
|
|
|
|
* If EOF is reached, readpartial raises EOFError.
|
|
|
|
*
|
|
|
|
* When readpartial doesn't blocks, it returns or raises immediately.
|
2005-01-08 21:18:36 +03:00
|
|
|
* If the buffer is not empty, it returns the data in the buffer.
|
2004-08-11 20:57:14 +04:00
|
|
|
* Otherwise if the stream has some content,
|
2008-03-19 18:29:09 +03:00
|
|
|
* it returns the data in the stream.
|
2004-08-11 20:57:14 +04:00
|
|
|
* Otherwise if the stream is reached to EOF, it raises EOFError.
|
|
|
|
*
|
2005-01-08 21:18:36 +03:00
|
|
|
* r, w = IO.pipe # buffer pipe content
|
2004-08-11 20:57:14 +04:00
|
|
|
* w << "abc" # "" "abc".
|
|
|
|
* r.readpartial(4096) #=> "abc" "" ""
|
|
|
|
* r.readpartial(4096) # blocks because buffer and pipe is empty.
|
|
|
|
*
|
2005-01-08 21:18:36 +03:00
|
|
|
* r, w = IO.pipe # buffer pipe content
|
2004-08-11 20:57:14 +04:00
|
|
|
* w << "abc" # "" "abc"
|
|
|
|
* w.close # "" "abc" EOF
|
|
|
|
* r.readpartial(4096) #=> "abc" "" EOF
|
|
|
|
* r.readpartial(4096) # raises EOFError
|
|
|
|
*
|
2005-01-08 21:18:36 +03:00
|
|
|
* r, w = IO.pipe # buffer pipe content
|
2004-08-11 20:57:14 +04:00
|
|
|
* w << "abc\ndef\n" # "" "abc\ndef\n"
|
|
|
|
* r.gets #=> "abc\n" "def\n" ""
|
|
|
|
* w << "ghi\n" # "def\n" "ghi\n"
|
|
|
|
* r.readpartial(4096) #=> "def\n" "" "ghi\n"
|
|
|
|
* r.readpartial(4096) #=> "ghi\n" "" ""
|
|
|
|
*
|
2006-05-13 11:43:41 +04:00
|
|
|
* Note that readpartial behaves similar to sysread.
|
|
|
|
* The differences are:
|
|
|
|
* * If the buffer is not empty, read from the buffer instead of "sysread for buffered IO (IOError)".
|
2008-10-08 14:06:16 +04:00
|
|
|
* * It doesn't cause Errno::EWOULDBLOCK and Errno::EINTR. When readpartial meets EWOULDBLOCK and EINTR by read system call, readpartial retry the system call.
|
2004-08-11 20:57:14 +04:00
|
|
|
*
|
2006-05-13 11:43:41 +04:00
|
|
|
* The later means that readpartial is nonblocking-flag insensitive.
|
2008-10-08 14:06:16 +04:00
|
|
|
* It blocks on the situation IO#sysread causes Errno::EWOULDBLOCK as if the fd is blocking mode.
|
2004-08-11 20:57:14 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_readpartial(int argc, VALUE *argv, VALUE io)
|
2004-08-11 20:57:14 +04:00
|
|
|
{
|
2005-01-01 14:25:43 +03:00
|
|
|
VALUE ret;
|
2004-08-11 20:57:14 +04:00
|
|
|
|
2006-05-22 11:38:42 +04:00
|
|
|
ret = io_getpartial(argc, argv, io, 0);
|
2005-01-01 14:25:43 +03:00
|
|
|
if (NIL_P(ret))
|
2004-08-11 20:57:14 +04:00
|
|
|
rb_eof_error();
|
|
|
|
else
|
2005-01-01 14:25:43 +03:00
|
|
|
return ret;
|
2004-08-11 20:57:14 +04:00
|
|
|
}
|
|
|
|
|
2006-05-22 11:38:42 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.read_nonblock(maxlen) => string
|
|
|
|
* ios.read_nonblock(maxlen, outbuf) => outbuf
|
|
|
|
*
|
|
|
|
* Reads at most <i>maxlen</i> bytes from <em>ios</em> using
|
2008-10-15 13:15:46 +04:00
|
|
|
* the read(2) system call after O_NONBLOCK is set for
|
2006-05-22 11:38:42 +04:00
|
|
|
* the underlying file descriptor.
|
|
|
|
*
|
|
|
|
* If the optional <i>outbuf</i> argument is present,
|
|
|
|
* it must reference a String, which will receive the data.
|
|
|
|
*
|
2008-10-15 13:15:46 +04:00
|
|
|
* read_nonblock just calls the read(2) system call.
|
|
|
|
* It causes all errors the read(2) system call causes: Errno::EWOULDBLOCK, Errno::EINTR, etc.
|
2006-05-22 11:38:42 +04:00
|
|
|
* The caller should care such errors.
|
|
|
|
*
|
2009-03-19 14:40:38 +03:00
|
|
|
* If the exception is Errno::EWOULDBLOCK or Errno::AGAIN,
|
|
|
|
* it is extended by IO::WaitReadable.
|
|
|
|
* So IO::WaitReadable can be used to rescue the exceptions for retrying read_nonblock.
|
|
|
|
*
|
2006-05-22 11:38:42 +04:00
|
|
|
* read_nonblock causes EOFError on EOF.
|
|
|
|
*
|
|
|
|
* If the read buffer is not empty,
|
|
|
|
* read_nonblock reads from the buffer like readpartial.
|
2008-10-15 13:15:46 +04:00
|
|
|
* In this case, the read(2) system call is not called.
|
2006-05-22 11:38:42 +04:00
|
|
|
*
|
2009-03-19 14:40:38 +03:00
|
|
|
* When read_nonblock raises an exception kind of IO::WaitReadable,
|
2008-10-15 13:15:46 +04:00
|
|
|
* read_nonblock should not be called
|
|
|
|
* until io is readable for avoiding busy loop.
|
|
|
|
* This can be done as follows.
|
2008-10-11 17:44:31 +04:00
|
|
|
*
|
|
|
|
* begin
|
|
|
|
* result = io.read_nonblock(maxlen)
|
2009-03-19 14:40:38 +03:00
|
|
|
* rescue IO::WaitReadable, Errno::EINTR
|
2008-10-11 17:44:31 +04:00
|
|
|
* IO.select([io])
|
|
|
|
* retry
|
|
|
|
* end
|
2008-10-15 13:15:46 +04:00
|
|
|
*
|
|
|
|
* Note that this is identical to readpartial
|
|
|
|
* except the non-blocking flag is set.
|
2006-05-22 11:38:42 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
io_read_nonblock(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
VALUE ret;
|
|
|
|
|
|
|
|
ret = io_getpartial(argc, argv, io, 1);
|
|
|
|
if (NIL_P(ret))
|
|
|
|
rb_eof_error();
|
|
|
|
else
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.write_nonblock(string) => integer
|
|
|
|
*
|
|
|
|
* Writes the given string to <em>ios</em> using
|
2008-10-15 13:15:46 +04:00
|
|
|
* the write(2) system call after O_NONBLOCK is set for
|
2006-05-22 11:38:42 +04:00
|
|
|
* the underlying file descriptor.
|
|
|
|
*
|
2008-09-03 23:05:24 +04:00
|
|
|
* It returns the number of bytes written.
|
|
|
|
*
|
2008-10-15 13:15:46 +04:00
|
|
|
* write_nonblock just calls the write(2) system call.
|
|
|
|
* It causes all errors the write(2) system call causes: Errno::EWOULDBLOCK, Errno::EINTR, etc.
|
2006-05-22 11:38:42 +04:00
|
|
|
* The result may also be smaller than string.length (partial write).
|
|
|
|
* The caller should care such errors and partial write.
|
|
|
|
*
|
2009-03-19 14:40:38 +03:00
|
|
|
* If the exception is Errno::EWOULDBLOCK or Errno::AGAIN,
|
|
|
|
* it is extended by IO::WaitWritable.
|
|
|
|
* So IO::WaitWritable can be used to rescue the exceptions for retrying write_nonblock.
|
|
|
|
*
|
2009-01-31 08:12:23 +03:00
|
|
|
* # Creates a pipe.
|
|
|
|
* r, w = IO.pipe
|
|
|
|
*
|
|
|
|
* # write_nonblock writes only 65536 bytes and return 65536.
|
|
|
|
* # (The pipe size is 65536 bytes on this environment.)
|
|
|
|
* s = "a" * 100000
|
|
|
|
* p w.write_nonblock(s) #=> 65536
|
|
|
|
*
|
|
|
|
* # write_nonblock cannot write a byte and raise EWOULDBLOCK (EAGAIN).
|
|
|
|
* p w.write_nonblock("b") # Resource temporarily unavailable (Errno::EAGAIN)
|
|
|
|
*
|
2006-05-22 11:38:42 +04:00
|
|
|
* If the write buffer is not empty, it is flushed at first.
|
|
|
|
*
|
2009-03-19 14:40:38 +03:00
|
|
|
* When write_nonblock raises an exception kind of IO::WaitWritable,
|
2008-10-15 13:15:46 +04:00
|
|
|
* write_nonblock should not be called
|
|
|
|
* until io is writable for avoiding busy loop.
|
|
|
|
* This can be done as follows.
|
2008-10-11 17:44:31 +04:00
|
|
|
*
|
|
|
|
* begin
|
|
|
|
* result = io.write_nonblock(string)
|
2009-03-19 14:40:38 +03:00
|
|
|
* rescue IO::WaitWritable, Errno::EINTR
|
2008-10-11 17:44:31 +04:00
|
|
|
* IO.select(nil, [io])
|
|
|
|
* retry
|
|
|
|
* end
|
2008-10-15 13:15:46 +04:00
|
|
|
*
|
|
|
|
* Note that this doesn't guarantee to write all data in string.
|
|
|
|
* The length written is reported as result and it should be checked later.
|
|
|
|
*
|
2006-05-22 11:38:42 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_write_nonblock(VALUE io, VALUE str)
|
|
|
|
{
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2006-05-22 11:38:42 +04:00
|
|
|
long n;
|
|
|
|
|
|
|
|
rb_secure(4);
|
|
|
|
if (TYPE(str) != T_STRING)
|
|
|
|
str = rb_obj_as_string(str);
|
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
io = GetWriteIO(io);
|
2006-05-22 11:38:42 +04:00
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_writable(fptr);
|
|
|
|
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
2006-05-22 11:38:42 +04:00
|
|
|
|
|
|
|
rb_io_set_nonblock(fptr);
|
2006-08-31 14:47:44 +04:00
|
|
|
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
|
2006-05-22 11:38:42 +04:00
|
|
|
|
2009-02-21 18:57:52 +03:00
|
|
|
if (n == -1) {
|
2009-03-19 14:40:38 +03:00
|
|
|
if (errno == EWOULDBLOCK || errno == EAGAIN)
|
|
|
|
rb_mod_sys_fail(rb_mWaitWritable, "write would block");
|
2009-02-21 18:57:52 +03:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
|
|
|
}
|
2006-05-22 11:38:42 +04:00
|
|
|
|
|
|
|
return LONG2FIX(n);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2005-01-24 14:43:12 +03:00
|
|
|
* ios.read([length [, buffer]]) => string, buffer, or nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2009-03-17 04:37:57 +03:00
|
|
|
* Reads <i>length</i> bytes from the I/O stream.
|
|
|
|
*
|
2005-01-24 14:43:12 +03:00
|
|
|
* <i>length</i> must be a non-negative integer or nil.
|
2009-03-17 04:37:57 +03:00
|
|
|
*
|
|
|
|
* If <i>length</i> is a positive integer,
|
2009-03-17 13:27:17 +03:00
|
|
|
* it try to read <i>length</i> bytes.
|
|
|
|
* It returns nil or a string which length is 1 to <i>length</i> bytes.
|
|
|
|
* nil means it met EOF at beginning.
|
|
|
|
* The 1 to <i>length</i>-1 bytes string means it met EOF after reading the result.
|
|
|
|
* The <i>length</i> bytes string means it doesn't meet EOF.
|
2009-03-17 04:37:57 +03:00
|
|
|
*
|
|
|
|
* If <i>length</i> is omitted or is <code>nil</code>,
|
|
|
|
* it reads until EOF.
|
|
|
|
* It returns a string even if EOF is met at beginning.
|
|
|
|
*
|
|
|
|
* If <i>length</i> is zero, it returns <code>""</code>.
|
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* If the optional <i>buffer</i> argument is present, it must reference
|
2005-01-24 14:43:12 +03:00
|
|
|
* a String, which will receive the data.
|
|
|
|
*
|
|
|
|
* At end of file, it returns <code>nil</code> or <code>""</code>
|
|
|
|
* depend on <i>length</i>.
|
|
|
|
* <code><i>ios</i>.read()</code> and
|
|
|
|
* <code><i>ios</i>.read(nil)</code> returns <code>""</code>.
|
|
|
|
* <code><i>ios</i>.read(<i>positive-integer</i>)</code> returns nil.
|
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.read(16) #=> "This is line one"
|
2009-03-17 04:37:57 +03:00
|
|
|
*
|
|
|
|
* # reads whole file
|
|
|
|
* open("file") {|f|
|
|
|
|
* data = f.read # This returns a string even if the file is empty.
|
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* # iterate over fixed length records.
|
|
|
|
* open("fixed-record-file") {|f|
|
|
|
|
* while record = f.read(256)
|
|
|
|
* ...
|
|
|
|
* end
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* # iterate over variable length records.
|
|
|
|
* # record is prefixed by 32-bit length.
|
|
|
|
* open("variable-record-file") {|f|
|
|
|
|
* while len = f.read(4)
|
|
|
|
* len = len.unpack("N")[0] # 32-bit length
|
|
|
|
* record = f.read(len) # This returns a string even if len is 0.
|
|
|
|
* end
|
|
|
|
* }
|
|
|
|
*
|
2009-03-17 13:14:01 +03:00
|
|
|
* Note that this method behaves like fread() function in C.
|
2009-03-17 04:37:57 +03:00
|
|
|
* If you need the behavior like read(2) system call,
|
|
|
|
* consider readpartial, read_nonblock and sysread.
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_read(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-08-21 19:47:54 +04:00
|
|
|
long n, len;
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE length, str;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-12-11 12:32:41 +03:00
|
|
|
rb_scan_args(argc, argv, "02", &length, &str);
|
2002-03-25 17:50:40 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (NIL_P(length)) {
|
2004-11-25 18:23:19 +03:00
|
|
|
if (!NIL_P(str)) StringValue(str);
|
2004-11-23 20:37:51 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2008-03-19 18:29:09 +03:00
|
|
|
rb_io_check_readable(fptr);
|
2002-12-11 12:32:41 +03:00
|
|
|
return read_all(fptr, remain_size(fptr), str);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-11-23 20:37:51 +03:00
|
|
|
len = NUM2LONG(length);
|
|
|
|
if (len < 0) {
|
|
|
|
rb_raise(rb_eArgError, "negative length %ld given", len);
|
|
|
|
}
|
|
|
|
|
2002-12-11 12:32:41 +03:00
|
|
|
if (NIL_P(str)) {
|
2007-12-12 10:39:43 +03:00
|
|
|
str = rb_str_new(0, len);
|
2002-12-11 12:32:41 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
StringValue(str);
|
|
|
|
rb_str_modify(str);
|
2003-03-20 09:27:22 +03:00
|
|
|
rb_str_resize(str,len);
|
2002-12-11 12:32:41 +03:00
|
|
|
}
|
2004-11-23 20:37:51 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
2003-06-23 12:41:07 +04:00
|
|
|
if (len == 0) return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
READ_CHECK(fptr);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) != len) {
|
2004-11-10 10:17:53 +03:00
|
|
|
rb_raise(rb_eRuntimeError, "buffer string modified");
|
|
|
|
}
|
2004-12-06 18:31:26 +03:00
|
|
|
n = io_fread(str, 0, fptr);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (n == 0) {
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->fd < 0) return Qnil;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_str_resize(str, 0);
|
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-11-30 12:36:39 +03:00
|
|
|
rb_str_resize(str, n);
|
2007-12-13 02:46:58 +03:00
|
|
|
|
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2007-12-24 19:36:14 +03:00
|
|
|
static void
|
|
|
|
rscheck(const char *rsptr, long rslen, VALUE rs)
|
|
|
|
{
|
|
|
|
if (!rs) return;
|
|
|
|
if (RSTRING_PTR(rs) != rsptr && RSTRING_LEN(rs) != rslen)
|
|
|
|
rb_raise(rb_eRuntimeError, "rs modified");
|
|
|
|
}
|
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
static int
|
2008-01-23 21:43:51 +03:00
|
|
|
appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-03-25 17:50:40 +03:00
|
|
|
VALUE str = *strp;
|
2006-12-29 22:21:50 +03:00
|
|
|
long limit = *lp;
|
2002-02-06 10:30:13 +03:00
|
|
|
|
2008-08-22 20:44:00 +04:00
|
|
|
if (NEED_READCONV(fptr)) {
|
2008-10-28 14:18:28 +03:00
|
|
|
make_readconv(fptr, 0);
|
2009-01-14 06:38:06 +03:00
|
|
|
do {
|
2008-08-18 05:40:01 +04:00
|
|
|
const char *p, *e;
|
|
|
|
int searchlen;
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_len) {
|
|
|
|
p = fptr->cbuf+fptr->cbuf_off;
|
|
|
|
searchlen = fptr->cbuf_len;
|
2008-08-18 05:40:01 +04:00
|
|
|
if (0 < limit && limit < searchlen)
|
2009-04-26 13:46:41 +04:00
|
|
|
searchlen = (int)limit;
|
2008-08-18 05:40:01 +04:00
|
|
|
e = memchr(p, delim, searchlen);
|
|
|
|
if (e) {
|
2009-04-26 13:46:41 +04:00
|
|
|
int len = (int)(e-p+1);
|
2008-08-18 05:40:01 +04:00
|
|
|
if (NIL_P(str))
|
2009-04-26 13:46:41 +04:00
|
|
|
*strp = str = rb_str_new(p, len);
|
2008-08-18 05:40:01 +04:00
|
|
|
else
|
2009-04-26 13:46:41 +04:00
|
|
|
rb_str_buf_cat(str, p, len);
|
|
|
|
fptr->cbuf_off += len;
|
|
|
|
fptr->cbuf_len -= len;
|
|
|
|
limit -= len;
|
2008-08-18 05:40:01 +04:00
|
|
|
*lp = limit;
|
|
|
|
return delim;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NIL_P(str))
|
|
|
|
*strp = str = rb_str_new(p, searchlen);
|
|
|
|
else
|
|
|
|
rb_str_buf_cat(str, p, searchlen);
|
2008-08-26 19:06:28 +04:00
|
|
|
fptr->cbuf_off += searchlen;
|
|
|
|
fptr->cbuf_len -= searchlen;
|
2008-08-18 05:40:01 +04:00
|
|
|
limit -= searchlen;
|
|
|
|
|
|
|
|
if (limit == 0) {
|
|
|
|
*lp = limit;
|
|
|
|
return (unsigned char)RSTRING_PTR(str)[RSTRING_LEN(str)-1];
|
|
|
|
}
|
|
|
|
}
|
2009-01-14 06:38:06 +03:00
|
|
|
} while (more_char(fptr) != -1);
|
|
|
|
*lp = limit;
|
|
|
|
return EOF;
|
2008-08-18 05:40:01 +04:00
|
|
|
}
|
|
|
|
|
2009-01-14 06:38:06 +03:00
|
|
|
do {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
long pending = READ_DATA_PENDING_COUNT(fptr);
|
2002-03-25 17:50:40 +03:00
|
|
|
if (pending > 0) {
|
2007-12-25 12:52:52 +03:00
|
|
|
const char *p = READ_DATA_PENDING_PTR(fptr);
|
|
|
|
const char *e;
|
2008-08-17 23:41:39 +04:00
|
|
|
long last;
|
2006-12-29 22:21:50 +03:00
|
|
|
|
|
|
|
if (limit > 0 && pending > limit) pending = limit;
|
|
|
|
e = memchr(p, delim, pending);
|
2007-12-25 12:52:52 +03:00
|
|
|
if (e) pending = e - p + 1;
|
2002-03-25 17:50:40 +03:00
|
|
|
if (!NIL_P(str)) {
|
2006-08-31 14:47:44 +04:00
|
|
|
last = RSTRING_LEN(str);
|
2008-08-17 23:41:39 +04:00
|
|
|
rb_str_resize(str, last + pending);
|
2002-03-25 17:50:40 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-08-17 23:41:39 +04:00
|
|
|
last = 0;
|
|
|
|
*strp = str = rb_str_buf_new(pending);
|
|
|
|
rb_str_set_len(str, pending);
|
2008-01-14 18:07:49 +03:00
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
read_buffered_data(RSTRING_PTR(str) + last, pending, fptr); /* must not fail */
|
2006-12-29 22:21:50 +03:00
|
|
|
limit -= pending;
|
|
|
|
*lp = limit;
|
2002-03-25 17:50:40 +03:00
|
|
|
if (e) return delim;
|
2008-08-17 23:41:39 +04:00
|
|
|
if (limit == 0)
|
2009-01-14 06:38:06 +03:00
|
|
|
return (unsigned char)RSTRING_PTR(str)[RSTRING_LEN(str)-1];
|
2002-08-28 18:36:38 +04:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_thread_wait_fd(fptr->fd);
|
2002-03-25 17:50:40 +03:00
|
|
|
rb_io_check_closed(fptr);
|
2009-01-14 06:38:06 +03:00
|
|
|
} while (io_fillbuf(fptr) >= 0);
|
|
|
|
*lp = limit;
|
|
|
|
return EOF;
|
2002-03-25 17:50:40 +03:00
|
|
|
}
|
2002-02-06 10:30:13 +03:00
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
static inline int
|
* 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 13:30:50 +03:00
|
|
|
swallow(rb_io_t *fptr, int term)
|
2002-03-25 17:50:40 +03:00
|
|
|
{
|
|
|
|
do {
|
2009-04-26 13:46:41 +04:00
|
|
|
size_t cnt;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
while ((cnt = READ_DATA_PENDING_COUNT(fptr)) > 0) {
|
2002-03-25 17:50:40 +03:00
|
|
|
char buf[1024];
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
const char *p = READ_DATA_PENDING_PTR(fptr);
|
2002-03-25 17:50:40 +03:00
|
|
|
int i;
|
|
|
|
if (cnt > sizeof buf) cnt = sizeof buf;
|
|
|
|
if (*p != term) return Qtrue;
|
2009-04-26 13:46:41 +04:00
|
|
|
i = (int)cnt;
|
2002-03-25 17:50:40 +03:00
|
|
|
while (--i && *++p == term);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (!read_buffered_data(buf, cnt - i, fptr)) /* must not fail */
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2002-03-25 17:50:40 +03:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_thread_wait_fd(fptr->fd);
|
2002-03-25 17:50:40 +03:00
|
|
|
rb_io_check_closed(fptr);
|
2007-08-25 10:20:48 +04:00
|
|
|
} while (io_fillbuf(fptr) == 0);
|
2002-03-25 17:50:40 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-06-12 03:52:20 +04:00
|
|
|
rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc)
|
2002-03-25 17:50:40 +03:00
|
|
|
{
|
|
|
|
VALUE str = Qnil;
|
2008-01-23 21:43:51 +03:00
|
|
|
int len = 0;
|
2008-02-28 09:30:38 +03:00
|
|
|
long pos = 0;
|
2008-08-23 05:14:33 +04:00
|
|
|
int cr = 0;
|
2002-03-25 17:50:40 +03:00
|
|
|
|
2006-12-29 22:21:50 +03:00
|
|
|
for (;;) {
|
2009-04-26 13:46:41 +04:00
|
|
|
int pending = READ_DATA_PENDING_COUNT(fptr);
|
2008-01-23 21:43:51 +03:00
|
|
|
|
|
|
|
if (pending > 0) {
|
|
|
|
const char *p = READ_DATA_PENDING_PTR(fptr);
|
|
|
|
const char *e;
|
|
|
|
|
|
|
|
e = memchr(p, '\n', pending);
|
|
|
|
if (e) {
|
2009-04-26 13:46:41 +04:00
|
|
|
pending = (int)(e - p + 1);
|
2008-01-23 21:43:51 +03:00
|
|
|
}
|
|
|
|
if (NIL_P(str)) {
|
|
|
|
str = rb_str_new(p, pending);
|
|
|
|
fptr->rbuf_off += pending;
|
|
|
|
fptr->rbuf_len -= pending;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_str_resize(str, len + pending);
|
|
|
|
read_buffered_data(RSTRING_PTR(str)+len, pending, fptr);
|
|
|
|
}
|
|
|
|
len += pending;
|
2008-02-28 09:30:38 +03:00
|
|
|
if (cr != ENC_CODERANGE_BROKEN)
|
|
|
|
pos = rb_str_coderange_scan_restartable(RSTRING_PTR(str) + pos, RSTRING_PTR(str) + len, enc, &cr);
|
2008-01-23 21:43:51 +03:00
|
|
|
if (e) break;
|
|
|
|
}
|
|
|
|
rb_thread_wait_fd(fptr->fd);
|
|
|
|
rb_io_check_closed(fptr);
|
|
|
|
if (io_fillbuf(fptr) < 0) {
|
|
|
|
if (NIL_P(str)) return Qnil;
|
2007-01-06 12:47:19 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-12-29 22:21:50 +03:00
|
|
|
}
|
2002-02-06 10:30:13 +03:00
|
|
|
|
2008-01-23 21:43:51 +03:00
|
|
|
str = io_enc_str(str, fptr);
|
2008-08-23 05:14:33 +04:00
|
|
|
ENC_CODERANGE_SET(str, cr);
|
2008-01-23 21:43:51 +03:00
|
|
|
fptr->lineno++;
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.last_lineno = fptr->lineno;
|
|
|
|
|
2002-02-06 10:30:13 +03:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-01-06 12:47:19 +03:00
|
|
|
static void
|
2007-12-23 21:12:44 +03:00
|
|
|
prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io)
|
2002-02-06 10:30:13 +03:00
|
|
|
{
|
2008-08-17 16:54:26 +04:00
|
|
|
VALUE rs = rb_rs, lim = Qnil;
|
2007-12-23 21:12:44 +03:00
|
|
|
rb_io_t *fptr;
|
2006-12-29 22:21:50 +03:00
|
|
|
|
2008-08-17 16:54:26 +04:00
|
|
|
if (argc == 1) {
|
|
|
|
VALUE tmp = Qnil;
|
2006-12-29 22:21:50 +03:00
|
|
|
|
2008-08-17 16:54:26 +04:00
|
|
|
if (NIL_P(argv[0]) || !NIL_P(tmp = rb_check_string_type(argv[0]))) {
|
|
|
|
rs = tmp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lim = argv[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (2 <= argc) {
|
|
|
|
rb_scan_args(argc, argv, "2", &rs, &lim);
|
|
|
|
if (!NIL_P(rs))
|
|
|
|
StringValue(rs);
|
2006-12-29 22:21:50 +03:00
|
|
|
}
|
2008-01-25 18:57:32 +03:00
|
|
|
if (!NIL_P(rs)) {
|
2008-01-23 21:43:51 +03:00
|
|
|
rb_encoding *enc_rs, *enc_io;
|
2007-12-24 19:36:14 +03:00
|
|
|
|
2008-01-23 21:43:51 +03:00
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
enc_rs = rb_enc_get(rs);
|
|
|
|
enc_io = io_read_encoding(fptr);
|
2007-12-24 19:36:14 +03:00
|
|
|
if (enc_io != enc_rs &&
|
|
|
|
(rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
|
|
|
|
!rb_enc_asciicompat(enc_io))) {
|
2008-01-25 18:57:32 +03:00
|
|
|
if (rs == rb_default_rs) {
|
|
|
|
rs = rb_enc_str_new(0, 0, enc_io);
|
|
|
|
rb_str_buf_cat_ascii(rs, "\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_raise(rb_eArgError, "encoding mismatch: %s IO with %s RS",
|
|
|
|
rb_enc_name(enc_io),
|
|
|
|
rb_enc_name(enc_rs));
|
|
|
|
}
|
2007-12-24 19:36:14 +03:00
|
|
|
}
|
2007-12-23 21:12:44 +03:00
|
|
|
}
|
2007-01-06 12:47:19 +03:00
|
|
|
*rsp = rs;
|
|
|
|
*limit = NIL_P(lim) ? -1L : NUM2LONG(lim);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_getline_1(VALUE rs, long limit, VALUE io)
|
|
|
|
{
|
|
|
|
VALUE str = Qnil;
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2007-01-06 12:47:19 +03:00
|
|
|
int nolimit = 0;
|
2007-12-25 12:52:52 +03:00
|
|
|
rb_encoding *enc;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-23 20:37:51 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2003-08-01 11:23:00 +04:00
|
|
|
rb_io_check_readable(fptr);
|
2009-02-25 06:06:12 +03:00
|
|
|
if (NIL_P(rs) && limit < 0) {
|
2002-12-11 12:32:41 +03:00
|
|
|
str = read_all(fptr, 0, Qnil);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) == 0) return Qnil;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2007-01-06 12:47:19 +03:00
|
|
|
else if (limit == 0) {
|
2007-12-23 21:01:16 +03:00
|
|
|
return rb_enc_str_new(0, 0, io_read_encoding(fptr));
|
2006-12-29 22:21:50 +03:00
|
|
|
}
|
2008-08-22 20:44:00 +04:00
|
|
|
else if (rs == rb_default_rs && limit < 0 && !NEED_READCONV(fptr) &&
|
2008-06-12 03:52:20 +04:00
|
|
|
rb_enc_asciicompat(enc = io_read_encoding(fptr))) {
|
|
|
|
return rb_io_getline_fast(fptr, enc);
|
2000-05-01 13:42:38 +04:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else {
|
2009-02-25 06:06:12 +03:00
|
|
|
int c, newline = -1;
|
|
|
|
const char *rsptr = 0;
|
|
|
|
long rslen = 0;
|
2002-08-21 19:47:54 +04:00
|
|
|
int rspara = 0;
|
2008-08-17 23:41:39 +04:00
|
|
|
int extra_limit = 16;
|
2002-03-25 17:50:40 +03:00
|
|
|
|
2009-02-25 06:06:12 +03:00
|
|
|
if (!NIL_P(rs)) {
|
|
|
|
rslen = RSTRING_LEN(rs);
|
|
|
|
if (rslen == 0) {
|
|
|
|
rsptr = "\n\n";
|
|
|
|
rslen = 2;
|
|
|
|
rspara = 1;
|
|
|
|
swallow(fptr, '\n');
|
|
|
|
rs = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rsptr = RSTRING_PTR(rs);
|
|
|
|
}
|
|
|
|
newline = (unsigned char)rsptr[rslen - 1];
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2008-10-07 21:39:44 +04:00
|
|
|
/* MS - Optimisation */
|
|
|
|
enc = io_read_encoding(fptr);
|
2008-01-23 21:43:51 +03:00
|
|
|
while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
|
2008-09-13 23:23:52 +04:00
|
|
|
const char *s, *p, *pp, *e;
|
2008-03-19 18:29:09 +03:00
|
|
|
|
2008-08-17 23:41:39 +04:00
|
|
|
if (c == newline) {
|
2007-12-25 12:52:52 +03:00
|
|
|
if (RSTRING_LEN(str) < rslen) continue;
|
|
|
|
s = RSTRING_PTR(str);
|
2008-09-13 23:23:52 +04:00
|
|
|
e = s + RSTRING_LEN(str);
|
|
|
|
p = e - rslen;
|
|
|
|
pp = rb_enc_left_char_head(s, p, e, enc);
|
2007-12-25 12:52:52 +03:00
|
|
|
if (pp != p) continue;
|
|
|
|
if (!rspara) rscheck(rsptr, rslen, rs);
|
|
|
|
if (memcmp(p, rsptr, rslen) == 0) break;
|
2004-11-20 17:26:23 +03:00
|
|
|
}
|
2007-01-06 12:47:19 +03:00
|
|
|
if (limit == 0) {
|
2008-08-17 23:41:39 +04:00
|
|
|
s = RSTRING_PTR(str);
|
|
|
|
p = s + RSTRING_LEN(str);
|
2008-09-13 23:23:52 +04:00
|
|
|
pp = rb_enc_left_char_head(s, p-1, p, enc);
|
2008-08-17 23:41:39 +04:00
|
|
|
if (extra_limit &&
|
|
|
|
MBCLEN_NEEDMORE_P(rb_enc_precise_mbclen(pp, p, enc))) {
|
|
|
|
/* relax the limit while incomplete character.
|
|
|
|
* extra_limit limits the relax length */
|
|
|
|
limit = 1;
|
|
|
|
extra_limit--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nolimit = 1;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-06 12:47:19 +03:00
|
|
|
}
|
2004-11-20 17:26:23 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
if (rspara) {
|
|
|
|
if (c != EOF) {
|
|
|
|
swallow(fptr, '\n');
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2008-08-18 05:40:01 +04:00
|
|
|
if (!NIL_P(str))
|
2008-08-18 07:47:15 +04:00
|
|
|
str = io_enc_str(str, fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
if (!NIL_P(str)) {
|
2007-01-06 12:47:19 +03:00
|
|
|
if (!nolimit) {
|
2006-12-29 22:21:50 +03:00
|
|
|
fptr->lineno++;
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.last_lineno = fptr->lineno;
|
2006-12-29 22:21:50 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2007-01-06 12:47:19 +03:00
|
|
|
static VALUE
|
|
|
|
rb_io_getline(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
VALUE rs;
|
|
|
|
long limit;
|
|
|
|
|
2007-12-23 21:12:44 +03:00
|
|
|
prepare_getline_args(argc, argv, &rs, &limit, io);
|
2007-01-06 12:47:19 +03:00
|
|
|
return rb_io_getline_1(rs, limit, io);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_gets(VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-08-25 12:36:46 +04:00
|
|
|
return rb_io_getline_1(rb_default_rs, -1, io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-12-29 22:21:50 +03:00
|
|
|
* ios.gets(sep=$/) => string or nil
|
|
|
|
* ios.gets(limit) => string or nil
|
|
|
|
* ios.gets(sep, limit) => string or nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Reads the next ``line'' from the I/O stream; lines are separated by
|
2006-12-29 22:21:50 +03:00
|
|
|
* <i>sep</i>. A separator of <code>nil</code> reads the entire
|
2003-12-27 03:44:05 +03:00
|
|
|
* contents, and a zero-length separator reads the input a paragraph at
|
|
|
|
* a time (two successive newlines in the input separate paragraphs).
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 08:06:52 +04:00
|
|
|
* The stream must be opened for reading or an <code>IOError</code>
|
2003-12-27 03:44:05 +03:00
|
|
|
* will be raised. The line read in will be returned and also assigned
|
|
|
|
* to <code>$_</code>. Returns <code>nil</code> if called at end of
|
2006-12-29 22:21:50 +03:00
|
|
|
* file. If the first argument is an integer, or optional second
|
|
|
|
* argument is given, the returning string would not be longer than the
|
2008-09-16 13:29:40 +04:00
|
|
|
* given value in bytes.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* File.new("testfile").gets #=> "This is line one\n"
|
|
|
|
* $_ #=> "This is line one\n"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_gets_m(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2006-12-29 22:21:50 +03:00
|
|
|
VALUE str;
|
2002-02-06 10:30:13 +03:00
|
|
|
|
2006-12-29 22:21:50 +03:00
|
|
|
str = rb_io_getline(argc, argv, io);
|
2004-06-04 13:56:25 +04:00
|
|
|
rb_lastline_set(str);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.lineno => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns the current line number in <em>ios</em>. The stream must be
|
|
|
|
* opened for reading. <code>lineno</code> counts the number of times
|
|
|
|
* <code>gets</code> is called, rather than the number of newlines
|
|
|
|
* encountered. The two values will differ if <code>gets</code> is
|
|
|
|
* called with a separator other than newline. See also the
|
|
|
|
* <code>$.</code> variable.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.lineno #=> 0
|
|
|
|
* f.gets #=> "This is line one\n"
|
|
|
|
* f.lineno #=> 1
|
|
|
|
* f.gets #=> "This is line two\n"
|
|
|
|
* f.lineno #=> 2
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_lineno(VALUE io)
|
1999-01-20 07:59:39 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
|
|
|
return INT2NUM(fptr->lineno);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.lineno = integer => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Manually sets the current line number to the given value.
|
|
|
|
* <code>$.</code> is updated only on the next read.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.gets #=> "This is line one\n"
|
|
|
|
* $. #=> 1
|
|
|
|
* f.lineno = 1000
|
|
|
|
* f.lineno #=> 1000
|
2008-03-09 04:04:46 +03:00
|
|
|
* $. #=> 1 # lineno of last read
|
2003-12-27 03:44:05 +03:00
|
|
|
* f.gets #=> "This is line two\n"
|
2008-03-09 04:04:46 +03:00
|
|
|
* $. #=> 1001 # lineno of last read
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_set_lineno(VALUE io, VALUE lineno)
|
1999-01-20 07:59:39 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
2000-06-14 09:30:29 +04:00
|
|
|
fptr->lineno = NUM2INT(lineno);
|
|
|
|
return lineno;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-12-29 22:21:50 +03:00
|
|
|
* ios.readline(sep=$/) => string
|
|
|
|
* ios.readline(limit) => string
|
|
|
|
* ios.readline(sep, limit) => string
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Reads a line as with <code>IO#gets</code>, but raises an
|
|
|
|
* <code>EOFError</code> on end of file.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_readline(int argc, VALUE *argv, VALUE io)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2000-01-05 07:41:21 +03:00
|
|
|
VALUE line = rb_io_gets_m(argc, argv, io);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (NIL_P(line)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_eof_error();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-12-29 22:21:50 +03:00
|
|
|
* ios.readlines(sep=$/) => array
|
|
|
|
* ios.readlines(limit) => array
|
|
|
|
* ios.readlines(sep, limit) => array
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Reads all of the lines in <em>ios</em>, and returns them in
|
2006-12-29 22:21:50 +03:00
|
|
|
* <i>anArray</i>. Lines are separated by the optional <i>sep</i>. If
|
|
|
|
* <i>sep</i> is <code>nil</code>, the rest of the stream is returned
|
|
|
|
* as a single record. If the first argument is an integer, or
|
|
|
|
* optional second argument is given, the returning string would not be
|
2008-09-16 13:29:40 +04:00
|
|
|
* longer than the given value in bytes. The stream must be opened for
|
|
|
|
* reading or an <code>IOError</code> will be raised.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.readlines[0] #=> "This is line one\n"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_readlines(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-01-06 12:47:19 +03:00
|
|
|
VALUE line, ary, rs;
|
|
|
|
long limit;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-12-23 21:12:44 +03:00
|
|
|
prepare_getline_args(argc, argv, &rs, &limit, io);
|
1999-01-20 07:59:39 +03:00
|
|
|
ary = rb_ary_new();
|
2007-01-06 12:47:19 +03:00
|
|
|
while (!NIL_P(line = rb_io_getline_1(rs, limit, io))) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_push(ary, line);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-12-29 22:21:50 +03:00
|
|
|
* ios.each(sep=$/) {|line| block } => ios
|
|
|
|
* ios.each(limit) {|line| block } => ios
|
|
|
|
* ios.each(sep,limit) {|line| block } => ios
|
|
|
|
* ios.each_line(sep=$/) {|line| block } => ios
|
|
|
|
* ios.each_line(limit) {|line| block } => ios
|
|
|
|
* ios.each_line(sep,limit) {|line| block } => ios
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Executes the block for every line in <em>ios</em>, where lines are
|
2006-12-29 22:21:50 +03:00
|
|
|
* separated by <i>sep</i>. <em>ios</em> must be opened for
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 08:06:52 +04:00
|
|
|
* reading or an <code>IOError</code> will be raised.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.each {|line| puts "#{f.lineno}: #{line}" }
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* 1: This is line one
|
|
|
|
* 2: This is line two
|
|
|
|
* 3: This is line three
|
|
|
|
* 4: And so on...
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_each_line(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-01-06 12:47:19 +03:00
|
|
|
VALUE str, rs;
|
|
|
|
long limit;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-08-30 18:49:51 +04:00
|
|
|
RETURN_ENUMERATOR(io, argc, argv);
|
2007-12-23 21:12:44 +03:00
|
|
|
prepare_getline_args(argc, argv, &rs, &limit, io);
|
2007-01-06 12:47:19 +03:00
|
|
|
while (!NIL_P(str = rb_io_getline_1(rs, limit, io))) {
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_yield(str);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
return io;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-01-02 19:21:26 +03:00
|
|
|
* ios.each_byte {|byte| block } => ios
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Calls the given block once for each byte (0..255) in <em>ios</em>,
|
|
|
|
* passing the byte as an argument. The stream must be opened for
|
* array.c, enum.c, eval.c, file.c, io.c, numeric.c, object.c, prec.c,
process.c, re.c, string.c: typos in RDoc comments. [ruby-core:02783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-14 08:06:52 +04:00
|
|
|
* reading or an <code>IOError</code> will be raised.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* checksum = 0
|
|
|
|
* f.each_byte {|x| checksum ^= x } #=> #<File:testfile>
|
|
|
|
* checksum #=> 12
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_each_byte(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
* 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-25 07:29:39 +04:00
|
|
|
char *p, *e;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-08-30 18:49:51 +04:00
|
|
|
RETURN_ENUMERATOR(io, 0, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
|
|
|
|
for (;;) {
|
* 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-25 07:29:39 +04:00
|
|
|
p = fptr->rbuf+fptr->rbuf_off;
|
|
|
|
e = p + fptr->rbuf_len;
|
|
|
|
while (p < e) {
|
2007-11-09 10:54:39 +03:00
|
|
|
fptr->rbuf_off++;
|
|
|
|
fptr->rbuf_len--;
|
* 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-25 07:29:39 +04:00
|
|
|
rb_yield(INT2FIX(*p & 0xff));
|
|
|
|
p++;
|
2009-06-22 12:23:30 +04:00
|
|
|
errno = 0;
|
* 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-25 07:29:39 +04:00
|
|
|
}
|
2003-08-01 11:23:00 +04:00
|
|
|
rb_io_check_readable(fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
READ_CHECK(fptr);
|
* 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-25 07:29:39 +04:00
|
|
|
if (io_fillbuf(fptr) < 0) {
|
2000-06-13 13:42:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2007-08-26 21:22:26 +04:00
|
|
|
}
|
2002-01-18 17:24:01 +03:00
|
|
|
return io;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-03-30 23:16:29 +04:00
|
|
|
static VALUE
|
2008-03-30 19:00:12 +04:00
|
|
|
io_getc(rb_io_t *fptr, rb_encoding *enc)
|
|
|
|
{
|
2008-03-30 23:16:29 +04:00
|
|
|
int r, n, cr = 0;
|
2008-03-30 19:00:12 +04:00
|
|
|
VALUE str;
|
|
|
|
|
2008-08-22 20:44:00 +04:00
|
|
|
if (NEED_READCONV(fptr)) {
|
2008-08-18 07:13:53 +04:00
|
|
|
VALUE str = Qnil;
|
|
|
|
|
2008-10-28 14:18:28 +03:00
|
|
|
make_readconv(fptr, 0);
|
2008-08-16 21:06:35 +04:00
|
|
|
|
|
|
|
while (1) {
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_len) {
|
2008-08-24 11:49:13 +04:00
|
|
|
if (fptr->encs.enc)
|
2008-08-26 19:06:28 +04:00
|
|
|
r = rb_enc_precise_mbclen(fptr->cbuf+fptr->cbuf_off,
|
|
|
|
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len,
|
2008-08-24 11:49:13 +04:00
|
|
|
fptr->encs.enc);
|
2008-08-22 20:44:00 +04:00
|
|
|
else
|
|
|
|
r = ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1);
|
2008-08-16 21:06:35 +04:00
|
|
|
if (!MBCLEN_NEEDMORE_P(r))
|
|
|
|
break;
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_len == fptr->cbuf_capa) {
|
2008-08-16 21:06:35 +04:00
|
|
|
rb_raise(rb_eIOError, "too long character");
|
|
|
|
}
|
|
|
|
}
|
2008-08-18 05:40:01 +04:00
|
|
|
|
|
|
|
if (more_char(fptr) == -1) {
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_len == 0)
|
2008-08-18 05:40:01 +04:00
|
|
|
return Qnil;
|
|
|
|
/* return an incomplete character just before EOF */
|
2008-08-26 19:06:28 +04:00
|
|
|
return io_shift_cbuf(fptr, fptr->cbuf_len, &str);
|
2008-08-17 08:25:56 +04:00
|
|
|
}
|
2008-08-16 21:06:35 +04:00
|
|
|
}
|
|
|
|
if (MBCLEN_INVALID_P(r)) {
|
2008-08-26 19:06:28 +04:00
|
|
|
r = rb_enc_mbclen(fptr->cbuf+fptr->cbuf_off,
|
|
|
|
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len,
|
2008-08-24 11:49:13 +04:00
|
|
|
fptr->encs.enc);
|
2008-08-26 19:06:28 +04:00
|
|
|
return io_shift_cbuf(fptr, r, &str);
|
2008-08-16 21:06:35 +04:00
|
|
|
}
|
2008-08-26 19:06:28 +04:00
|
|
|
return io_shift_cbuf(fptr, MBCLEN_CHARFOUND_LEN(r), &str);
|
2008-07-29 18:38:44 +04:00
|
|
|
}
|
|
|
|
|
2008-03-30 19:00:12 +04:00
|
|
|
if (io_fillbuf(fptr) < 0) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
2008-03-30 23:16:29 +04:00
|
|
|
if (rb_enc_asciicompat(enc) && ISASCII(fptr->rbuf[fptr->rbuf_off])) {
|
|
|
|
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, 1);
|
|
|
|
fptr->rbuf_off += 1;
|
|
|
|
fptr->rbuf_len -= 1;
|
|
|
|
cr = ENC_CODERANGE_7BIT;
|
2008-03-30 19:00:12 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-03-30 23:16:29 +04:00
|
|
|
r = rb_enc_precise_mbclen(fptr->rbuf+fptr->rbuf_off, fptr->rbuf+fptr->rbuf_off+fptr->rbuf_len, enc);
|
|
|
|
if (MBCLEN_CHARFOUND_P(r) &&
|
|
|
|
(n = MBCLEN_CHARFOUND_LEN(r)) <= fptr->rbuf_len) {
|
|
|
|
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, n);
|
|
|
|
fptr->rbuf_off += n;
|
|
|
|
fptr->rbuf_len -= n;
|
|
|
|
cr = ENC_CODERANGE_VALID;
|
|
|
|
}
|
|
|
|
else if (MBCLEN_NEEDMORE_P(r)) {
|
|
|
|
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, fptr->rbuf_len);
|
|
|
|
fptr->rbuf_len = 0;
|
|
|
|
getc_needmore:
|
|
|
|
if (io_fillbuf(fptr) != -1) {
|
|
|
|
rb_str_cat(str, fptr->rbuf+fptr->rbuf_off, 1);
|
|
|
|
fptr->rbuf_off++;
|
|
|
|
fptr->rbuf_len--;
|
|
|
|
r = rb_enc_precise_mbclen(RSTRING_PTR(str), RSTRING_PTR(str)+RSTRING_LEN(str), enc);
|
|
|
|
if (MBCLEN_NEEDMORE_P(r)) {
|
|
|
|
goto getc_needmore;
|
|
|
|
}
|
|
|
|
else if (MBCLEN_CHARFOUND_P(r)) {
|
|
|
|
cr = ENC_CODERANGE_VALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
str = rb_str_new(fptr->rbuf+fptr->rbuf_off, 1);
|
|
|
|
fptr->rbuf_off++;
|
|
|
|
fptr->rbuf_len--;
|
|
|
|
}
|
2008-03-30 19:00:12 +04:00
|
|
|
}
|
2008-03-30 23:16:29 +04:00
|
|
|
if (!cr) cr = ENC_CODERANGE_BROKEN;
|
|
|
|
str = io_enc_str(str, fptr);
|
2008-08-23 05:14:33 +04:00
|
|
|
ENC_CODERANGE_SET(str, cr);
|
2008-03-30 23:16:29 +04:00
|
|
|
return str;
|
2008-03-30 19:00:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.each_char {|c| block } => ios
|
|
|
|
*
|
|
|
|
* Calls the given block once for each character in <em>ios</em>,
|
|
|
|
* passing the character as an argument. The stream must be opened for
|
|
|
|
* reading or an <code>IOError</code> will be raised.
|
|
|
|
*
|
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.each_char {|c| print c, ' ' } #=> #<File:testfile>
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_each_char(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
rb_encoding *enc;
|
|
|
|
VALUE c;
|
|
|
|
|
|
|
|
RETURN_ENUMERATOR(io, 0, 0);
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
|
|
|
|
|
|
|
enc = io_input_encoding(fptr);
|
|
|
|
READ_CHECK(fptr);
|
|
|
|
while (!NIL_P(c = io_getc(fptr, enc))) {
|
|
|
|
rb_yield(c);
|
|
|
|
}
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-06-22 12:23:30 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.each_codepoint {|c| block } => ios
|
|
|
|
*
|
|
|
|
* Passes the <code>Integer</code> ordinal of each character in <i>ios</i>,
|
|
|
|
* passing the codepoint as an argument. The stream must be opened for
|
|
|
|
* reading or an <code>IOError</code> will be raised.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_each_codepoint(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
rb_encoding *enc;
|
|
|
|
unsigned int c;
|
|
|
|
int r, n;
|
|
|
|
|
|
|
|
RETURN_ENUMERATOR(io, 0, 0);
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
|
|
|
|
|
|
|
READ_CHECK(fptr);
|
|
|
|
if (NEED_READCONV(fptr)) {
|
|
|
|
for (;;) {
|
|
|
|
make_readconv(fptr, 0);
|
|
|
|
for (;;) {
|
|
|
|
if (fptr->cbuf_len) {
|
|
|
|
if (fptr->encs.enc)
|
|
|
|
r = rb_enc_precise_mbclen(fptr->cbuf+fptr->cbuf_off,
|
|
|
|
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len,
|
|
|
|
fptr->encs.enc);
|
|
|
|
else
|
|
|
|
r = ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1);
|
|
|
|
if (!MBCLEN_NEEDMORE_P(r))
|
|
|
|
break;
|
|
|
|
if (fptr->cbuf_len == fptr->cbuf_capa) {
|
|
|
|
rb_raise(rb_eIOError, "too long character");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (more_char(fptr) == -1) {
|
|
|
|
/* ignore an incomplete character before EOF */
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (MBCLEN_INVALID_P(r)) {
|
2009-06-25 02:49:37 +04:00
|
|
|
rb_raise(rb_eArgError, "invalid byte sequence in %s",
|
|
|
|
rb_enc_name(fptr->encs.enc));
|
2009-06-22 12:23:30 +04:00
|
|
|
}
|
|
|
|
n = MBCLEN_CHARFOUND_LEN(r);
|
|
|
|
c = rb_enc_codepoint(fptr->cbuf+fptr->cbuf_off,
|
|
|
|
fptr->cbuf+fptr->cbuf_off+fptr->cbuf_len,
|
|
|
|
fptr->encs.enc);
|
|
|
|
fptr->rbuf_off += n;
|
|
|
|
fptr->rbuf_len -= n;
|
|
|
|
rb_yield(UINT2NUM(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enc = io_input_encoding(fptr);
|
|
|
|
for (;;) {
|
|
|
|
if (io_fillbuf(fptr) < 0) {
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
r = rb_enc_precise_mbclen(fptr->rbuf+fptr->rbuf_off,
|
|
|
|
fptr->rbuf+fptr->rbuf_off+fptr->rbuf_len, enc);
|
|
|
|
if (MBCLEN_CHARFOUND_P(r) &&
|
|
|
|
(n = MBCLEN_CHARFOUND_LEN(r)) <= fptr->rbuf_len) {
|
|
|
|
c = rb_enc_codepoint(fptr->rbuf+fptr->rbuf_off,
|
|
|
|
fptr->rbuf+fptr->rbuf_off+fptr->rbuf_len, enc);
|
|
|
|
fptr->rbuf_off += n;
|
|
|
|
fptr->rbuf_len -= n;
|
|
|
|
rb_yield(UINT2NUM(c));
|
|
|
|
}
|
|
|
|
else if (MBCLEN_INVALID_P(r)) {
|
|
|
|
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-10-17 03:07:07 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-03-30 19:39:00 +04:00
|
|
|
* ios.lines(sep=$/) => anEnumerator
|
|
|
|
* ios.lines(limit) => anEnumerator
|
|
|
|
* ios.lines(sep, limit) => anEnumerator
|
2008-03-19 18:29:09 +03:00
|
|
|
*
|
2008-03-30 19:39:00 +04:00
|
|
|
* Returns an enumerator that gives each line in <em>ios</em>.
|
|
|
|
* The stream must be opened for reading or an <code>IOError</code>
|
|
|
|
* will be raised.
|
2008-03-19 18:29:09 +03:00
|
|
|
*
|
2008-03-30 19:39:00 +04:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.lines.to_a #=> ["foo\n", "bar\n"]
|
|
|
|
* f.rewind
|
|
|
|
* f.lines.sort #=> ["bar\n", "foo\n"]
|
2006-10-17 03:07:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-30 19:00:12 +04:00
|
|
|
rb_io_lines(int argc, VALUE *argv, VALUE io)
|
2006-10-17 03:07:07 +04:00
|
|
|
{
|
2008-03-30 19:00:12 +04:00
|
|
|
return rb_enumeratorize(io, ID2SYM(rb_intern("each_line")), argc, argv);
|
2006-10-17 03:07:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-03-30 19:39:00 +04:00
|
|
|
* ios.bytes => anEnumerator
|
2008-03-19 18:29:09 +03:00
|
|
|
*
|
2008-03-30 19:39:00 +04:00
|
|
|
* Returns an enumerator that gives each byte (0..255) in <em>ios</em>.
|
|
|
|
* The stream must be opened for reading or an <code>IOError</code>
|
|
|
|
* will be raised.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-03-30 19:39:00 +04:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.bytes.to_a #=> [104, 101, 108, 108, 111]
|
|
|
|
* f.rewind
|
|
|
|
* f.bytes.sort #=> [101, 104, 108, 108, 111]
|
2006-10-17 03:07:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-30 19:00:12 +04:00
|
|
|
rb_io_bytes(VALUE io)
|
|
|
|
{
|
|
|
|
return rb_enumeratorize(io, ID2SYM(rb_intern("each_byte")), 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.chars => anEnumerator
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-03-30 19:00:12 +04:00
|
|
|
* Returns an enumerator that gives each character in <em>ios</em>.
|
|
|
|
* The stream must be opened for reading or an <code>IOError</code>
|
|
|
|
* will be raised.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-03-30 19:39:00 +04:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.chars.to_a #=> ["h", "e", "l", "l", "o"]
|
|
|
|
* f.rewind
|
|
|
|
* f.chars.sort #=> ["e", "h", "l", "l", "o"]
|
2008-03-30 19:00:12 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_chars(VALUE io)
|
2006-10-17 03:07:07 +04:00
|
|
|
{
|
2008-03-30 19:00:12 +04:00
|
|
|
return rb_enumeratorize(io, ID2SYM(rb_intern("each_char")), 0, 0);
|
2006-10-17 03:07:07 +04:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:23:30 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.codepoints => anEnumerator
|
|
|
|
*
|
|
|
|
* Returns an enumerator that gives each codepoint in <em>ios</em>.
|
|
|
|
* The stream must be opened for reading or an <code>IOError</code>
|
|
|
|
* will be raised.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_codepoints(VALUE io)
|
|
|
|
{
|
|
|
|
return rb_enumeratorize(io, ID2SYM(rb_intern("each_codepoint")), 0, 0);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-12-03 06:22:12 +03:00
|
|
|
* ios.getc => string or nil
|
2008-03-19 18:29:09 +03:00
|
|
|
*
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
* Reads a one-character string from <em>ios</em>. Returns
|
2003-12-27 03:44:05 +03:00
|
|
|
* <code>nil</code> if called at end of file.
|
2008-03-19 18:29:09 +03:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
2008-12-03 06:22:12 +03:00
|
|
|
* f.getc #=> "h"
|
|
|
|
* f.getc #=> "e"
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
* 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-25 07:29:39 +04:00
|
|
|
static VALUE
|
|
|
|
rb_io_getc(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2007-12-13 02:58:58 +03:00
|
|
|
rb_encoding *enc;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_check_readable(fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-12-24 19:36:14 +03:00
|
|
|
enc = io_input_encoding(fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
READ_CHECK(fptr);
|
2008-03-30 19:00:12 +04:00
|
|
|
return io_getc(fptr, enc);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
* ios.readchar => string
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
* 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-25 07:29:39 +04:00
|
|
|
* Reads a one-character string from <em>ios</em>. Raises an
|
2003-12-27 03:44:05 +03:00
|
|
|
* <code>EOFError</code> on end of file.
|
* 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-25 07:29:39 +04:00
|
|
|
*
|
|
|
|
* f = File.new("testfile")
|
2008-12-03 06:22:12 +03:00
|
|
|
* f.readchar #=> "h"
|
|
|
|
* f.readchar #=> "e"
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_readchar(VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* 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-25 07:29:39 +04:00
|
|
|
VALUE c = rb_io_getc(io);
|
|
|
|
|
|
|
|
if (NIL_P(c)) {
|
|
|
|
rb_eof_error();
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.getbyte => fixnum or nil
|
|
|
|
*
|
|
|
|
* Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
|
|
|
|
* <code>nil</code> if called at end of file.
|
|
|
|
*
|
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.getbyte #=> 84
|
|
|
|
* f.getbyte #=> 104
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_io_getbyte(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
|
|
|
READ_CHECK(fptr);
|
|
|
|
if (fptr->fd == 0 && (fptr->mode & FMODE_TTY) && TYPE(rb_stdout) == T_FILE) {
|
|
|
|
rb_io_t *ofp;
|
|
|
|
GetOpenFile(rb_stdout, ofp);
|
|
|
|
if (ofp->mode & FMODE_TTY) {
|
|
|
|
rb_io_flush(rb_stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (io_fillbuf(fptr) < 0) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
fptr->rbuf_off++;
|
|
|
|
fptr->rbuf_len--;
|
|
|
|
c = (unsigned char)fptr->rbuf[fptr->rbuf_off-1];
|
|
|
|
return INT2FIX(c & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.readbyte => fixnum
|
|
|
|
*
|
2008-09-16 13:36:06 +04:00
|
|
|
* Reads a byte as with <code>IO#getbyte</code>, but raises an
|
* 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-25 07:29:39 +04:00
|
|
|
* <code>EOFError</code> on end of file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_readbyte(VALUE io)
|
|
|
|
{
|
|
|
|
VALUE c = rb_io_getbyte(io);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (NIL_P(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_eof_error();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2008-08-18 18:28:45 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.ungetbyte(string) => nil
|
|
|
|
* ios.ungetbyte(integer) => nil
|
|
|
|
*
|
|
|
|
* Pushes back bytes (passed as a parameter) onto <em>ios</em>,
|
|
|
|
* such that a subsequent buffered read will return it. Only one byte
|
|
|
|
* may be pushed back before a subsequent read operation (that is,
|
|
|
|
* you will be able to read only the last of several bytes that have been pushed
|
|
|
|
* back). Has no effect with unbuffered reads (such as <code>IO#sysread</code>).
|
|
|
|
*
|
|
|
|
* f = File.new("testfile") #=> #<File:testfile>
|
|
|
|
* b = f.getbyte #=> 0x38
|
|
|
|
* f.ungetbyte(b) #=> nil
|
|
|
|
* f.getbyte #=> 0x38
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_io_ungetbyte(VALUE io, VALUE b)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
2009-01-21 15:42:39 +03:00
|
|
|
io_unset_eof(fptr);
|
2008-08-18 18:28:45 +04:00
|
|
|
if (NIL_P(b)) return Qnil;
|
|
|
|
if (FIXNUM_P(b)) {
|
|
|
|
char cc = FIX2INT(b);
|
|
|
|
b = rb_str_new(&cc, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(b);
|
|
|
|
}
|
|
|
|
io_ungetbyte(b, fptr);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
* ios.ungetc(string) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Pushes back one character (passed as a parameter) onto <em>ios</em>,
|
|
|
|
* such that a subsequent buffered read will return it. Only one character
|
|
|
|
* may be pushed back before a subsequent read operation (that is,
|
|
|
|
* you will be able to read only the last of several characters that have been pushed
|
|
|
|
* back). Has no effect with unbuffered reads (such as <code>IO#sysread</code>).
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile") #=> #<File:testfile>
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
* c = f.getc #=> "8"
|
2003-12-27 03:44:05 +03:00
|
|
|
* f.ungetc(c) #=> nil
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
* f.getc #=> "8"
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_ungetc(VALUE io, VALUE c)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2008-08-18 18:28:45 +04:00
|
|
|
long len;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_check_readable(fptr);
|
2009-01-21 15:42:39 +03:00
|
|
|
io_unset_eof(fptr);
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
if (NIL_P(c)) return Qnil;
|
|
|
|
if (FIXNUM_P(c)) {
|
* 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-25 07:29:39 +04:00
|
|
|
int cc = FIX2INT(c);
|
2008-03-02 17:04:02 +03:00
|
|
|
rb_encoding *enc = io_read_encoding(fptr);
|
* 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-25 07:29:39 +04:00
|
|
|
char buf[16];
|
|
|
|
|
2008-03-02 17:04:02 +03:00
|
|
|
c = rb_str_new(buf, rb_enc_mbcput(cc, buf, enc));
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(c);
|
2004-03-10 10:05:19 +03:00
|
|
|
}
|
2008-08-22 20:44:00 +04:00
|
|
|
if (NEED_READCONV(fptr)) {
|
2008-08-18 18:28:45 +04:00
|
|
|
len = RSTRING_LEN(c);
|
2009-04-26 13:46:41 +04:00
|
|
|
#if SIZEOF_LONG > SIZEOF_INT
|
|
|
|
if (len > INT_MAX)
|
|
|
|
rb_raise(rb_eIOError, "ungetc failed");
|
|
|
|
#endif
|
|
|
|
make_readconv(fptr, (int)len);
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_capa - fptr->cbuf_len < len)
|
2008-08-18 18:28:45 +04:00
|
|
|
rb_raise(rb_eIOError, "ungetc failed");
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf_off < len) {
|
|
|
|
MEMMOVE(fptr->cbuf+fptr->cbuf_capa-fptr->cbuf_len,
|
|
|
|
fptr->cbuf+fptr->cbuf_off,
|
|
|
|
char, fptr->cbuf_len);
|
|
|
|
fptr->cbuf_off = fptr->cbuf_capa-fptr->cbuf_len;
|
2008-08-18 18:28:45 +04:00
|
|
|
}
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->cbuf_off -= (int)len;
|
|
|
|
fptr->cbuf_len += (int)len;
|
2008-08-26 19:06:28 +04:00
|
|
|
MEMMOVE(fptr->cbuf+fptr->cbuf_off, RSTRING_PTR(c), char, len);
|
2008-08-18 18:28:45 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
io_ungetbyte(c, fptr);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.isatty => true or false
|
|
|
|
* ios.tty? => true or false
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns <code>true</code> if <em>ios</em> is associated with a
|
|
|
|
* terminal device (tty), <code>false</code> otherwise.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* File.new("testfile").isatty #=> false
|
|
|
|
* File.new("/dev/tty").isatty #=> true
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_isatty(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (isatty(fptr->fd) == 0)
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2009-04-16 20:58:06 +04:00
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
|
2007-11-20 11:12:34 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.close_on_exec? => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <em>ios</em> will be closed on exec.
|
|
|
|
*
|
|
|
|
* f = open("/dev/null")
|
|
|
|
* f.close_on_exec? #=> false
|
|
|
|
* f.close_on_exec = true
|
|
|
|
* f.close_on_exec? #=> true
|
|
|
|
* f.close_on_exec = false
|
|
|
|
* f.close_on_exec? #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_close_on_exec_p(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
VALUE write_io;
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (io != write_io) {
|
|
|
|
GetOpenFile(write_io, fptr);
|
|
|
|
if (fptr && 0 <= (fd = fptr->fd)) {
|
2008-08-23 04:47:54 +04:00
|
|
|
if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail_path(fptr->pathv);
|
2007-11-20 11:12:34 +03:00
|
|
|
if (!(ret & FD_CLOEXEC)) return Qfalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
if (fptr && 0 <= (fd = fptr->fd)) {
|
2008-08-23 04:47:54 +04:00
|
|
|
if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail_path(fptr->pathv);
|
2007-11-20 11:12:34 +03:00
|
|
|
if (!(ret & FD_CLOEXEC)) return Qfalse;
|
|
|
|
}
|
|
|
|
return Qtrue;
|
2009-04-16 20:58:06 +04:00
|
|
|
}
|
2007-11-20 11:12:34 +03:00
|
|
|
#else
|
2009-04-16 20:58:06 +04:00
|
|
|
#define rb_io_close_on_exec_p rb_f_notimplement
|
2007-11-20 11:12:34 +03:00
|
|
|
#endif
|
|
|
|
|
2009-04-16 20:58:06 +04:00
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
|
2007-11-20 11:12:34 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.close_on_exec = bool => true or false
|
|
|
|
*
|
|
|
|
* Sets a close-on-exec flag.
|
|
|
|
*
|
|
|
|
* f = open("/dev/null")
|
|
|
|
* f.close_on_exec = true
|
|
|
|
* system("cat", "/proc/self/fd/#{f.fileno}") # cat: /proc/self/fd/3: No such file or directory
|
|
|
|
* f.closed? #=> false
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_set_close_on_exec(VALUE io, VALUE arg)
|
|
|
|
{
|
|
|
|
int flag = RTEST(arg) ? FD_CLOEXEC : 0;
|
|
|
|
rb_io_t *fptr;
|
|
|
|
VALUE write_io;
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (io != write_io) {
|
|
|
|
GetOpenFile(write_io, fptr);
|
|
|
|
if (fptr && 0 <= (fd = fptr->fd)) {
|
2008-08-23 04:47:54 +04:00
|
|
|
if ((ret = fcntl(fptr->fd, F_GETFD)) == -1) rb_sys_fail_path(fptr->pathv);
|
2007-11-20 11:12:34 +03:00
|
|
|
if ((ret & FD_CLOEXEC) != flag) {
|
|
|
|
ret = (ret & ~FD_CLOEXEC) | flag;
|
|
|
|
ret = fcntl(fd, F_SETFD, ret);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (ret == -1) rb_sys_fail_path(fptr->pathv);
|
2007-11-20 11:12:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
if (fptr && 0 <= (fd = fptr->fd)) {
|
2008-08-23 04:47:54 +04:00
|
|
|
if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail_path(fptr->pathv);
|
2007-11-20 11:12:34 +03:00
|
|
|
if ((ret & FD_CLOEXEC) != flag) {
|
|
|
|
ret = (ret & ~FD_CLOEXEC) | flag;
|
|
|
|
ret = fcntl(fd, F_SETFD, ret);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (ret == -1) rb_sys_fail_path(fptr->pathv);
|
2007-11-20 11:12:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
2009-04-16 20:58:06 +04:00
|
|
|
#else
|
|
|
|
#define rb_io_set_close_on_exec rb_f_notimplement
|
|
|
|
#endif
|
2007-11-20 11:12:34 +03:00
|
|
|
|
2004-12-23 20:53:58 +03:00
|
|
|
#define FMODE_PREP (1<<16)
|
|
|
|
#define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
|
2008-08-23 04:47:54 +04:00
|
|
|
#define PREP_STDIO_NAME(f) (RSTRING_PTR((f)->pathv))
|
2004-12-23 20:53:58 +03:00
|
|
|
|
2008-12-26 08:04:39 +03:00
|
|
|
static VALUE
|
2008-12-26 12:05:47 +03:00
|
|
|
finish_writeconv(rb_io_t *fptr, int noalloc)
|
2008-08-18 16:06:42 +04:00
|
|
|
{
|
|
|
|
unsigned char *ds, *dp, *de;
|
|
|
|
rb_econv_result_t res;
|
|
|
|
|
|
|
|
if (!fptr->wbuf) {
|
|
|
|
unsigned char buf[1024];
|
2009-04-26 13:46:41 +04:00
|
|
|
long r;
|
2008-08-18 16:06:42 +04:00
|
|
|
|
|
|
|
res = econv_destination_buffer_full;
|
|
|
|
while (res == econv_destination_buffer_full) {
|
|
|
|
ds = dp = buf;
|
|
|
|
de = buf + sizeof(buf);
|
|
|
|
res = rb_econv_convert(fptr->writeconv, NULL, NULL, &dp, de, 0);
|
|
|
|
while (dp-ds) {
|
2008-08-26 20:09:29 +04:00
|
|
|
retry:
|
2008-08-18 16:06:42 +04:00
|
|
|
r = rb_write_internal(fptr->fd, ds, dp-ds);
|
|
|
|
if (r == dp-ds)
|
|
|
|
break;
|
|
|
|
if (0 <= r) {
|
|
|
|
ds += r;
|
|
|
|
}
|
|
|
|
if (rb_io_wait_writable(fptr->fd)) {
|
2008-12-26 08:04:39 +03:00
|
|
|
if (fptr->fd < 0)
|
2008-12-26 12:05:47 +03:00
|
|
|
return noalloc ? Qtrue : rb_exc_new3(rb_eIOError, rb_str_new_cstr("closed stream"));
|
2008-08-18 16:06:42 +04:00
|
|
|
goto retry;
|
|
|
|
}
|
2008-12-26 12:05:47 +03:00
|
|
|
return noalloc ? Qtrue : INT2NUM(errno);
|
|
|
|
}
|
|
|
|
if (res == econv_invalid_byte_sequence ||
|
|
|
|
res == econv_incomplete_input ||
|
|
|
|
res == econv_undefined_conversion) {
|
|
|
|
return noalloc ? Qtrue : rb_econv_make_exception(fptr->writeconv);
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-26 08:04:39 +03:00
|
|
|
return Qnil;
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
res = econv_destination_buffer_full;
|
|
|
|
while (res == econv_destination_buffer_full) {
|
|
|
|
if (fptr->wbuf_len == fptr->wbuf_capa) {
|
2008-12-26 08:04:39 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
2008-12-26 12:05:47 +03:00
|
|
|
return noalloc ? Qtrue : INT2NUM(errno);
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ds = dp = (unsigned char *)fptr->wbuf + fptr->wbuf_off + fptr->wbuf_len;
|
|
|
|
de = (unsigned char *)fptr->wbuf + fptr->wbuf_capa;
|
|
|
|
res = rb_econv_convert(fptr->writeconv, NULL, NULL, &dp, de, 0);
|
2009-04-26 13:46:41 +04:00
|
|
|
fptr->wbuf_len += (int)(dp - ds);
|
2008-12-26 12:05:47 +03:00
|
|
|
if (res == econv_invalid_byte_sequence ||
|
|
|
|
res == econv_incomplete_input ||
|
|
|
|
res == econv_undefined_conversion) {
|
|
|
|
return noalloc ? Qtrue : rb_econv_make_exception(fptr->writeconv);
|
|
|
|
}
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
2008-12-26 08:04:39 +03:00
|
|
|
return Qnil;
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
|
2008-12-26 12:05:47 +03:00
|
|
|
struct finish_writeconv_arg {
|
|
|
|
rb_io_t *fptr;
|
|
|
|
int noalloc;
|
|
|
|
};
|
|
|
|
|
2008-11-07 23:47:02 +03:00
|
|
|
static VALUE
|
|
|
|
finish_writeconv_sync(VALUE arg)
|
|
|
|
{
|
2008-12-26 12:05:47 +03:00
|
|
|
struct finish_writeconv_arg *p = (struct finish_writeconv_arg *)arg;
|
|
|
|
return finish_writeconv(p->fptr, p->noalloc);
|
2008-11-07 23:47:02 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static 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 13:30:50 +03:00
|
|
|
fptr_finalize(rb_io_t *fptr, int noraise)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-12-26 08:04:39 +03:00
|
|
|
VALUE err = Qnil;
|
2008-08-18 16:06:42 +04:00
|
|
|
if (fptr->writeconv) {
|
2008-11-07 23:47:02 +03:00
|
|
|
if (fptr->write_lock) {
|
2008-12-26 12:05:47 +03:00
|
|
|
struct finish_writeconv_arg arg;
|
|
|
|
arg.fptr = fptr;
|
|
|
|
arg.noalloc = noraise;
|
|
|
|
err = rb_mutex_synchronize(fptr->write_lock, finish_writeconv_sync, (VALUE)&arg);
|
2008-11-07 23:47:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-12-26 12:05:47 +03:00
|
|
|
err = finish_writeconv(fptr, noraise);
|
2008-11-07 23:47:02 +03:00
|
|
|
}
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->wbuf_len) {
|
2008-12-26 08:04:39 +03:00
|
|
|
if (io_fflush(fptr) < 0 && NIL_P(err))
|
2008-12-26 12:05:47 +03:00
|
|
|
err = noraise ? Qtrue : INT2NUM(errno);
|
2002-02-05 20:10:54 +03:00
|
|
|
}
|
2009-06-16 18:46:53 +04:00
|
|
|
if (IS_PREP_STDIO(fptr) || fptr->fd <= 2) {
|
|
|
|
goto skip_fd_close;
|
2002-02-05 10:56:31 +03:00
|
|
|
}
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->stdio_file) {
|
2008-12-25 09:08:12 +03:00
|
|
|
/* fptr->stdio_file is deallocated anyway
|
|
|
|
* even if fclose failed. */
|
2008-12-26 08:04:39 +03:00
|
|
|
if (fclose(fptr->stdio_file) < 0 && NIL_P(err))
|
2008-12-26 12:05:47 +03:00
|
|
|
err = noraise ? Qtrue : INT2NUM(errno);
|
2004-12-08 16:26:27 +03:00
|
|
|
}
|
|
|
|
else if (0 <= fptr->fd) {
|
2008-12-25 09:08:12 +03:00
|
|
|
/* fptr->fd may be closed even if close fails.
|
|
|
|
* POSIX doesn't specify it.
|
|
|
|
* We assumes it is closed. */
|
2008-12-26 08:04:39 +03:00
|
|
|
if (close(fptr->fd) < 0 && NIL_P(err))
|
2008-12-26 12:05:47 +03:00
|
|
|
err = noraise ? Qtrue : INT2NUM(errno);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2009-06-16 18:46:53 +04:00
|
|
|
skip_fd_close:
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->fd = -1;
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->stdio_file = 0;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
|
2008-12-26 08:04:39 +03:00
|
|
|
|
|
|
|
if (!NIL_P(err) && !noraise) {
|
|
|
|
switch(TYPE(err)) {
|
|
|
|
case T_FIXNUM:
|
|
|
|
case T_BIGNUM:
|
|
|
|
errno = NUM2INT(err);
|
|
|
|
rb_sys_fail_path(fptr->pathv);
|
|
|
|
|
|
|
|
default:
|
|
|
|
rb_exc_raise(err);
|
|
|
|
}
|
2008-06-09 12:48:41 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2000-12-12 10:42:35 +03:00
|
|
|
static 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 13:30:50 +03:00
|
|
|
rb_io_fptr_cleanup(rb_io_t *fptr, int noraise)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
if (fptr->finalize) {
|
2003-04-14 13:04:43 +04:00
|
|
|
(*fptr->finalize)(fptr, noraise);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-04-14 13:04:43 +04:00
|
|
|
fptr_finalize(fptr, noraise);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2008-08-18 12:24:49 +04:00
|
|
|
static void
|
|
|
|
clear_readconv(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
if (fptr->readconv) {
|
|
|
|
rb_econv_close(fptr->readconv);
|
|
|
|
fptr->readconv = NULL;
|
|
|
|
}
|
2008-08-26 19:06:28 +04:00
|
|
|
if (fptr->cbuf) {
|
|
|
|
free(fptr->cbuf);
|
|
|
|
fptr->cbuf = NULL;
|
2008-08-18 12:24:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-18 16:06:42 +04:00
|
|
|
static void
|
|
|
|
clear_writeconv(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
if (fptr->writeconv) {
|
|
|
|
rb_econv_close(fptr->writeconv);
|
|
|
|
fptr->writeconv = NULL;
|
|
|
|
}
|
|
|
|
fptr->writeconv_initialized = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_codeconv(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
clear_readconv(fptr);
|
|
|
|
clear_writeconv(fptr);
|
|
|
|
}
|
|
|
|
|
2004-04-07 06:51:05 +04:00
|
|
|
int
|
* 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 13:30:50 +03:00
|
|
|
rb_io_fptr_finalize(rb_io_t *fptr)
|
2000-12-12 10:42:35 +03:00
|
|
|
{
|
2004-04-07 06:51:05 +04:00
|
|
|
if (!fptr) return 0;
|
2008-08-23 04:47:54 +04:00
|
|
|
fptr->pathv = Qnil;
|
2008-12-25 09:55:38 +03:00
|
|
|
fptr->write_lock = 0;
|
2004-12-08 16:26:27 +03:00
|
|
|
if (0 <= fptr->fd)
|
2004-12-06 14:19:27 +03:00
|
|
|
rb_io_fptr_cleanup(fptr, Qtrue);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->rbuf) {
|
|
|
|
free(fptr->rbuf);
|
|
|
|
fptr->rbuf = 0;
|
|
|
|
}
|
|
|
|
if (fptr->wbuf) {
|
|
|
|
free(fptr->wbuf);
|
|
|
|
fptr->wbuf = 0;
|
2004-08-19 11:33:15 +04:00
|
|
|
}
|
2008-08-18 16:06:42 +04:00
|
|
|
clear_codeconv(fptr);
|
2004-02-25 15:17:39 +03:00
|
|
|
free(fptr);
|
2004-04-07 06:51:05 +04:00
|
|
|
return 1;
|
2000-12-12 10:42:35 +03:00
|
|
|
}
|
|
|
|
|
2009-06-17 02:36:27 +04:00
|
|
|
size_t rb_econv_memsize(rb_econv_t *);
|
|
|
|
|
|
|
|
size_t
|
|
|
|
rb_io_memsize(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
size_t size = sizeof(rb_io_t);
|
|
|
|
size += fptr->rbuf_capa;
|
|
|
|
size += fptr->wbuf_capa;
|
|
|
|
size += fptr->cbuf_capa;
|
|
|
|
if (fptr->readconv) size += rb_econv_memsize(fptr->readconv);
|
|
|
|
if (fptr->writeconv) size += rb_econv_memsize(fptr->writeconv);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2002-02-05 10:56:31 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_close(VALUE io)
|
2000-05-01 13:42:38 +04: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
int fd;
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE write_io;
|
|
|
|
rb_io_t *write_fptr;
|
|
|
|
|
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (io != write_io) {
|
|
|
|
write_fptr = RFILE(write_io)->fptr;
|
|
|
|
if (write_fptr && 0 <= write_fptr->fd) {
|
|
|
|
rb_io_fptr_cleanup(write_fptr, Qtrue);
|
|
|
|
}
|
|
|
|
}
|
2000-05-01 13:42:38 +04:00
|
|
|
|
2002-02-05 10:56:31 +03:00
|
|
|
fptr = RFILE(io)->fptr;
|
2002-02-20 07:31:50 +03:00
|
|
|
if (!fptr) return Qnil;
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->fd < 0) return Qnil;
|
2000-05-01 13:42:38 +04:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fd = fptr->fd;
|
2002-02-05 10:56:31 +03:00
|
|
|
rb_io_fptr_cleanup(fptr, Qfalse);
|
2000-05-01 13:42:38 +04:00
|
|
|
rb_thread_fd_close(fd);
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (fptr->pid) {
|
|
|
|
rb_syswait(fptr->pid);
|
|
|
|
fptr->pid = 0;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.close => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Closes <em>ios</em> and flushes any pending writes to the operating
|
|
|
|
* system. The stream is unavailable for any further data operations;
|
|
|
|
* an <code>IOError</code> is raised if such an attempt is made. I/O
|
|
|
|
* streams are automatically closed when they are claimed by the
|
|
|
|
* garbage collector.
|
2006-03-28 05:50:11 +04:00
|
|
|
*
|
|
|
|
* If <em>ios</em> is opened by <code>IO.popen</code>,
|
|
|
|
* <code>close</code> sets <code>$?</code>.
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_close_m(VALUE io)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (rb_safe_level() >= 4 && !OBJ_UNTRUSTED(io)) {
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't close");
|
|
|
|
}
|
2002-01-18 17:24:01 +03:00
|
|
|
rb_io_check_closed(RFILE(io)->fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_close(io);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-03-04 10:04:11 +03:00
|
|
|
static VALUE
|
2006-07-27 12:25:18 +04:00
|
|
|
io_call_close(VALUE io)
|
2003-03-04 10:04:11 +03:00
|
|
|
{
|
|
|
|
return rb_funcall(io, rb_intern("close"), 0, 0);
|
|
|
|
}
|
|
|
|
|
2006-07-27 12:25:18 +04:00
|
|
|
static VALUE
|
|
|
|
io_close(VALUE io)
|
|
|
|
{
|
|
|
|
return rb_rescue(io_call_close, io, 0, 0);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.closed? => true or false
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns <code>true</code> if <em>ios</em> is completely closed (for
|
|
|
|
* duplex streams, both reader and writer), <code>false</code>
|
|
|
|
* otherwise.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.close #=> nil
|
|
|
|
* f.closed? #=> true
|
|
|
|
* f = IO.popen("/bin/sh","r+")
|
|
|
|
* f.close_write #=> nil
|
|
|
|
* f.closed? #=> false
|
|
|
|
* f.close_read #=> nil
|
|
|
|
* f.closed? #=> true
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_closed(VALUE io)
|
1999-01-20 07:59:39 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE write_io;
|
|
|
|
rb_io_t *write_fptr;
|
|
|
|
|
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (io != write_io) {
|
|
|
|
write_fptr = RFILE(write_io)->fptr;
|
|
|
|
if (write_fptr && 0 <= write_fptr->fd) {
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
fptr = RFILE(io)->fptr;
|
2004-10-29 16:28:32 +04:00
|
|
|
rb_io_check_initialized(fptr);
|
2004-12-08 16:26:27 +03:00
|
|
|
return 0 <= fptr->fd ? Qfalse : Qtrue;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.close_read => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Closes the read end of a duplex I/O stream (i.e., one that contains
|
|
|
|
* both a read and a write stream, such as a pipe). Will raise an
|
|
|
|
* <code>IOError</code> if the stream is not duplexed.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = IO.popen("/bin/sh","r+")
|
|
|
|
* f.close_read
|
|
|
|
* f.readlines
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* prog.rb:3:in `readlines': not opened for reading (IOError)
|
|
|
|
* from prog.rb:3
|
|
|
|
*/
|
|
|
|
|
* intern.h: add prototypes.
rb_gc_enable(), rb_gc_disable(), rb_gc_start(), rb_str_new5()
rb_str_buf_append(), rb_str_buf_cat(), rb_str_buf_cat2(),
rb_str_dup_frozen()
* ruby.h: added declaration.
rb_defout, rb_stdin, rb_stdout, rb_stderr, ruby_errinfo
* rubyio.h: changed double include guard macro to RUBYIO_H.
* array.c (inspect_call): make static.
* eval.c (dvar_asgn): ditto.
* io.c (rb_io_close_read): ditto.
* lex.c (rb_reserved_word): ditto.
* ruby.c: (req_list_head, req_list_last): ditto.
* ruby.c (require_libraries): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2001-12-17 10:52:35 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_close_read(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE write_io;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (rb_safe_level() >= 4 && !OBJ_UNTRUSTED(io)) {
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't close");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (is_socket(fptr->fd, fptr->pathv)) {
|
2004-12-08 16:26:27 +03:00
|
|
|
#ifndef SHUT_RD
|
|
|
|
# define SHUT_RD 0
|
|
|
|
#endif
|
|
|
|
if (shutdown(fptr->fd, SHUT_RD) < 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->mode &= ~FMODE_READABLE;
|
|
|
|
if (!(fptr->mode & FMODE_WRITABLE))
|
|
|
|
return rb_io_close(io);
|
|
|
|
return Qnil;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2007-11-20 06:16:53 +03:00
|
|
|
|
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (io != write_io) {
|
2008-01-31 00:24:24 +03:00
|
|
|
rb_io_t *wfptr;
|
2009-01-13 12:23:54 +03:00
|
|
|
rb_io_fptr_cleanup(fptr, Qfalse);
|
2008-01-31 00:24:24 +03:00
|
|
|
GetOpenFile(write_io, wfptr);
|
2008-08-27 21:19:19 +04:00
|
|
|
RFILE(io)->fptr = wfptr;
|
|
|
|
RFILE(write_io)->fptr = NULL;
|
|
|
|
rb_io_fptr_finalize(fptr);
|
2007-11-20 06:16:53 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
|
|
|
rb_raise(rb_eIOError, "closing non-duplex IO for reading");
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
return rb_io_close(io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.close_write => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Closes the write end of a duplex I/O stream (i.e., one that contains
|
|
|
|
* both a read and a write stream, such as a pipe). Will raise an
|
|
|
|
* <code>IOError</code> if the stream is not duplexed.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = IO.popen("/bin/sh","r+")
|
|
|
|
* f.close_write
|
|
|
|
* f.print "nowhere"
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* prog.rb:3:in `write': not opened for writing (IOError)
|
|
|
|
* from prog.rb:3:in `print'
|
|
|
|
* from prog.rb:3
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_close_write(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2008-01-31 00:24:24 +03:00
|
|
|
VALUE write_io;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (rb_safe_level() >= 4 && !OBJ_UNTRUSTED(io)) {
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't close");
|
|
|
|
}
|
2008-01-31 00:24:24 +03:00
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
GetOpenFile(write_io, fptr);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (is_socket(fptr->fd, fptr->pathv)) {
|
2004-12-08 16:26:27 +03:00
|
|
|
#ifndef SHUT_WR
|
|
|
|
# define SHUT_WR 1
|
|
|
|
#endif
|
|
|
|
if (shutdown(fptr->fd, SHUT_WR) < 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->mode &= ~FMODE_WRITABLE;
|
|
|
|
if (!(fptr->mode & FMODE_READABLE))
|
2008-01-31 00:24:24 +03:00
|
|
|
return rb_io_close(write_io);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
return Qnil;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->mode & FMODE_READABLE) {
|
|
|
|
rb_raise(rb_eIOError, "closing non-duplex IO for writing");
|
|
|
|
}
|
2008-01-31 00:24:24 +03:00
|
|
|
|
|
|
|
rb_io_close(write_io);
|
|
|
|
if (io != write_io) {
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
fptr->tied_io_for_writing = 0;
|
|
|
|
fptr->mode &= ~FMODE_DUPLEX;
|
|
|
|
}
|
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.sysseek(offset, whence=SEEK_SET) => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Seeks to a given <i>offset</i> in the stream according to the value
|
|
|
|
* of <i>whence</i> (see <code>IO#seek</code> for values of
|
|
|
|
* <i>whence</i>). Returns the new offset into the file.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.sysseek(-13, IO::SEEK_END) #=> 53
|
|
|
|
* f.sysread(10) #=> "And so on."
|
|
|
|
*/
|
|
|
|
|
2002-03-27 08:28:00 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_sysseek(int argc, VALUE *argv, VALUE io)
|
2002-03-27 08:28:00 +03:00
|
|
|
{
|
|
|
|
VALUE offset, ptrname;
|
2002-04-18 12:46:18 +04:00
|
|
|
int whence = SEEK_SET;
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-03-27 08:28:00 +03:00
|
|
|
off_t pos;
|
|
|
|
|
2002-04-18 12:46:18 +04:00
|
|
|
if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
|
|
|
|
whence = NUM2INT(ptrname);
|
|
|
|
}
|
2004-11-23 20:37:51 +03:00
|
|
|
pos = NUM2OFFT(offset);
|
2002-03-27 08:28:00 +03:00
|
|
|
GetOpenFile(io, fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if ((fptr->mode & FMODE_READABLE) && READ_DATA_BUFFERED(fptr)) {
|
2002-03-27 08:52:36 +03:00
|
|
|
rb_raise(rb_eIOError, "sysseek for buffered IO");
|
2002-03-27 08:28:00 +03:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if ((fptr->mode & FMODE_WRITABLE) && fptr->wbuf_len) {
|
2002-03-27 08:28:00 +03:00
|
|
|
rb_warn("sysseek for buffered IO");
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
pos = lseek(fptr->fd, pos, whence);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (pos == -1) rb_sys_fail_path(fptr->pathv);
|
2002-03-27 08:28:00 +03:00
|
|
|
|
|
|
|
return OFFT2NUM(pos);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2005-01-25 07:03:02 +03:00
|
|
|
* ios.syswrite(string) => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Writes the given string to <em>ios</em> using a low-level write.
|
|
|
|
* Returns the number of bytes written. Do not mix with other methods
|
|
|
|
* that write to <em>ios</em> or you may get unpredictable results.
|
|
|
|
* Raises <code>SystemCallError</code> on error.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("out", "w")
|
|
|
|
* f.syswrite("ABCDEF") #=> 6
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_syswrite(VALUE io, VALUE str)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-08-21 19:47:54 +04:00
|
|
|
long n;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
rb_secure(4);
|
|
|
|
if (TYPE(str) != T_STRING)
|
1999-01-20 07:59:39 +03:00
|
|
|
str = rb_obj_as_string(str);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
io = GetWriteIO(io);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(io, fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_check_writable(fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (fptr->wbuf_len) {
|
2002-02-07 07:18:08 +03:00
|
|
|
rb_warn("syswrite for buffered IO");
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (!rb_thread_fd_writable(fptr->fd)) {
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_io_check_closed(fptr);
|
|
|
|
}
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
|
2006-08-31 14:47:44 +04:00
|
|
|
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-08-23 04:47:54 +04:00
|
|
|
if (n == -1) rb_sys_fail_path(fptr->pathv);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-08-21 19:47:54 +04:00
|
|
|
return LONG2FIX(n);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-08-11 20:57:14 +04:00
|
|
|
* ios.sysread(integer[, outbuf]) => string
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Reads <i>integer</i> bytes from <em>ios</em> using a low-level
|
|
|
|
* read and returns them as a string. Do not mix with other methods
|
|
|
|
* that read from <em>ios</em> or you may get unpredictable results.
|
2004-08-11 20:57:14 +04:00
|
|
|
* If the optional <i>outbuf</i> argument is present, it must reference
|
|
|
|
* a String, which will receive the data.
|
2003-12-27 03:44:05 +03:00
|
|
|
* Raises <code>SystemCallError</code> on error and
|
|
|
|
* <code>EOFError</code> at end of file.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.sysread(16) #=> "This is line one"
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_sysread(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-12-11 12:32:41 +03:00
|
|
|
VALUE len, str;
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-08-21 19:47:54 +04:00
|
|
|
long n, ilen;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-12-11 12:32:41 +03:00
|
|
|
rb_scan_args(argc, argv, "11", &len, &str);
|
2002-08-21 19:47:54 +04:00
|
|
|
ilen = NUM2LONG(len);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-12-11 12:32:41 +03:00
|
|
|
if (NIL_P(str)) {
|
|
|
|
str = rb_str_new(0, ilen);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
StringValue(str);
|
|
|
|
rb_str_modify(str);
|
|
|
|
rb_str_resize(str, ilen);
|
|
|
|
}
|
2003-06-23 12:41:07 +04:00
|
|
|
if (ilen == 0) return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-23 20:37:51 +03:00
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (READ_DATA_BUFFERED(fptr)) {
|
2004-11-23 20:37:51 +03:00
|
|
|
rb_raise(rb_eIOError, "sysread for buffered IO");
|
|
|
|
}
|
2004-11-29 18:58:18 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
n = fptr->fd;
|
|
|
|
rb_thread_wait_fd(fptr->fd);
|
2004-11-27 05:21:53 +03:00
|
|
|
rb_io_check_closed(fptr);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) != ilen) {
|
2004-11-29 18:58:18 +03:00
|
|
|
rb_raise(rb_eRuntimeError, "buffer string modified");
|
|
|
|
}
|
2007-11-23 11:35:29 +03:00
|
|
|
|
|
|
|
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), ilen);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-03-20 09:27:22 +03:00
|
|
|
if (n == -1) {
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2003-03-20 09:27:22 +03:00
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
rb_str_set_len(str, n);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (n == 0 && ilen > 0) {
|
|
|
|
rb_eof_error();
|
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
rb_str_resize(str, n);
|
1999-01-20 07:59:39 +03:00
|
|
|
OBJ_TAINT(str);
|
|
|
|
|
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_binmode(VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
2008-10-20 19:53:14 +04:00
|
|
|
if (fptr->readconv)
|
|
|
|
rb_econv_binmode(fptr->readconv);
|
|
|
|
if (fptr->writeconv)
|
|
|
|
rb_econv_binmode(fptr->writeconv);
|
|
|
|
fptr->mode |= FMODE_BINMODE;
|
|
|
|
fptr->mode &= ~FMODE_TEXTMODE;
|
|
|
|
fptr->writeconv_pre_ecflags &= ~(ECONV_UNIVERSAL_NEWLINE_DECORATOR|ECONV_CRLF_NEWLINE_DECORATOR|ECONV_CR_NEWLINE_DECORATOR);
|
|
|
|
return io;
|
|
|
|
}
|
2008-10-16 19:25:25 +04:00
|
|
|
|
2008-10-21 08:31:15 +04:00
|
|
|
VALUE
|
2008-10-20 19:53:14 +04:00
|
|
|
rb_io_ascii8bit_binmode(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
2008-10-16 19:25:25 +04:00
|
|
|
if (fptr->readconv) {
|
|
|
|
rb_econv_close(fptr->readconv);
|
|
|
|
fptr->readconv = NULL;
|
|
|
|
}
|
|
|
|
if (fptr->writeconv) {
|
|
|
|
rb_econv_close(fptr->writeconv);
|
|
|
|
fptr->writeconv = NULL;
|
|
|
|
}
|
2007-12-21 10:02:55 +03:00
|
|
|
fptr->mode |= FMODE_BINMODE;
|
2008-08-22 20:44:00 +04:00
|
|
|
fptr->mode &= ~FMODE_TEXTMODE;
|
2008-10-16 19:25:25 +04:00
|
|
|
|
|
|
|
fptr->encs.enc = rb_ascii8bit_encoding();
|
|
|
|
fptr->encs.enc2 = NULL;
|
|
|
|
fptr->encs.ecflags = 0;
|
|
|
|
fptr->encs.ecopts = Qnil;
|
|
|
|
clear_codeconv(fptr);
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.binmode => ios
|
|
|
|
*
|
2008-10-18 09:07:38 +04:00
|
|
|
* Puts <em>ios</em> into binary mode.
|
|
|
|
* Once a stream is in binary mode, it cannot be reset to nonbinary mode.
|
|
|
|
*
|
|
|
|
* - newline conversion disabled
|
|
|
|
* - encoding conversion disabled
|
|
|
|
* - content is treated as ASCII-8BIT
|
|
|
|
*
|
2007-11-20 06:16:53 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_binmode_m(VALUE io)
|
|
|
|
{
|
|
|
|
VALUE write_io;
|
|
|
|
|
2008-10-20 19:53:14 +04:00
|
|
|
rb_io_ascii8bit_binmode(io);
|
2007-12-23 05:01:34 +03:00
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (write_io != io)
|
2008-10-20 19:53:14 +04:00
|
|
|
rb_io_ascii8bit_binmode(write_io);
|
2007-11-20 06:16:53 +03:00
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2008-06-21 19:08:57 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.binmode? => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <em>ios</em> is binmode.
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_io_binmode_p(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
return fptr->mode & FMODE_BINMODE ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
2006-06-20 22:02:17 +04:00
|
|
|
static const char*
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_fmode_modestr(int fmode)
|
2003-05-09 12:12:52 +04:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
# define MODE_BTMODE(a,b,c) ((fmode & FMODE_BINMODE) ? (b) : \
|
|
|
|
(fmode & FMODE_TEXTMODE) ? (c) : (a))
|
|
|
|
if (fmode & FMODE_APPEND) {
|
|
|
|
if ((fmode & FMODE_READWRITE) == FMODE_READWRITE) {
|
2008-08-22 20:44:00 +04:00
|
|
|
return MODE_BTMODE("a+", "ab+", "at+");
|
2004-10-06 11:40:06 +04:00
|
|
|
}
|
2008-08-22 20:44:00 +04:00
|
|
|
return MODE_BTMODE("a", "ab", "at");
|
2004-10-06 11:40:06 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
switch (fmode & FMODE_READWRITE) {
|
2003-05-09 12:12:52 +04:00
|
|
|
case FMODE_READABLE:
|
2008-08-22 20:44:00 +04:00
|
|
|
return MODE_BTMODE("r", "rb", "rt");
|
2003-05-09 12:12:52 +04:00
|
|
|
case FMODE_WRITABLE:
|
2008-08-22 20:44:00 +04:00
|
|
|
return MODE_BTMODE("w", "wb", "wt");
|
2003-05-09 12:12:52 +04:00
|
|
|
case FMODE_READWRITE:
|
2008-09-05 15:30:35 +04:00
|
|
|
if (fmode & FMODE_CREATE) {
|
2008-08-22 20:44:00 +04:00
|
|
|
return MODE_BTMODE("w+", "wb+", "wt+");
|
2004-10-18 06:29:43 +04:00
|
|
|
}
|
2008-08-22 20:44:00 +04:00
|
|
|
return MODE_BTMODE("r+", "rb+", "rt+");
|
2003-05-09 12:12:52 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_raise(rb_eArgError, "invalid access fmode 0x%x", fmode);
|
2004-10-05 05:37:46 +04:00
|
|
|
return NULL; /* not reached */
|
2003-05-09 12:12:52 +04:00
|
|
|
}
|
|
|
|
|
2009-07-09 18:47:48 +04:00
|
|
|
static int
|
2009-07-10 17:17:43 +04:00
|
|
|
io_encname_bom_p(const char *name, long len)
|
|
|
|
{
|
2009-07-09 18:47:48 +04:00
|
|
|
if (len) {
|
2009-07-10 17:17:43 +04:00
|
|
|
if (len > 4 && STRNCASECMP(name + len - 4, "-bom", 4) == 0)
|
2009-07-09 18:47:48 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char *p = strchr(name, ':');
|
|
|
|
if (!p) p = name + strlen(name);
|
2009-07-10 17:17:43 +04:00
|
|
|
if (p - name > 4 && STRNCASECMP(p - 4, "-bom", 4) == 0)
|
2009-07-09 18:47:48 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
int
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_modestr_fmode(const char *modestr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
int fmode = 0;
|
2009-07-09 18:47:48 +04:00
|
|
|
const char *m = modestr, *p = NULL;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-06-05 11:19:39 +04:00
|
|
|
switch (*m++) {
|
1998-01-16 15:13:05 +03:00
|
|
|
case 'r':
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode |= FMODE_READABLE;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case 'w':
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode |= FMODE_WRITABLE | FMODE_TRUNC | FMODE_CREATE;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case 'a':
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode |= FMODE_WRITABLE | FMODE_APPEND | FMODE_CREATE;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
default:
|
1999-08-13 09:45:20 +04:00
|
|
|
error:
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_raise(rb_eArgError, "invalid access mode %s", modestr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
while (*m) {
|
|
|
|
switch (*m++) {
|
2007-12-12 16:23:07 +03:00
|
|
|
case 'b':
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode |= FMODE_BINMODE;
|
2002-04-24 08:54:16 +04:00
|
|
|
break;
|
2008-08-22 20:44:00 +04:00
|
|
|
case 't':
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode |= FMODE_TEXTMODE;
|
2008-08-22 20:44:00 +04:00
|
|
|
break;
|
2007-12-12 16:23:07 +03:00
|
|
|
case '+':
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode |= FMODE_READWRITE;
|
2002-04-24 08:54:16 +04:00
|
|
|
break;
|
2007-12-12 16:23:07 +03:00
|
|
|
default:
|
2002-04-24 08:54:16 +04:00
|
|
|
goto error;
|
2007-12-12 16:23:07 +03:00
|
|
|
case ':':
|
2009-07-09 18:47:48 +04:00
|
|
|
p = m;
|
2008-08-22 20:44:00 +04:00
|
|
|
goto finished;
|
2002-04-24 08:54:16 +04:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2008-08-26 20:09:29 +04:00
|
|
|
finished:
|
2008-09-05 15:30:35 +04:00
|
|
|
if ((fmode & FMODE_BINMODE) && (fmode & FMODE_TEXTMODE))
|
2008-08-22 20:44:00 +04:00
|
|
|
goto error;
|
2009-07-09 18:47:48 +04:00
|
|
|
if (p && io_encname_bom_p(p, 0))
|
|
|
|
fmode |= FMODE_STRIP_BOM;
|
2008-08-22 20:44:00 +04:00
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
return fmode;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2004-11-18 04:11:01 +03:00
|
|
|
int
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_oflags_fmode(int oflags)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
int fmode = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
|
2002-03-29 17:50:09 +03:00
|
|
|
case O_RDONLY:
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode = FMODE_READABLE;
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
|
|
|
case O_WRONLY:
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode = FMODE_WRITABLE;
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
|
|
|
case O_RDWR:
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode = FMODE_READWRITE;
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
if (oflags & O_APPEND) {
|
|
|
|
fmode |= FMODE_APPEND;
|
2004-10-06 11:40:06 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
if (oflags & O_TRUNC) {
|
|
|
|
fmode |= FMODE_TRUNC;
|
2008-08-19 22:38:32 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
if (oflags & O_CREAT) {
|
|
|
|
fmode |= FMODE_CREATE;
|
2004-10-19 14:25:23 +04:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifdef O_BINARY
|
2008-09-05 15:30:35 +04:00
|
|
|
if (oflags & O_BINARY) {
|
|
|
|
fmode |= FMODE_BINMODE;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
return fmode;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-08-19 23:17:46 +04:00
|
|
|
static int
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_fmode_oflags(int fmode)
|
2001-06-05 11:19:39 +04:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags = 0;
|
2001-06-05 11:19:39 +04:00
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
switch (fmode & FMODE_READWRITE) {
|
2008-08-19 22:38:32 +04:00
|
|
|
case FMODE_READABLE:
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags |= O_RDONLY;
|
2008-08-19 22:38:32 +04:00
|
|
|
break;
|
|
|
|
case FMODE_WRITABLE:
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags |= O_WRONLY;
|
2008-08-19 22:38:32 +04:00
|
|
|
break;
|
|
|
|
case FMODE_READWRITE:
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags |= O_RDWR;
|
2008-08-19 22:38:32 +04:00
|
|
|
break;
|
2001-06-05 11:19:39 +04:00
|
|
|
}
|
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
if (fmode & FMODE_APPEND) {
|
|
|
|
oflags |= O_APPEND;
|
2008-08-19 22:38:32 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
if (fmode & FMODE_TRUNC) {
|
|
|
|
oflags |= O_TRUNC;
|
2008-08-19 22:38:32 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
if (fmode & FMODE_CREATE) {
|
|
|
|
oflags |= O_CREAT;
|
2008-08-19 22:38:32 +04:00
|
|
|
}
|
2001-06-05 11:19:39 +04:00
|
|
|
#ifdef O_BINARY
|
2008-09-05 15:30:35 +04:00
|
|
|
if (fmode & FMODE_BINMODE) {
|
|
|
|
oflags |= O_BINARY;
|
2001-06-05 11:19:39 +04:00
|
|
|
}
|
2008-08-19 22:38:32 +04:00
|
|
|
#endif
|
2001-06-05 11:19:39 +04:00
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
return oflags;
|
2008-08-19 22:38:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_modestr_oflags(const char *modestr)
|
2008-08-19 22:38:32 +04:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
return rb_io_fmode_oflags(rb_io_modestr_fmode(modestr));
|
2001-06-05 11:19:39 +04:00
|
|
|
}
|
|
|
|
|
2006-06-20 22:02:17 +04:00
|
|
|
static const char*
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_oflags_modestr(int oflags)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2004-10-06 11:40:06 +04:00
|
|
|
#ifdef O_BINARY
|
2008-09-05 15:30:35 +04:00
|
|
|
# define MODE_BINARY(a,b) ((oflags & O_BINARY) ? (b) : (a))
|
2004-10-06 11:40:06 +04:00
|
|
|
#else
|
|
|
|
# define MODE_BINARY(a,b) (a)
|
|
|
|
#endif
|
2008-09-05 15:30:35 +04:00
|
|
|
if (oflags & O_APPEND) {
|
|
|
|
if ((oflags & O_RDWR) == O_RDWR) {
|
2004-10-06 11:40:06 +04:00
|
|
|
return MODE_BINARY("a+", "ab+");
|
|
|
|
}
|
|
|
|
return MODE_BINARY("a", "ab");
|
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
switch (oflags & (O_RDONLY|O_WRONLY|O_RDWR)) {
|
2002-03-29 17:50:09 +03:00
|
|
|
case O_RDONLY:
|
2004-10-06 11:40:06 +04:00
|
|
|
return MODE_BINARY("r", "rb");
|
1999-08-13 09:45:20 +04:00
|
|
|
case O_WRONLY:
|
2004-10-06 11:40:06 +04:00
|
|
|
return MODE_BINARY("w", "wb");
|
1999-08-13 09:45:20 +04:00
|
|
|
case O_RDWR:
|
2004-10-06 11:40:06 +04:00
|
|
|
return MODE_BINARY("r+", "rb+");
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_raise(rb_eArgError, "invalid access oflags 0x%x", oflags);
|
2004-10-06 11:40:06 +04:00
|
|
|
return NULL; /* not reached */
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2008-10-07 21:39:44 +04:00
|
|
|
/*
|
|
|
|
* Convert external/internal encodings to enc/enc2
|
|
|
|
* NULL => use default encoding
|
|
|
|
* Qnil => no encoding specified (internal only)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
rb_io_ext_int_to_encs(rb_encoding *ext, rb_encoding *intern, rb_encoding **enc, rb_encoding **enc2)
|
|
|
|
{
|
|
|
|
int default_ext = 0;
|
|
|
|
|
|
|
|
if (ext == NULL) {
|
|
|
|
ext = rb_default_external_encoding();
|
|
|
|
default_ext = 1;
|
|
|
|
}
|
|
|
|
if (intern == NULL && ext != rb_ascii8bit_encoding())
|
|
|
|
/* If external is ASCII-8BIT, no default transcoding */
|
|
|
|
intern = rb_default_internal_encoding();
|
|
|
|
if (intern == NULL || intern == (rb_encoding *)Qnil || intern == ext) {
|
|
|
|
/* No internal encoding => use external + no transcoding */
|
2009-07-07 05:15:32 +04:00
|
|
|
*enc = (default_ext && intern != ext) ? NULL : ext;
|
2008-10-07 21:39:44 +04:00
|
|
|
*enc2 = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*enc = intern;
|
|
|
|
*enc2 = ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-23 18:56:41 +03:00
|
|
|
static void
|
2008-08-20 00:20:31 +04:00
|
|
|
parse_mode_enc(const char *estr, rb_encoding **enc_p, rb_encoding **enc2_p)
|
2007-12-12 16:23:07 +03:00
|
|
|
{
|
2008-10-07 21:39:44 +04:00
|
|
|
const char *p;
|
|
|
|
char encname[ENCODING_MAXNAMELEN+1];
|
2007-12-22 19:21:09 +03:00
|
|
|
int idx, idx2;
|
2008-10-07 21:39:44 +04:00
|
|
|
rb_encoding *ext_enc, *int_enc;
|
2008-03-19 18:29:09 +03:00
|
|
|
|
2008-10-07 21:39:44 +04:00
|
|
|
/* parse estr as "enc" or "enc2:enc" or "enc:-" */
|
2008-08-18 11:55:04 +04:00
|
|
|
|
2008-10-07 21:39:44 +04:00
|
|
|
p = strrchr(estr, ':');
|
|
|
|
if (p) {
|
2009-04-26 13:46:41 +04:00
|
|
|
long len = (p++) - estr;
|
2008-10-07 21:39:44 +04:00
|
|
|
if (len == 0 || len > ENCODING_MAXNAMELEN)
|
|
|
|
idx = -1;
|
|
|
|
else {
|
2009-07-09 18:47:48 +04:00
|
|
|
if (io_encname_bom_p(estr, len))
|
|
|
|
len -= 4;
|
2008-10-07 21:39:44 +04:00
|
|
|
memcpy(encname, estr, len);
|
|
|
|
encname[len] = '\0';
|
|
|
|
estr = encname;
|
|
|
|
idx = rb_enc_find_index(encname);
|
|
|
|
}
|
2007-12-23 18:56:41 +03:00
|
|
|
}
|
2009-07-09 18:47:48 +04:00
|
|
|
else {
|
|
|
|
long len = strlen(estr);
|
|
|
|
if (io_encname_bom_p(estr, len)) {
|
|
|
|
len -= 4;
|
|
|
|
memcpy(encname, estr, len);
|
|
|
|
encname[len] = '\0';
|
|
|
|
estr = encname;
|
|
|
|
}
|
2008-10-07 21:39:44 +04:00
|
|
|
idx = rb_enc_find_index(estr);
|
2009-07-09 18:47:48 +04:00
|
|
|
}
|
2008-10-07 21:39:44 +04:00
|
|
|
|
|
|
|
if (idx >= 0)
|
|
|
|
ext_enc = rb_enc_from_index(idx);
|
2007-12-23 18:56:41 +03:00
|
|
|
else {
|
2008-10-07 21:39:44 +04:00
|
|
|
if (idx != -2)
|
|
|
|
rb_warn("Unsupported encoding %s ignored", estr);
|
|
|
|
ext_enc = NULL;
|
2007-12-23 18:56:41 +03:00
|
|
|
}
|
|
|
|
|
2008-10-07 21:39:44 +04:00
|
|
|
int_enc = NULL;
|
|
|
|
if (p) {
|
|
|
|
if (*p == '-' && *(p+1) == '\0') {
|
|
|
|
/* Special case - "-" => no transcoding */
|
|
|
|
int_enc = (rb_encoding *)Qnil;
|
2007-12-12 16:23:07 +03:00
|
|
|
}
|
2007-12-23 18:56:41 +03:00
|
|
|
else {
|
2008-10-07 21:39:44 +04:00
|
|
|
idx2 = rb_enc_find_index(p);
|
|
|
|
if (idx2 < 0)
|
|
|
|
rb_warn("Unsupported encoding %s ignored", p);
|
|
|
|
else if (idx2 == idx) {
|
|
|
|
rb_warn("Ignoring internal encoding %s: it is identical to external encoding %s", p, estr);
|
|
|
|
int_enc = (rb_encoding *)Qnil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
int_enc = rb_enc_from_index(idx2);
|
2007-12-12 16:23:07 +03:00
|
|
|
}
|
|
|
|
}
|
2008-10-07 21:39:44 +04:00
|
|
|
|
|
|
|
rb_io_ext_int_to_encs(ext_enc, int_enc, enc_p, enc2_p);
|
2007-12-12 16:23:07 +03:00
|
|
|
}
|
|
|
|
|
2008-08-20 00:20:31 +04:00
|
|
|
static void
|
|
|
|
mode_enc(rb_io_t *fptr, const char *estr)
|
|
|
|
{
|
|
|
|
clear_codeconv(fptr);
|
|
|
|
|
2008-08-24 11:49:13 +04:00
|
|
|
parse_mode_enc(estr, &fptr->encs.enc, &fptr->encs.enc2);
|
2008-08-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
|
2008-09-24 21:10:03 +04:00
|
|
|
static void
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_mode_enc(rb_io_t *fptr, const char *modestr)
|
2007-12-23 18:56:41 +03:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
const char *p = strchr(modestr, ':');
|
2007-12-23 18:56:41 +03:00
|
|
|
if (p) {
|
|
|
|
mode_enc(fptr, p+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-21 13:18:34 +04:00
|
|
|
int
|
|
|
|
rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p)
|
2008-08-20 00:20:31 +04:00
|
|
|
{
|
2008-12-19 11:22:45 +03:00
|
|
|
VALUE encoding=Qnil, extenc=Qundef, intenc=Qundef, tmp;
|
2008-08-20 00:20:31 +04:00
|
|
|
int extracted = 0;
|
2008-12-19 11:22:45 +03:00
|
|
|
rb_encoding *extencoding = NULL;
|
|
|
|
rb_encoding *intencoding = NULL;
|
|
|
|
|
2008-08-20 00:20:31 +04:00
|
|
|
if (!NIL_P(opt)) {
|
|
|
|
VALUE v;
|
2008-12-19 11:22:45 +03:00
|
|
|
v = rb_hash_lookup2(opt, sym_encoding, Qnil);
|
|
|
|
if (v != Qnil) encoding = v;
|
|
|
|
v = rb_hash_lookup2(opt, sym_extenc, Qundef);
|
|
|
|
if (v != Qnil) extenc = v;
|
|
|
|
v = rb_hash_lookup2(opt, sym_intenc, Qundef);
|
|
|
|
if (v != Qundef) intenc = v;
|
|
|
|
}
|
|
|
|
if ((extenc != Qundef || intenc != Qundef) && !NIL_P(encoding)) {
|
|
|
|
rb_warn("Ignoring encoding parameter '%s': %s_encoding is used",
|
|
|
|
StringValueCStr(encoding),
|
|
|
|
extenc == Qundef ? "internal" : "external");
|
|
|
|
encoding = Qnil;
|
|
|
|
}
|
|
|
|
if (extenc != Qundef && !NIL_P(extenc)) {
|
|
|
|
extencoding = rb_to_encoding(extenc);
|
|
|
|
}
|
|
|
|
if (intenc != Qundef) {
|
|
|
|
if (NIL_P(intenc)) {
|
|
|
|
/* internal_encoding: nil => no transcoding */
|
|
|
|
intencoding = (rb_encoding *)Qnil;
|
2008-08-20 00:20:31 +04:00
|
|
|
}
|
2008-12-19 11:22:45 +03:00
|
|
|
else if (!NIL_P(tmp = rb_check_string_type(intenc))) {
|
|
|
|
char *p = StringValueCStr(tmp);
|
|
|
|
|
|
|
|
if (*p == '-' && *(p+1) == '\0') {
|
|
|
|
/* Special case - "-" => no transcoding */
|
|
|
|
intencoding = (rb_encoding *)Qnil;
|
2008-10-07 21:39:44 +04:00
|
|
|
}
|
2008-12-19 11:22:45 +03:00
|
|
|
else {
|
2008-10-07 21:39:44 +04:00
|
|
|
intencoding = rb_to_encoding(intenc);
|
2008-08-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
}
|
2008-12-19 11:22:45 +03:00
|
|
|
else {
|
|
|
|
intencoding = rb_to_encoding(intenc);
|
2008-08-20 00:20:31 +04:00
|
|
|
}
|
2008-12-19 11:22:45 +03:00
|
|
|
if (extencoding == intencoding) {
|
|
|
|
intencoding = (rb_encoding *)Qnil;
|
2008-08-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
}
|
2008-12-19 11:22:45 +03:00
|
|
|
if (!NIL_P(encoding)) {
|
|
|
|
extracted = 1;
|
|
|
|
parse_mode_enc(StringValueCStr(encoding), enc_p, enc2_p);
|
|
|
|
}
|
|
|
|
else if (extenc != Qundef || intenc != Qundef) {
|
|
|
|
extracted = 1;
|
|
|
|
rb_io_ext_int_to_encs(extencoding, intencoding, enc_p, enc2_p);
|
|
|
|
}
|
2008-08-20 00:20:31 +04:00
|
|
|
return extracted;
|
|
|
|
}
|
|
|
|
|
2008-08-24 11:49:13 +04:00
|
|
|
typedef struct rb_io_enc_t convconfig_t;
|
2008-08-20 14:24:37 +04:00
|
|
|
|
2008-09-12 21:58:58 +04:00
|
|
|
static void
|
|
|
|
validate_enc_binmode(int fmode, rb_encoding *enc, rb_encoding *enc2)
|
|
|
|
{
|
|
|
|
if ((fmode & FMODE_READABLE) &&
|
|
|
|
!enc2 &&
|
|
|
|
!(fmode & FMODE_BINMODE) &&
|
|
|
|
!rb_enc_asciicompat(enc ? enc : rb_default_external_encoding()))
|
|
|
|
rb_raise(rb_eArgError, "ASCII incompatible encoding needs binmode");
|
|
|
|
}
|
|
|
|
|
2008-10-28 15:00:42 +03:00
|
|
|
static void
|
|
|
|
extract_binmode(VALUE opthash, int *fmode)
|
|
|
|
{
|
|
|
|
if (!NIL_P(opthash)) {
|
|
|
|
VALUE v;
|
|
|
|
v = rb_hash_aref(opthash, sym_textmode);
|
|
|
|
if (!NIL_P(v) && RTEST(v))
|
|
|
|
*fmode |= FMODE_TEXTMODE;
|
|
|
|
v = rb_hash_aref(opthash, sym_binmode);
|
|
|
|
if (!NIL_P(v) && RTEST(v))
|
|
|
|
*fmode |= FMODE_BINMODE;
|
|
|
|
|
|
|
|
if ((*fmode & FMODE_BINMODE) && (*fmode & FMODE_TEXTMODE))
|
|
|
|
rb_raise(rb_eArgError, "both textmode and binmode specified");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-20 14:24:37 +04:00
|
|
|
static void
|
2008-09-17 20:39:47 +04:00
|
|
|
rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
|
2008-09-05 15:30:35 +04:00
|
|
|
int *oflags_p, int *fmode_p, convconfig_t *convconfig_p)
|
2008-08-20 14:24:37 +04:00
|
|
|
{
|
2008-09-04 15:20:53 +04:00
|
|
|
VALUE vmode;
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags, fmode;
|
2008-08-20 14:24:37 +04:00
|
|
|
rb_encoding *enc, *enc2;
|
2008-09-03 19:11:46 +04:00
|
|
|
int ecflags;
|
2008-09-03 22:18:10 +04:00
|
|
|
VALUE ecopts;
|
2008-09-17 20:39:47 +04:00
|
|
|
int has_enc = 0, has_vmode = 0;
|
2008-08-21 21:44:38 +04:00
|
|
|
VALUE intmode;
|
2008-08-20 14:24:37 +04:00
|
|
|
|
2008-09-04 15:20:53 +04:00
|
|
|
vmode = *vmode_p;
|
2008-08-21 21:58:50 +04:00
|
|
|
|
2008-10-07 21:39:44 +04:00
|
|
|
/* Set to defaults */
|
|
|
|
rb_io_ext_int_to_encs(NULL, NULL, &enc, &enc2);
|
2008-08-20 14:24:37 +04:00
|
|
|
|
2008-09-04 15:20:53 +04:00
|
|
|
if (NIL_P(vmode)) {
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode = FMODE_READABLE;
|
|
|
|
oflags = O_RDONLY;
|
2008-08-20 14:24:37 +04:00
|
|
|
}
|
2008-09-04 15:20:53 +04:00
|
|
|
else if (!NIL_P(intmode = rb_check_to_integer(vmode, "to_int"))) {
|
|
|
|
vmode = intmode;
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = NUM2INT(intmode);
|
|
|
|
fmode = rb_io_oflags_fmode(oflags);
|
2008-08-20 14:24:37 +04:00
|
|
|
}
|
2008-08-21 21:44:38 +04:00
|
|
|
else {
|
2008-08-20 14:24:37 +04:00
|
|
|
const char *p;
|
2008-09-17 20:39:47 +04:00
|
|
|
|
|
|
|
vmode_handle:
|
2008-09-04 15:20:53 +04:00
|
|
|
SafeStringValue(vmode);
|
|
|
|
p = StringValueCStr(vmode);
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode = rb_io_modestr_fmode(p);
|
|
|
|
oflags = rb_io_fmode_oflags(fmode);
|
2008-08-20 14:24:37 +04:00
|
|
|
p = strchr(p, ':');
|
|
|
|
if (p) {
|
|
|
|
has_enc = 1;
|
|
|
|
parse_mode_enc(p+1, &enc, &enc2);
|
2009-07-09 18:47:48 +04:00
|
|
|
if (io_encname_bom_p(p+1, 0))
|
|
|
|
fmode |= FMODE_STRIP_BOM;
|
2008-08-20 14:24:37 +04:00
|
|
|
}
|
2008-10-20 20:57:19 +04:00
|
|
|
else {
|
|
|
|
rb_encoding *e;
|
|
|
|
|
|
|
|
e = (fmode & FMODE_BINMODE) ? rb_ascii8bit_encoding() : NULL;
|
|
|
|
rb_io_ext_int_to_encs(e, NULL, &enc, &enc2);
|
|
|
|
}
|
2008-08-20 14:24:37 +04:00
|
|
|
}
|
|
|
|
|
2008-08-24 13:13:55 +04:00
|
|
|
if (NIL_P(opthash)) {
|
2008-09-03 19:11:46 +04:00
|
|
|
ecflags = 0;
|
2008-09-03 22:18:10 +04:00
|
|
|
ecopts = Qnil;
|
2008-08-24 13:13:55 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-08-23 06:23:42 +04:00
|
|
|
VALUE v;
|
2008-10-28 15:00:42 +03:00
|
|
|
extract_binmode(opthash, &fmode);
|
2008-08-23 06:23:42 +04:00
|
|
|
#ifdef O_BINARY
|
2008-10-28 15:00:42 +03:00
|
|
|
if (fmode & FMODE_BINMODE)
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags |= O_BINARY;
|
2008-08-23 06:23:42 +04:00
|
|
|
#endif
|
2008-09-17 20:39:47 +04:00
|
|
|
if (!has_vmode) {
|
|
|
|
v = rb_hash_aref(opthash, sym_mode);
|
|
|
|
if (!NIL_P(v)) {
|
|
|
|
if (!NIL_P(vmode)) {
|
|
|
|
rb_raise(rb_eArgError, "mode specified twice");
|
|
|
|
}
|
|
|
|
has_vmode = 1;
|
|
|
|
vmode = v;
|
|
|
|
goto vmode_handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v = rb_hash_aref(opthash, sym_perm);
|
|
|
|
if (!NIL_P(v)) {
|
|
|
|
if (vperm_p) {
|
|
|
|
if (!NIL_P(*vperm_p)) {
|
|
|
|
rb_raise(rb_eArgError, "perm specified twice");
|
|
|
|
}
|
|
|
|
*vperm_p = v;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* perm no use, just ignore */
|
|
|
|
}
|
|
|
|
}
|
2008-09-03 22:18:10 +04:00
|
|
|
ecflags = rb_econv_prepare_opts(opthash, &ecopts);
|
2008-08-23 06:23:42 +04:00
|
|
|
|
2008-10-21 13:18:34 +04:00
|
|
|
if (rb_io_extract_encoding_option(opthash, &enc, &enc2)) {
|
2008-08-20 14:24:37 +04:00
|
|
|
if (has_enc) {
|
2008-08-31 18:24:51 +04:00
|
|
|
rb_raise(rb_eArgError, "encoding specified twice");
|
2008-08-20 14:24:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 21:58:58 +04:00
|
|
|
validate_enc_binmode(fmode, enc, enc2);
|
2008-09-06 02:26:39 +04:00
|
|
|
|
2008-09-04 15:20:53 +04:00
|
|
|
*vmode_p = vmode;
|
2008-08-21 21:58:50 +04:00
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
*oflags_p = oflags;
|
|
|
|
*fmode_p = fmode;
|
2008-08-20 14:24:37 +04:00
|
|
|
convconfig_p->enc = enc;
|
|
|
|
convconfig_p->enc2 = enc2;
|
2008-09-04 14:22:11 +04:00
|
|
|
convconfig_p->ecflags = ecflags;
|
2008-09-03 22:18:10 +04:00
|
|
|
convconfig_p->ecopts = ecopts;
|
2008-08-20 14:24:37 +04:00
|
|
|
}
|
|
|
|
|
2007-11-20 13:47:53 +03:00
|
|
|
struct sysopen_struct {
|
2008-09-04 08:01:13 +04:00
|
|
|
const char *fname;
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags;
|
2008-09-04 15:20:53 +04:00
|
|
|
mode_t perm;
|
2009-02-25 11:36:45 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
int wchar;
|
|
|
|
#endif
|
2007-11-20 13:47:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
sysopen_func(void *ptr)
|
|
|
|
{
|
|
|
|
struct sysopen_struct *data = ptr;
|
2009-02-25 11:36:45 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (data->wchar)
|
2009-02-26 04:58:20 +03:00
|
|
|
return (VALUE)rb_w32_wopen((WCHAR *)data->fname, data->oflags,
|
|
|
|
data->perm);
|
2009-02-25 11:36:45 +03:00
|
|
|
#endif
|
2008-09-05 15:30:35 +04:00
|
|
|
return (VALUE)open(data->fname, data->oflags, data->perm);
|
2007-11-20 13:47:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-02-25 11:36:45 +03:00
|
|
|
rb_sysopen_internal(VALUE fname, int oflags, mode_t perm)
|
2007-11-20 13:47:53 +03:00
|
|
|
{
|
2009-02-25 11:36:45 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
static rb_encoding *utf16 = (rb_encoding *)-1;
|
|
|
|
#endif
|
2007-11-26 04:44:23 +03:00
|
|
|
struct sysopen_struct data;
|
2009-02-25 11:36:45 +03:00
|
|
|
data.fname = RSTRING_PTR(fname);
|
2008-09-05 15:30:35 +04:00
|
|
|
data.oflags = oflags;
|
2008-09-04 15:20:53 +04:00
|
|
|
data.perm = perm;
|
2009-02-25 11:36:45 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (utf16 == (rb_encoding *)-1) {
|
|
|
|
utf16 = rb_enc_find("UTF-16LE");
|
|
|
|
if (utf16 == rb_ascii8bit_encoding())
|
|
|
|
utf16 = NULL;
|
|
|
|
}
|
|
|
|
if (utf16) {
|
2009-02-26 04:58:20 +03:00
|
|
|
VALUE wfname = rb_str_encode(fname, rb_enc_from_encoding(utf16), 0,
|
|
|
|
Qnil);
|
2009-02-25 11:36:45 +03:00
|
|
|
rb_enc_str_buf_cat(wfname, "", 1, utf16); /* workaround */
|
|
|
|
data.fname = RSTRING_PTR(wfname);
|
|
|
|
data.wchar = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.wchar = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2008-08-31 11:44:24 +04:00
|
|
|
return (int)rb_thread_blocking_region(sysopen_func, &data, RUBY_UBF_IO, 0);
|
2007-11-20 13:47:53 +03:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static int
|
2009-02-25 11:36:45 +03:00
|
|
|
rb_sysopen(VALUE fname, int oflags, mode_t perm)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2008-08-22 20:44:00 +04:00
|
|
|
#ifdef O_BINARY
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags |= O_BINARY;
|
2008-08-22 20:44:00 +04:00
|
|
|
#endif
|
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
fd = rb_sysopen_internal(fname, oflags, perm);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (fd < 0) {
|
|
|
|
if (errno == EMFILE || errno == ENFILE) {
|
|
|
|
rb_gc();
|
2008-09-05 15:30:35 +04:00
|
|
|
fd = rb_sysopen_internal(fname, oflags, perm);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
if (fd < 0) {
|
2009-02-25 11:36:45 +03:00
|
|
|
rb_sys_fail(RSTRING_PTR(fname));
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
}
|
2008-04-24 18:46:39 +04:00
|
|
|
UPDATE_MAXFD(fd);
|
1999-08-13 09:45:20 +04:00
|
|
|
return fd;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FILE *
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_fdopen(int fd, const char *modestr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
FILE *file;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-05-07 12:44:24 +04:00
|
|
|
#if defined(sun)
|
|
|
|
errno = 0;
|
|
|
|
#endif
|
2008-09-05 15:30:35 +04:00
|
|
|
file = fdopen(fd, modestr);
|
2000-07-06 11:21:26 +04:00
|
|
|
if (!file) {
|
2005-06-03 18:23:17 +04:00
|
|
|
if (
|
2004-05-07 12:44:24 +04:00
|
|
|
#if defined(sun)
|
2005-06-03 18:23:17 +04:00
|
|
|
errno == 0 ||
|
2004-05-07 12:44:24 +04:00
|
|
|
#endif
|
2005-06-03 18:23:17 +04:00
|
|
|
errno == EMFILE || errno == ENFILE) {
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_gc();
|
2004-05-07 12:44:24 +04:00
|
|
|
#if defined(sun)
|
|
|
|
errno = 0;
|
|
|
|
#endif
|
2008-09-05 15:30:35 +04:00
|
|
|
file = fdopen(fd, modestr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-07-06 11:21:26 +04:00
|
|
|
if (!file) {
|
2003-07-26 16:27:04 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (errno == 0) errno = EINVAL;
|
2004-05-07 12:44:24 +04:00
|
|
|
#elif defined(sun)
|
|
|
|
if (errno == 0) errno = EMFILE;
|
2003-07-26 16:27:04 +04:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
/* xxx: should be _IONBF? A buffer in FILE may have trouble. */
|
2001-05-02 08:22:21 +04:00
|
|
|
#ifdef USE_SETVBUF
|
2004-06-25 19:13:16 +04:00
|
|
|
if (setvbuf(file, NULL, _IOFBF, 0) != 0)
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-19 03:19:47 +04:00
|
|
|
rb_warn("setvbuf() can't be honoured (fd=%d)", fd);
|
2001-05-02 08:22:21 +04:00
|
|
|
#endif
|
1999-08-13 09:45:20 +04:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2004-12-23 13:12:35 +03:00
|
|
|
static 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 13:30:50 +03:00
|
|
|
io_check_tty(rb_io_t *fptr)
|
2004-12-23 13:12:35 +03:00
|
|
|
{
|
2005-02-07 17:18:41 +03:00
|
|
|
if (isatty(fptr->fd))
|
|
|
|
fptr->mode |= FMODE_TTY|FMODE_DUPLEX;
|
2004-12-23 13:12:35 +03:00
|
|
|
}
|
|
|
|
|
2009-07-09 18:47:48 +04:00
|
|
|
static VALUE rb_io_internal_encoding(VALUE);
|
|
|
|
static void io_encoding_set(rb_io_t *, VALUE, VALUE, VALUE);
|
|
|
|
|
|
|
|
static int
|
2009-07-10 17:17:43 +04:00
|
|
|
io_strip_bom(VALUE io)
|
|
|
|
{
|
2009-07-09 18:47:48 +04:00
|
|
|
int b1, b2, b3, b4;
|
|
|
|
switch (b1 = FIX2INT(rb_io_getbyte(io))) {
|
|
|
|
case 0xEF:
|
|
|
|
b2 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b2 == 0xBB) {
|
|
|
|
b3 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b3 == 0xBF) {
|
|
|
|
return rb_utf8_encindex();
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b3));
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b2));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFE:
|
|
|
|
b2 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b2 == 0xFF) {
|
|
|
|
return rb_enc_find_index("UTF-16BE");
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b2));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xFF:
|
|
|
|
b2 = FIX2INT(rb_io_getbyte(io));
|
2009-07-10 18:21:04 +04:00
|
|
|
if (b2 == 0xFE) {
|
2009-07-09 18:47:48 +04:00
|
|
|
b3 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b3 == 0) {
|
|
|
|
b4 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b4 == 0) {
|
|
|
|
return rb_enc_find_index("UTF-32LE");
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b4));
|
|
|
|
}
|
|
|
|
else {
|
2009-07-10 18:21:13 +04:00
|
|
|
rb_io_ungetbyte(io, INT2FIX(b3));
|
2009-07-09 18:47:48 +04:00
|
|
|
return rb_enc_find_index("UTF-16LE");
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b3));
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b2));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
b2 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b2 == 0) {
|
|
|
|
b3 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b3 == 0xFE) {
|
|
|
|
b4 = FIX2INT(rb_io_getbyte(io));
|
|
|
|
if (b4 == 0xFF) {
|
|
|
|
return rb_enc_find_index("UTF-32BE");
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b4));
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b3));
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b2));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rb_io_ungetbyte(io, INT2FIX(b1));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-07-10 17:17:43 +04:00
|
|
|
io_set_encoding_by_bom(VALUE io)
|
|
|
|
{
|
2009-07-09 18:47:48 +04:00
|
|
|
int idx = io_strip_bom(io);
|
|
|
|
|
|
|
|
if (idx) {
|
|
|
|
rb_io_t *fptr;
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
io_encoding_set(fptr, rb_enc_from_encoding(rb_enc_from_index(idx)),
|
|
|
|
rb_io_internal_encoding(io), Qnil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_file_open_generic(VALUE io, VALUE filename, int oflags, int fmode, convconfig_t *convconfig, mode_t perm)
|
1999-08-13 09:45:20 +04: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2008-09-12 22:32:19 +04:00
|
|
|
convconfig_t cc;
|
|
|
|
if (!convconfig) {
|
2008-10-07 21:39:44 +04:00
|
|
|
/* Set to default encodings */
|
|
|
|
rb_io_ext_int_to_encs(NULL, NULL, &cc.enc, &cc.enc2);
|
2008-09-12 22:32:19 +04:00
|
|
|
cc.ecflags = 0;
|
|
|
|
cc.ecopts = Qnil;
|
|
|
|
convconfig = &cc;
|
|
|
|
}
|
|
|
|
validate_enc_binmode(fmode, convconfig->enc, convconfig->enc2);
|
2000-03-23 11:37:35 +03:00
|
|
|
|
|
|
|
MakeOpenFile(io, fptr);
|
2008-09-05 15:30:35 +04:00
|
|
|
fptr->mode = fmode;
|
2008-09-12 22:32:19 +04:00
|
|
|
fptr->encs = *convconfig;
|
2008-08-23 04:47:54 +04:00
|
|
|
fptr->pathv = rb_str_new_frozen(filename);
|
2009-02-25 11:36:45 +03:00
|
|
|
fptr->fd = rb_sysopen(fptr->pathv, oflags, perm);
|
2004-12-23 13:12:35 +03:00
|
|
|
io_check_tty(fptr);
|
2009-07-09 18:47:48 +04:00
|
|
|
if (fmode & FMODE_STRIP_BOM) io_set_encoding_by_bom(io);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2000-03-23 11:37:35 +03:00
|
|
|
return io;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2008-08-20 14:24:37 +04:00
|
|
|
static VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_file_open_internal(VALUE io, VALUE filename, const char *modestr)
|
2008-08-20 14:24:37 +04:00
|
|
|
{
|
2008-10-21 05:40:41 +04:00
|
|
|
int fmode = rb_io_modestr_fmode(modestr);
|
2008-09-05 15:30:35 +04:00
|
|
|
const char *p = strchr(modestr, ':');
|
2008-08-20 14:24:37 +04:00
|
|
|
convconfig_t convconfig;
|
2008-10-21 05:40:41 +04:00
|
|
|
|
2008-08-20 14:24:37 +04:00
|
|
|
if (p) {
|
|
|
|
parse_mode_enc(p+1, &convconfig.enc, &convconfig.enc2);
|
|
|
|
}
|
|
|
|
else {
|
2008-10-20 20:57:19 +04:00
|
|
|
rb_encoding *e;
|
2008-10-07 21:39:44 +04:00
|
|
|
/* Set to default encodings */
|
2008-10-20 20:57:19 +04:00
|
|
|
|
|
|
|
e = (fmode & FMODE_BINMODE) ? rb_ascii8bit_encoding() : NULL;
|
|
|
|
rb_io_ext_int_to_encs(e, NULL, &convconfig.enc, &convconfig.enc2);
|
2008-09-04 14:22:11 +04:00
|
|
|
convconfig.ecflags = 0;
|
2008-09-03 22:18:10 +04:00
|
|
|
convconfig.ecopts = Qnil;
|
2008-08-20 14:24:37 +04:00
|
|
|
}
|
|
|
|
|
2008-08-22 00:12:29 +04:00
|
|
|
return rb_file_open_generic(io, filename,
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_fmode_oflags(fmode),
|
|
|
|
fmode,
|
2008-08-20 14:24:37 +04:00
|
|
|
&convconfig,
|
|
|
|
0666);
|
|
|
|
}
|
|
|
|
|
2008-09-04 18:43:45 +04:00
|
|
|
VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_file_open_str(VALUE fname, const char *modestr)
|
2008-09-04 18:43:45 +04:00
|
|
|
{
|
2008-09-12 22:32:19 +04:00
|
|
|
FilePathValue(fname);
|
2008-09-05 15:30:35 +04:00
|
|
|
return rb_file_open_internal(io_alloc(rb_cFile), fname, modestr);
|
2008-09-04 18:43:45 +04:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_file_open(const char *fname, const char *modestr)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
return rb_file_open_internal(io_alloc(rb_cFile), rb_str_new_cstr(fname), modestr);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
#if defined(__CYGWIN__) || !defined(HAVE_FORK)
|
1998-01-16 15:13:05 +03:00
|
|
|
static struct pipe_list {
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct pipe_list *next;
|
|
|
|
} *pipe_list;
|
|
|
|
|
|
|
|
static 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 13:30:50 +03:00
|
|
|
pipe_add_fptr(rb_io_t *fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct pipe_list *list;
|
|
|
|
|
|
|
|
list = ALLOC(struct pipe_list);
|
|
|
|
list->fptr = fptr;
|
|
|
|
list->next = pipe_list;
|
|
|
|
pipe_list = list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static 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 13:30:50 +03:00
|
|
|
pipe_del_fptr(rb_io_t *fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct pipe_list *list = pipe_list;
|
|
|
|
struct pipe_list *tmp;
|
|
|
|
|
|
|
|
if (list->fptr == fptr) {
|
|
|
|
pipe_list = list->next;
|
1999-01-20 07:59:39 +03:00
|
|
|
free(list);
|
1998-01-16 15:13:05 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (list->next) {
|
|
|
|
if (list->next->fptr == fptr) {
|
|
|
|
tmp = list->next;
|
|
|
|
list->next = list->next->next;
|
|
|
|
free(tmp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* 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 10:32:32 +04:00
|
|
|
pipe_atexit(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct pipe_list *list = pipe_list;
|
1999-01-20 07:59:39 +03:00
|
|
|
struct pipe_list *tmp;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
while (list) {
|
1999-01-20 07:59:39 +03:00
|
|
|
tmp = list->next;
|
|
|
|
rb_io_fptr_finalize(list->fptr);
|
|
|
|
list = tmp;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static 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 13:30:50 +03:00
|
|
|
pipe_finalize(rb_io_t *fptr, int noraise)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2004-02-16 09:45:32 +03:00
|
|
|
#if !defined(HAVE_FORK) && !defined(_WIN32)
|
2000-07-10 10:30:11 +04:00
|
|
|
int status;
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->stdio_file) {
|
|
|
|
status = pclose(fptr->stdio_file);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fptr->fd = -1;
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->stdio_file = 0;
|
2007-02-05 19:22:38 +03:00
|
|
|
rb_last_status_set(status, fptr->pid);
|
1999-01-20 07:59:39 +03:00
|
|
|
#else
|
2003-04-14 13:04:43 +04:00
|
|
|
fptr_finalize(fptr, noraise);
|
1999-01-20 07:59:39 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
pipe_del_fptr(fptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_synchronized(rb_io_t *fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-12-13 20:06:41 +03:00
|
|
|
rb_io_check_initialized(fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->mode |= FMODE_SYNC;
|
|
|
|
}
|
|
|
|
|
1999-09-20 11:14:18 +04:00
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_unbuffered(rb_io_t *fptr)
|
1999-09-20 11:14:18 +04:00
|
|
|
{
|
|
|
|
rb_io_synchronized(fptr);
|
|
|
|
}
|
|
|
|
|
2008-07-05 18:12:53 +04:00
|
|
|
int
|
|
|
|
rb_pipe(int *pipes)
|
2008-07-05 17:38:46 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ret = pipe(pipes);
|
|
|
|
if (ret == -1) {
|
|
|
|
if (errno == EMFILE || errno == ENFILE) {
|
|
|
|
rb_gc();
|
|
|
|
ret = pipe(pipes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret == 0) {
|
|
|
|
UPDATE_MAXFD(pipes[0]);
|
|
|
|
UPDATE_MAXFD(pipes[1]);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-11-20 07:04:51 +03:00
|
|
|
#ifdef HAVE_FORK
|
2004-02-16 09:45:32 +03:00
|
|
|
struct popen_arg {
|
2008-04-28 04:11:46 +04:00
|
|
|
struct rb_exec_arg *execp;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
int modef;
|
|
|
|
int pair[2];
|
2007-11-20 06:16:53 +03:00
|
|
|
int write_pair[2];
|
2004-02-16 09:45:32 +03:00
|
|
|
};
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
popen_redirect(struct popen_arg *p)
|
2004-02-16 09:45:32 +03:00
|
|
|
{
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if ((p->modef & FMODE_READABLE) && (p->modef & FMODE_WRITABLE)) {
|
2007-11-20 06:16:53 +03:00
|
|
|
close(p->write_pair[1]);
|
|
|
|
if (p->write_pair[0] != 0) {
|
|
|
|
dup2(p->write_pair[0], 0);
|
|
|
|
close(p->write_pair[0]);
|
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
close(p->pair[0]);
|
2007-11-20 06:16:53 +03:00
|
|
|
if (p->pair[1] != 1) {
|
|
|
|
dup2(p->pair[1], 1);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
close(p->pair[1]);
|
2007-11-20 06:16:53 +03:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
|
|
|
else if (p->modef & FMODE_READABLE) {
|
|
|
|
close(p->pair[0]);
|
|
|
|
if (p->pair[1] != 1) {
|
|
|
|
dup2(p->pair[1], 1);
|
|
|
|
close(p->pair[1]);
|
|
|
|
}
|
2002-06-28 22:26:01 +04:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
else {
|
|
|
|
close(p->pair[1]);
|
|
|
|
if (p->pair[0] != 0) {
|
|
|
|
dup2(p->pair[0], 0);
|
|
|
|
close(p->pair[0]);
|
|
|
|
}
|
2002-06-28 22:26:01 +04:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
2002-06-28 22:26:01 +04:00
|
|
|
|
2008-04-24 18:46:39 +04:00
|
|
|
void
|
|
|
|
rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
int max = max_file_descriptor;
|
|
|
|
if (max < maxhint)
|
|
|
|
max = maxhint;
|
|
|
|
for (fd = lowfd; fd <= max; fd++) {
|
|
|
|
if (!NIL_P(noclose_fds) &&
|
|
|
|
RTEST(rb_hash_lookup(noclose_fds, INT2FIX(fd))))
|
|
|
|
continue;
|
|
|
|
#ifdef FD_CLOEXEC
|
|
|
|
ret = fcntl(fd, F_GETFD);
|
|
|
|
if (ret != -1 && !(ret & FD_CLOEXEC)) {
|
|
|
|
fcntl(fd, F_SETFD, ret|FD_CLOEXEC);
|
|
|
|
}
|
|
|
|
#else
|
2009-01-05 18:35:21 +03:00
|
|
|
ret = close(fd);
|
2008-04-24 18:46:39 +04:00
|
|
|
#endif
|
2009-01-05 18:35:21 +03:00
|
|
|
#define CONTIGUOUS_CLOSED_FDS 20
|
|
|
|
if (ret != -1) {
|
|
|
|
if (max < fd + CONTIGUOUS_CLOSED_FDS)
|
|
|
|
max = fd + CONTIGUOUS_CLOSED_FDS;
|
|
|
|
}
|
2008-04-24 18:46:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
static int
|
2008-12-23 16:15:54 +03:00
|
|
|
popen_exec(void *pp, char *errmsg, size_t errmsg_len)
|
2004-02-16 09:45:32 +03:00
|
|
|
{
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
struct popen_arg *p = (struct popen_arg*)pp;
|
2002-06-28 22:26:01 +04:00
|
|
|
|
2008-05-11 08:15:29 +04:00
|
|
|
rb_thread_atfork_before_exec();
|
2009-02-05 14:33:19 +03:00
|
|
|
return rb_exec_err(p->execp, errmsg, errmsg_len);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
pipe_open(struct rb_exec_arg *eargp, VALUE prog, const char *modestr, int fmode, convconfig_t *convconfig)
|
2004-02-16 09:45:32 +03:00
|
|
|
{
|
2009-05-07 08:10:27 +04:00
|
|
|
rb_pid_t pid = 0;
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2007-08-04 23:56:27 +04:00
|
|
|
VALUE port;
|
2007-11-20 06:16:53 +03:00
|
|
|
rb_io_t *write_fptr;
|
|
|
|
VALUE write_port;
|
2007-04-04 12:08:46 +04:00
|
|
|
#if defined(HAVE_FORK)
|
2004-02-16 09:45:32 +03:00
|
|
|
int status;
|
|
|
|
struct popen_arg arg;
|
2008-12-23 16:15:54 +03:00
|
|
|
char errmsg[80] = { '\0' };
|
2009-01-15 05:41:38 +03:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
volatile VALUE argbuf;
|
|
|
|
char **args = NULL;
|
2008-12-04 19:39:03 +03:00
|
|
|
int pair[2], write_pair[2];
|
2009-02-18 09:33:53 +03:00
|
|
|
#endif
|
|
|
|
#if !defined(HAVE_FORK)
|
2009-02-06 16:31:20 +03:00
|
|
|
struct rb_exec_arg sarg;
|
2004-02-16 09:45:32 +03:00
|
|
|
#endif
|
2004-12-08 16:26:27 +03:00
|
|
|
FILE *fp = 0;
|
|
|
|
int fd = -1;
|
2007-11-20 06:16:53 +03:00
|
|
|
int write_fd = -1;
|
2008-04-24 18:46:39 +04:00
|
|
|
const char *cmd = 0;
|
2008-04-28 04:11:46 +04:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
2008-04-24 18:46:39 +04:00
|
|
|
|
|
|
|
if (prog)
|
|
|
|
cmd = StringValueCStr(prog);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-04-28 04:11:46 +04:00
|
|
|
if (!eargp) {
|
|
|
|
/* fork : IO.popen("-") */
|
|
|
|
argc = 0;
|
|
|
|
argv = 0;
|
|
|
|
}
|
|
|
|
else if (eargp->argc) {
|
|
|
|
/* no shell : IO.popen([prog, arg0], arg1, ...) */
|
|
|
|
argc = eargp->argc;
|
|
|
|
argv = eargp->argv;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* with shell : IO.popen(prog) */
|
|
|
|
argc = 0;
|
|
|
|
argv = 0;
|
2008-04-24 18:46:39 +04:00
|
|
|
}
|
2008-04-28 04:11:46 +04:00
|
|
|
|
|
|
|
#if defined(HAVE_FORK)
|
|
|
|
arg.execp = eargp;
|
2008-09-05 15:30:35 +04:00
|
|
|
arg.modef = fmode;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
arg.pair[0] = arg.pair[1] = -1;
|
2007-11-20 06:16:53 +03:00
|
|
|
arg.write_pair[0] = arg.write_pair[1] = -1;
|
2008-09-05 15:30:35 +04:00
|
|
|
switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
|
2007-04-04 12:08:46 +04:00
|
|
|
case FMODE_READABLE|FMODE_WRITABLE:
|
2008-07-05 18:12:53 +04:00
|
|
|
if (rb_pipe(arg.write_pair) < 0)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_sys_fail(cmd);
|
2008-07-05 18:12:53 +04:00
|
|
|
if (rb_pipe(arg.pair) < 0) {
|
2007-11-20 06:16:53 +03:00
|
|
|
int e = errno;
|
|
|
|
close(arg.write_pair[0]);
|
|
|
|
close(arg.write_pair[1]);
|
|
|
|
errno = e;
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
}
|
2008-04-28 04:11:46 +04:00
|
|
|
if (eargp) {
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.write_pair[0]));
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(arg.pair[1]));
|
2008-04-24 18:46:39 +04:00
|
|
|
}
|
2007-04-04 12:08:46 +04:00
|
|
|
break;
|
|
|
|
case FMODE_READABLE:
|
2008-07-05 18:12:53 +04:00
|
|
|
if (rb_pipe(arg.pair) < 0)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_sys_fail(cmd);
|
2008-04-28 04:11:46 +04:00
|
|
|
if (eargp)
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(arg.pair[1]));
|
2007-04-04 12:08:46 +04:00
|
|
|
break;
|
|
|
|
case FMODE_WRITABLE:
|
2008-07-05 18:12:53 +04:00
|
|
|
if (rb_pipe(arg.pair) < 0)
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_sys_fail(cmd);
|
2008-04-28 04:11:46 +04:00
|
|
|
if (eargp)
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(arg.pair[0]));
|
2007-04-04 12:08:46 +04:00
|
|
|
break;
|
|
|
|
default:
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_sys_fail(cmd);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
2008-04-28 04:11:46 +04:00
|
|
|
if (eargp) {
|
2008-04-30 09:40:19 +04:00
|
|
|
rb_exec_arg_fixup(arg.execp);
|
2009-02-05 14:33:19 +03:00
|
|
|
pid = rb_fork_err(&status, popen_exec, &arg, arg.execp->redirect_fds, errmsg, sizeof(errmsg));
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-08-04 23:56:27 +04:00
|
|
|
fflush(stdin); /* is it really needed? */
|
2009-02-05 14:33:19 +03:00
|
|
|
pid = rb_fork(&status, 0, 0, Qnil);
|
2004-02-16 09:45:32 +03:00
|
|
|
if (pid == 0) { /* child */
|
|
|
|
popen_redirect(&arg);
|
|
|
|
rb_io_synchronized(RFILE(orig_stdout)->fptr);
|
|
|
|
rb_io_synchronized(RFILE(orig_stderr)->fptr);
|
|
|
|
return Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
/* parent */
|
|
|
|
if (pid == -1) {
|
2004-11-30 17:49:18 +03:00
|
|
|
int e = errno;
|
2006-06-27 18:14:25 +04:00
|
|
|
close(arg.pair[0]);
|
|
|
|
close(arg.pair[1]);
|
2008-09-05 15:30:35 +04:00
|
|
|
if ((fmode & (FMODE_READABLE|FMODE_WRITABLE)) == (FMODE_READABLE|FMODE_WRITABLE)) {
|
2007-11-20 06:16:53 +03:00
|
|
|
close(arg.write_pair[0]);
|
|
|
|
close(arg.write_pair[1]);
|
|
|
|
}
|
2004-11-30 17:49:18 +03:00
|
|
|
errno = e;
|
2008-12-23 16:15:54 +03:00
|
|
|
if (errmsg[0])
|
|
|
|
rb_sys_fail(errmsg);
|
2004-11-02 08:33:11 +03:00
|
|
|
rb_sys_fail(cmd);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
if ((fmode & FMODE_READABLE) && (fmode & FMODE_WRITABLE)) {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
close(arg.pair[1]);
|
2004-12-08 16:26:27 +03:00
|
|
|
fd = arg.pair[0];
|
2007-11-20 06:16:53 +03:00
|
|
|
close(arg.write_pair[0]);
|
|
|
|
write_fd = arg.write_pair[1];
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
else if (fmode & FMODE_READABLE) {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
close(arg.pair[1]);
|
2004-12-08 16:26:27 +03:00
|
|
|
fd = arg.pair[0];
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
close(arg.pair[0]);
|
2004-12-08 16:26:27 +03:00
|
|
|
fd = arg.pair[1];
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
if (argc) {
|
|
|
|
int i;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-01-16 08:55:22 +03:00
|
|
|
if (argc >= FIXNUM_MAX / sizeof(char *)) {
|
|
|
|
rb_raise(rb_eArgError, "too many arguments");
|
|
|
|
}
|
|
|
|
argbuf = rb_str_tmp_new((argc+1) * sizeof(char *));
|
|
|
|
args = (void *)RSTRING_PTR(argbuf);
|
2004-02-16 09:45:32 +03:00
|
|
|
for (i = 0; i < argc; ++i) {
|
2008-01-28 06:32:27 +03:00
|
|
|
args[i] = StringValueCStr(argv[i]);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
args[i] = NULL;
|
|
|
|
}
|
2008-12-04 19:39:03 +03:00
|
|
|
switch (fmode & (FMODE_READABLE|FMODE_WRITABLE)) {
|
|
|
|
case FMODE_READABLE|FMODE_WRITABLE:
|
|
|
|
if (rb_pipe(write_pair) < 0)
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
if (rb_pipe(pair) < 0) {
|
|
|
|
int e = errno;
|
|
|
|
close(write_pair[0]);
|
|
|
|
close(write_pair[1]);
|
|
|
|
errno = e;
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
}
|
|
|
|
if (eargp) {
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(write_pair[0]));
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(pair[1]));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FMODE_READABLE:
|
|
|
|
if (rb_pipe(pair) < 0)
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
if (eargp)
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(1), INT2FIX(pair[1]));
|
|
|
|
break;
|
|
|
|
case FMODE_WRITABLE:
|
|
|
|
if (rb_pipe(pair) < 0)
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
if (eargp)
|
|
|
|
rb_exec_arg_addopt(eargp, INT2FIX(0), INT2FIX(pair[0]));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
}
|
2008-05-12 18:15:32 +04:00
|
|
|
if (eargp) {
|
|
|
|
rb_exec_arg_fixup(eargp);
|
2009-02-05 14:33:19 +03:00
|
|
|
rb_run_exec_options(eargp, &sarg);
|
2008-05-12 18:15:32 +04:00
|
|
|
}
|
2008-12-20 12:28:29 +03:00
|
|
|
while ((pid = (args ?
|
2009-03-21 01:25:57 +03:00
|
|
|
rb_w32_aspawn(P_NOWAIT, cmd, args) :
|
2008-12-20 12:28:29 +03:00
|
|
|
rb_w32_spawn(P_NOWAIT, cmd, 0))) == -1) {
|
2004-02-16 09:45:32 +03:00
|
|
|
/* exec failed */
|
|
|
|
switch (errno) {
|
|
|
|
case EAGAIN:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_thread_sleep(1);
|
2004-02-16 09:45:32 +03:00
|
|
|
break;
|
2004-02-20 06:57:36 +03:00
|
|
|
default:
|
2008-05-12 18:15:32 +04:00
|
|
|
if (eargp)
|
2009-02-05 14:33:19 +03:00
|
|
|
rb_run_exec_options(&sarg, NULL);
|
2007-08-07 07:31:54 +04:00
|
|
|
rb_sys_fail(cmd);
|
2004-02-16 09:45:32 +03:00
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
2008-05-12 18:15:32 +04:00
|
|
|
if (eargp)
|
2009-02-05 14:33:19 +03:00
|
|
|
rb_run_exec_options(&sarg, NULL);
|
2008-12-04 19:39:03 +03:00
|
|
|
if ((fmode & FMODE_READABLE) && (fmode & FMODE_WRITABLE)) {
|
|
|
|
close(pair[1]);
|
|
|
|
fd = pair[0];
|
|
|
|
close(write_pair[0]);
|
|
|
|
write_fd = write_pair[1];
|
|
|
|
}
|
|
|
|
else if (fmode & FMODE_READABLE) {
|
|
|
|
close(pair[1]);
|
|
|
|
fd = pair[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
close(pair[0]);
|
|
|
|
fd = pair[1];
|
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
#else
|
2007-04-04 05:17:34 +04:00
|
|
|
if (argc) {
|
2004-12-09 06:34:47 +03:00
|
|
|
prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
|
2007-04-04 05:17:34 +04:00
|
|
|
cmd = StringValueCStr(prog);
|
|
|
|
}
|
2008-05-12 18:15:32 +04:00
|
|
|
if (eargp) {
|
|
|
|
rb_exec_arg_fixup(eargp);
|
2009-02-05 14:33:19 +03:00
|
|
|
rb_run_exec_options(eargp, &sarg);
|
2008-05-12 18:15:32 +04:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
fp = popen(cmd, modestr);
|
2008-05-12 18:15:32 +04:00
|
|
|
if (eargp)
|
2009-02-05 14:33:19 +03:00
|
|
|
rb_run_exec_options(&sarg, NULL);
|
2006-08-31 15:24:44 +04:00
|
|
|
if (!fp) rb_sys_fail(RSTRING_PTR(prog));
|
2004-12-08 16:26:27 +03:00
|
|
|
fd = fileno(fp);
|
2004-02-16 09:45:32 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
port = io_alloc(rb_cIO);
|
|
|
|
MakeOpenFile(port, fptr);
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->fd = fd;
|
|
|
|
fptr->stdio_file = fp;
|
2008-09-05 15:30:35 +04:00
|
|
|
fptr->mode = fmode | FMODE_SYNC|FMODE_DUPLEX;
|
2008-08-20 22:14:07 +04:00
|
|
|
if (convconfig) {
|
2008-08-24 11:49:13 +04:00
|
|
|
fptr->encs = *convconfig;
|
2008-08-20 22:14:07 +04:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
fptr->pid = pid;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
if (0 <= write_fd) {
|
|
|
|
write_port = io_alloc(rb_cIO);
|
|
|
|
MakeOpenFile(write_port, write_fptr);
|
|
|
|
write_fptr->fd = write_fd;
|
2008-09-05 15:30:35 +04:00
|
|
|
write_fptr->mode = (fmode & ~FMODE_READABLE)| FMODE_SYNC|FMODE_DUPLEX;
|
2007-11-20 06:16:53 +03:00
|
|
|
fptr->mode &= ~FMODE_WRITABLE;
|
|
|
|
fptr->tied_io_for_writing = write_port;
|
|
|
|
rb_ivar_set(port, rb_intern("@tied_io_for_writing"), write_port);
|
|
|
|
}
|
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
#if defined (__CYGWIN__) || !defined(HAVE_FORK)
|
|
|
|
fptr->finalize = pipe_finalize;
|
|
|
|
pipe_add_fptr(fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2004-02-16 09:45:32 +03:00
|
|
|
return port;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2007-08-04 23:56:27 +04:00
|
|
|
static VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
pipe_open_v(int argc, VALUE *argv, const char *modestr, int fmode, convconfig_t *convconfig)
|
2007-08-04 23:56:27 +04:00
|
|
|
{
|
2008-04-28 04:11:46 +04:00
|
|
|
VALUE prog;
|
|
|
|
struct rb_exec_arg earg;
|
|
|
|
prog = rb_exec_arg_init(argc, argv, Qfalse, &earg);
|
2008-09-05 15:30:35 +04:00
|
|
|
return pipe_open(&earg, prog, modestr, fmode, convconfig);
|
2007-08-04 23:56:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
pipe_open_s(VALUE prog, const char *modestr, int fmode, convconfig_t *convconfig)
|
2007-08-04 23:56:27 +04:00
|
|
|
{
|
2008-04-24 18:46:39 +04:00
|
|
|
const char *cmd = RSTRING_PTR(prog);
|
|
|
|
int argc = 1;
|
|
|
|
VALUE *argv = &prog;
|
2008-04-28 04:11:46 +04:00
|
|
|
struct rb_exec_arg earg;
|
2007-08-04 23:56:27 +04:00
|
|
|
|
2008-04-24 18:46:39 +04:00
|
|
|
if (RSTRING_LEN(prog) == 1 && cmd[0] == '-') {
|
2007-08-04 23:56:27 +04:00
|
|
|
#if !defined(HAVE_FORK)
|
|
|
|
rb_raise(rb_eNotImpError,
|
|
|
|
"fork() function is unimplemented on this machine");
|
|
|
|
#endif
|
2008-09-05 15:30:35 +04:00
|
|
|
return pipe_open(0, 0, modestr, fmode, convconfig);
|
2007-08-04 23:56:27 +04:00
|
|
|
}
|
2008-04-24 18:46:39 +04:00
|
|
|
|
2008-04-28 04:11:46 +04:00
|
|
|
rb_exec_arg_init(argc, argv, Qtrue, &earg);
|
2008-09-05 15:30:35 +04:00
|
|
|
return pipe_open(&earg, prog, modestr, fmode, convconfig);
|
2008-08-20 22:14:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-10-21 17:57:16 +04:00
|
|
|
pop_last_hash(int *argc_p, VALUE *argv)
|
2008-08-20 22:14:07 +04:00
|
|
|
{
|
|
|
|
VALUE last, tmp;
|
|
|
|
if (*argc_p == 0)
|
|
|
|
return Qnil;
|
2008-10-21 17:57:16 +04:00
|
|
|
last = argv[*argc_p-1];
|
2008-08-20 22:14:07 +04:00
|
|
|
tmp = rb_check_convert_type(last, T_HASH, "Hash", "to_hash");
|
|
|
|
if (NIL_P(tmp))
|
|
|
|
return Qnil;
|
|
|
|
(*argc_p)--;
|
|
|
|
return tmp;
|
2007-08-04 23:56:27 +04:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.popen(cmd, mode="r" [, opt]) => io
|
|
|
|
* IO.popen(cmd, mode="r" [, opt]) {|io| block } => obj
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
|
|
|
* Runs the specified command as a subprocess; the subprocess's
|
2003-12-27 03:44:05 +03:00
|
|
|
* standard input and output will be connected to the returned
|
2008-12-04 18:21:32 +03:00
|
|
|
* <code>IO</code> object.
|
|
|
|
*
|
2009-03-28 17:49:49 +03:00
|
|
|
* The PID of the started process can be obtained by IO#pid method.
|
|
|
|
*
|
2008-12-04 18:21:32 +03:00
|
|
|
* _cmd_ is a string or an array as follows.
|
|
|
|
*
|
|
|
|
* cmd:
|
|
|
|
* "-" : fork
|
|
|
|
* commandline : command line string which is passed to a shell
|
2009-02-22 19:22:28 +03:00
|
|
|
* [env, cmdname, arg1, ..., opts] : command name and zero or more arguments (no shell)
|
|
|
|
* [env, [cmdname, argv0], arg1, ..., opts] : command name, argv[0] and zero or more arguments (no shell)
|
2008-12-04 18:21:32 +03:00
|
|
|
* (env and opts are optional.)
|
|
|
|
*
|
|
|
|
* If _cmd_ is a +String+ ``<code>-</code>'',
|
|
|
|
* then a new instance of Ruby is started as the subprocess.
|
|
|
|
*
|
|
|
|
* If <i>cmd</i> is an +Array+ of +String+,
|
|
|
|
* then it will be used as the subprocess's +argv+ bypassing a shell.
|
2008-04-24 18:46:39 +04:00
|
|
|
* The array can contains a hash at first for environments and
|
2008-12-04 18:21:32 +03:00
|
|
|
* a hash at last for options similar to <code>spawn</code>.
|
|
|
|
*
|
|
|
|
* The default mode for the new file object is ``r'',
|
|
|
|
* but <i>mode</i> may be set to any of the modes listed in the description for class IO.
|
2008-12-03 18:02:49 +03:00
|
|
|
* The last argument <i>opt</i> qualifies <i>mode</i>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2008-12-03 18:02:49 +03:00
|
|
|
* # set IO encoding
|
2009-01-15 16:45:06 +03:00
|
|
|
* IO.popen("nkf -e filename", :external_encoding=>"EUC-JP") {|nkf_io|
|
|
|
|
* euc_jp_string = nkf_io.read
|
|
|
|
* }
|
2008-12-03 18:02:49 +03:00
|
|
|
*
|
|
|
|
* # merge standard output and standard error using
|
|
|
|
* # spawn option. See the document of Kernel.spawn.
|
2009-01-15 16:45:06 +03:00
|
|
|
* IO.popen(["ls", "/", :err=>[:child, :out]]) {|ls_io|
|
|
|
|
* ls_result_with_error = ls_io.read
|
|
|
|
* }
|
2008-12-03 18:02:49 +03:00
|
|
|
*
|
|
|
|
* Raises exceptions which <code>IO.pipe</code> and
|
|
|
|
* <code>Kernel.spawn</code> raise.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* If a block is given, Ruby will run the command as a child connected
|
|
|
|
* to Ruby with a pipe. Ruby's end of the pipe will be passed as a
|
2006-03-28 05:50:11 +04:00
|
|
|
* parameter to the block.
|
|
|
|
* At the end of block, Ruby close the pipe and sets <code>$?</code>.
|
2008-12-03 18:02:49 +03:00
|
|
|
* In this case <code>IO.popen</code> returns
|
2003-12-27 03:44:05 +03:00
|
|
|
* the value of the block.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
|
|
|
* If a block is given with a _cmd_ of ``<code>-</code>'',
|
2003-12-27 03:44:05 +03:00
|
|
|
* the block will be run in two separate processes: once in the parent,
|
|
|
|
* and once in a child. The parent process will be passed the pipe
|
|
|
|
* object as a parameter to the block, the child version of the block
|
|
|
|
* will be passed <code>nil</code>, and the child's standard in and
|
|
|
|
* standard out will be connected to the parent through the pipe. Not
|
|
|
|
* available on all platforms.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = IO.popen("uname")
|
|
|
|
* p f.readlines
|
2009-01-15 16:45:06 +03:00
|
|
|
* f.close
|
2003-12-27 03:44:05 +03:00
|
|
|
* puts "Parent is #{Process.pid}"
|
2004-06-29 05:17:39 +04:00
|
|
|
* IO.popen("date") { |f| puts f.gets }
|
2009-01-15 16:45:06 +03:00
|
|
|
* IO.popen("-") {|f| $stderr.puts "#{Process.pid} is here, f is #{f.inspect}"}
|
2006-03-28 05:50:11 +04:00
|
|
|
* p $?
|
2004-06-29 05:17:39 +04:00
|
|
|
* IO.popen(%w"sed -e s|^|<foo>| -e s&$&;zot;&", "r+") {|f|
|
|
|
|
* f.puts "bar"; f.close_write; puts f.gets
|
|
|
|
* }
|
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* ["Linux\n"]
|
2009-01-15 16:45:06 +03:00
|
|
|
* Parent is 21346
|
|
|
|
* Thu Jan 15 22:41:19 JST 2009
|
|
|
|
* 21346 is here, f is #<IO:fd 3>
|
|
|
|
* 21352 is here, f is nil
|
|
|
|
* #<Process::Status: pid 21352 exit 0>
|
2004-06-29 05:17:39 +04:00
|
|
|
* <foo>bar;zot;
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
2000-03-23 11:37:35 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
|
2000-03-23 11:37:35 +03:00
|
|
|
{
|
2008-09-05 15:30:35 +04:00
|
|
|
const char *modestr;
|
2008-08-20 22:14:07 +04:00
|
|
|
VALUE pname, pmode, port, tmp, opt;
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags, fmode;
|
2008-08-20 22:14:07 +04:00
|
|
|
convconfig_t convconfig;
|
|
|
|
|
2008-10-21 17:57:16 +04:00
|
|
|
opt = pop_last_hash(&argc, argv);
|
2008-08-20 22:14:07 +04:00
|
|
|
rb_scan_args(argc, argv, "11", &pname, &pmode);
|
|
|
|
|
2008-09-17 20:39:47 +04:00
|
|
|
rb_io_extract_modeenc(&pmode, 0, opt, &oflags, &fmode, &convconfig);
|
2008-09-05 15:30:35 +04:00
|
|
|
modestr = rb_io_oflags_modestr(oflags);
|
2000-03-23 11:37:35 +03:00
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
tmp = rb_check_array_type(pname);
|
|
|
|
if (!NIL_P(tmp)) {
|
2009-04-26 13:46:41 +04:00
|
|
|
long len = RARRAY_LEN(tmp);
|
|
|
|
#if SIZEOF_LONG > SIZEOF_INT
|
|
|
|
if (len > INT_MAX) {
|
|
|
|
rb_raise(rb_eArgError, "too many arguments");
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-16 08:55:22 +03:00
|
|
|
tmp = rb_ary_dup(tmp);
|
|
|
|
RBASIC(tmp)->klass = 0;
|
2009-04-26 13:46:41 +04:00
|
|
|
port = pipe_open_v((int)len, RARRAY_PTR(tmp), modestr, fmode, &convconfig);
|
2008-01-16 12:03:12 +03:00
|
|
|
rb_ary_clear(tmp);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(pname);
|
2008-09-05 15:30:35 +04:00
|
|
|
port = pipe_open_s(pname, modestr, fmode, &convconfig);
|
2004-11-02 02:49:16 +03:00
|
|
|
}
|
|
|
|
if (NIL_P(port)) {
|
|
|
|
/* child */
|
|
|
|
if (rb_block_given_p()) {
|
|
|
|
rb_yield(Qnil);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_io_flush(rb_stdout);
|
|
|
|
rb_io_flush(rb_stderr);
|
2004-11-02 02:49:16 +03:00
|
|
|
_exit(0);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
2004-11-02 02:49:16 +03:00
|
|
|
return Qnil;
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
RBASIC(port)->klass = klass;
|
|
|
|
if (rb_block_given_p()) {
|
|
|
|
return rb_ensure(rb_yield, port, io_close, port);
|
|
|
|
}
|
|
|
|
return port;
|
2000-03-23 11:37:35 +03:00
|
|
|
}
|
|
|
|
|
2008-08-20 15:16:59 +04:00
|
|
|
static void
|
|
|
|
rb_scan_open_args(int argc, VALUE *argv,
|
2008-09-05 15:30:35 +04:00
|
|
|
VALUE *fname_p, int *oflags_p, int *fmode_p,
|
2008-08-20 20:10:36 +04:00
|
|
|
convconfig_t *convconfig_p, mode_t *perm_p)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-08-20 20:10:36 +04:00
|
|
|
VALUE opt=Qnil, fname, vmode, vperm;
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags, fmode;
|
2008-08-20 20:10:36 +04:00
|
|
|
mode_t perm;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2008-10-21 17:57:16 +04:00
|
|
|
opt = pop_last_hash(&argc, argv);
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_scan_args(argc, argv, "12", &fname, &vmode, &vperm);
|
2008-09-15 18:29:09 +04:00
|
|
|
FilePathValue(fname);
|
2009-02-25 11:36:45 +03:00
|
|
|
#if defined __APPLE__
|
2008-12-29 05:56:23 +03:00
|
|
|
{
|
|
|
|
static rb_encoding *fs_encoding;
|
|
|
|
rb_encoding *fname_encoding = rb_enc_get(fname);
|
|
|
|
if (!fs_encoding)
|
|
|
|
fs_encoding = rb_filesystem_encoding();
|
|
|
|
if (rb_usascii_encoding() != fname_encoding
|
|
|
|
&& rb_ascii8bit_encoding() != fname_encoding
|
|
|
|
#if defined __APPLE__
|
|
|
|
&& rb_utf8_encoding() != fname_encoding
|
|
|
|
#endif
|
|
|
|
&& fs_encoding != fname_encoding) {
|
|
|
|
static VALUE fs_enc;
|
|
|
|
if (!fs_enc)
|
|
|
|
fs_enc = rb_enc_from_encoding(fs_encoding);
|
|
|
|
fname = rb_str_encode(fname, fs_enc, 0, Qnil);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2008-09-17 20:39:47 +04:00
|
|
|
rb_io_extract_modeenc(&vmode, &vperm, opt, &oflags, &fmode, convconfig_p);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2008-08-20 20:10:36 +04:00
|
|
|
perm = NIL_P(vperm) ? 0666 : NUM2UINT(vperm);
|
2008-08-18 20:33:46 +04:00
|
|
|
|
2008-08-20 15:16:59 +04:00
|
|
|
*fname_p = fname;
|
2008-09-05 15:30:35 +04:00
|
|
|
*oflags_p = oflags;
|
|
|
|
*fmode_p = fmode;
|
2008-08-20 20:10:36 +04:00
|
|
|
*perm_p = perm;
|
2008-08-20 15:16:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_open_file(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
VALUE fname;
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags, fmode;
|
2008-08-20 15:16:59 +04:00
|
|
|
convconfig_t convconfig;
|
2008-08-20 20:10:36 +04:00
|
|
|
mode_t perm;
|
2008-08-20 15:16:59 +04:00
|
|
|
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_scan_open_args(argc, argv, &fname, &oflags, &fmode, &convconfig, &perm);
|
|
|
|
rb_file_open_generic(io, fname, oflags, fmode, &convconfig, perm);
|
2008-06-17 01:31:56 +04:00
|
|
|
|
2001-06-05 11:19:39 +04:00
|
|
|
return io;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2008-12-23 14:30:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-method: File::open
|
|
|
|
*
|
|
|
|
* call-seq:
|
|
|
|
* File.open(filename, mode="r" [, opt]) => file
|
|
|
|
* File.open(filename [, mode [, perm]] [, opt]) => file
|
|
|
|
* File.open(filename, mode="r" [, opt]) {|file| block } => obj
|
|
|
|
* File.open(filename [, mode [, perm]] [, opt]) {|file| block } => obj
|
|
|
|
*
|
|
|
|
* With no associated block, <code>open</code> is a synonym for
|
|
|
|
* <code>File.new</code>. If the optional code block is given, it will
|
|
|
|
* be passed <i>file</i> as an argument, and the File object will
|
|
|
|
* automatically be closed when the block terminates. In this instance,
|
|
|
|
* <code>File.open</code> returns the value of the block.
|
|
|
|
*/
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
2008-12-23 14:30:44 +03:00
|
|
|
* Document-method: IO::open
|
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.open(fd, mode_string="r" [, opt] ) => io
|
|
|
|
* IO.open(fd, mode_string="r" [, opt] ) {|io| block } => obj
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* With no associated block, <code>open</code> is a synonym for
|
2008-12-03 18:02:49 +03:00
|
|
|
* <code>IO.new</code>. If the optional code block is given, it will
|
2003-12-27 03:44:05 +03:00
|
|
|
* be passed <i>io</i> as an argument, and the IO object will
|
|
|
|
* automatically be closed when the block terminates. In this instance,
|
2008-12-03 18:02:49 +03:00
|
|
|
* <code>IO.open</code> returns the value of the block.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
2001-06-05 11:19:39 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_open(int argc, VALUE *argv, VALUE klass)
|
2001-06-05 11:19:39 +04:00
|
|
|
{
|
2002-01-18 17:24:01 +03:00
|
|
|
VALUE io = rb_class_new_instance(argc, argv, klass);
|
2001-06-05 11:19:39 +04:00
|
|
|
|
2000-05-24 08:34:26 +04:00
|
|
|
if (rb_block_given_p()) {
|
2003-03-04 10:04:11 +03:00
|
|
|
return rb_ensure(rb_yield, io, io_close, io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2002-01-18 17:24:01 +03:00
|
|
|
return io;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.sysopen(path, [mode, [perm]]) => fixnum
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Opens the given path, returning the underlying file descriptor as a
|
|
|
|
* <code>Fixnum</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* IO.sysopen("testfile") #=> 3
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
2002-05-23 09:35:32 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_sysopen(int argc, VALUE *argv)
|
2002-05-23 09:35:32 +04:00
|
|
|
{
|
2008-08-20 20:10:36 +04:00
|
|
|
VALUE fname, vmode, vperm;
|
2008-08-21 22:03:52 +04:00
|
|
|
VALUE intmode;
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags, fd;
|
2008-08-20 20:10:36 +04:00
|
|
|
mode_t perm;
|
2002-05-23 09:35:32 +04:00
|
|
|
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_scan_args(argc, argv, "12", &fname, &vmode, &vperm);
|
2004-04-07 10:30:15 +04:00
|
|
|
FilePathValue(fname);
|
2002-05-23 09:35:32 +04:00
|
|
|
|
2008-08-21 22:03:52 +04:00
|
|
|
if (NIL_P(vmode))
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = O_RDONLY;
|
2008-08-21 22:03:52 +04:00
|
|
|
else if (!NIL_P(intmode = rb_check_to_integer(vmode, "to_int")))
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = NUM2INT(intmode);
|
2002-05-23 09:35:32 +04:00
|
|
|
else {
|
2003-06-23 10:52:39 +04:00
|
|
|
SafeStringValue(vmode);
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = rb_io_modestr_oflags(StringValueCStr(vmode));
|
2002-05-23 09:35:32 +04:00
|
|
|
}
|
2008-08-20 20:10:36 +04:00
|
|
|
if (NIL_P(vperm)) perm = 0666;
|
|
|
|
else perm = NUM2UINT(vperm);
|
2002-05-23 09:35:32 +04:00
|
|
|
|
2007-09-12 10:19:06 +04:00
|
|
|
RB_GC_GUARD(fname) = rb_str_new4(fname);
|
2009-02-25 11:36:45 +03:00
|
|
|
fd = rb_sysopen(fname, oflags, perm);
|
2002-05-23 09:35:32 +04:00
|
|
|
return INT2NUM(fd);
|
|
|
|
}
|
|
|
|
|
2008-08-23 05:45:49 +04:00
|
|
|
static VALUE
|
|
|
|
check_pipe_command(VALUE filename_or_command)
|
|
|
|
{
|
|
|
|
char *s = RSTRING_PTR(filename_or_command);
|
|
|
|
long l = RSTRING_LEN(filename_or_command);
|
|
|
|
char *e = s + l;
|
|
|
|
int chlen;
|
|
|
|
|
|
|
|
if (rb_enc_ascget(s, e, &chlen, rb_enc_get(filename_or_command)) == '|') {
|
|
|
|
VALUE cmd = rb_str_new(s+chlen, l-chlen);
|
|
|
|
OBJ_INFECT(cmd, filename_or_command);
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* open(path [, mode_enc [, perm]] [, opt] ) => io or nil
|
|
|
|
* open(path [, mode_enc [, perm]] [, opt] ) {|io| block } => obj
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Creates an <code>IO</code> object connected to the given stream,
|
|
|
|
* file, or subprocess.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* If <i>path</i> does not start with a pipe character
|
|
|
|
* (``<code>|</code>''), treat it as the name of a file to open using
|
2008-01-05 06:35:13 +03:00
|
|
|
* the specified mode (defaulting to ``<code>r</code>'').
|
|
|
|
*
|
|
|
|
* The mode_enc is
|
2008-03-19 18:29:09 +03:00
|
|
|
* either a string or an integer. If it is an integer, it must be
|
2007-12-23 20:13:07 +03:00
|
|
|
* bitwise-or of open(2) flags, such as File::RDWR or File::EXCL.
|
2008-01-05 06:35:13 +03:00
|
|
|
* If it is a string, it is either "mode", "mode:ext_enc", or
|
|
|
|
* "mode:ext_enc:int_enc".
|
|
|
|
* The mode is one of the following:
|
2007-12-23 20:13:07 +03:00
|
|
|
*
|
|
|
|
* r: read (default)
|
|
|
|
* w: write
|
|
|
|
* a: append
|
|
|
|
*
|
|
|
|
* The mode can be followed by "b" (means binary-mode), or "+"
|
2008-01-05 06:35:13 +03:00
|
|
|
* (means both reading and writing allowed) or both.
|
|
|
|
* If ext_enc (external encoding) is specified,
|
|
|
|
* read string will be tagged by the encoding in reading,
|
|
|
|
* and output string will be converted
|
|
|
|
* to the specified encoding in writing.
|
|
|
|
* If two encoding names,
|
|
|
|
* ext_enc and int_enc (external encoding and internal encoding),
|
|
|
|
* are specified, the read string is converted from ext_enc
|
|
|
|
* to int_enc then tagged with the int_enc in read mode,
|
|
|
|
* and in write mode, the output string will be
|
|
|
|
* converted from int_enc to ext_enc before writing.
|
2008-03-19 18:29:09 +03:00
|
|
|
*
|
2007-12-23 20:13:07 +03:00
|
|
|
* If a file is being created, its initial permissions may be
|
|
|
|
* set using the integer third parameter.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* If a block is specified, it will be invoked with the
|
|
|
|
* <code>File</code> object as a parameter, and the file will be
|
2005-01-25 07:03:02 +03:00
|
|
|
* automatically closed when the block terminates. The call
|
|
|
|
* returns the value of the block.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* If <i>path</i> starts with a pipe character, a subprocess is
|
|
|
|
* created, connected to the caller by a pair of pipes. The returned
|
|
|
|
* <code>IO</code> object may be used to write to the standard input
|
|
|
|
* and read from the standard output of this subprocess. If the command
|
|
|
|
* following the ``<code>|</code>'' is a single minus sign, Ruby forks,
|
|
|
|
* and this subprocess is connected to the parent. In the subprocess,
|
|
|
|
* the <code>open</code> call returns <code>nil</code>. If the command
|
|
|
|
* is not ``<code>-</code>'', the subprocess runs the command. If a
|
|
|
|
* block is associated with an <code>open("|-")</code> call, that block
|
|
|
|
* will be run twice---once in the parent and once in the child. The
|
|
|
|
* block parameter will be an <code>IO</code> object in the parent and
|
|
|
|
* <code>nil</code> in the child. The parent's <code>IO</code> object
|
|
|
|
* will be connected to the child's <code>$stdin</code> and
|
|
|
|
* <code>$stdout</code>. The subprocess will be terminated at the end
|
|
|
|
* of the block.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* open("testfile") do |f|
|
|
|
|
* print f.gets
|
|
|
|
* end
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* This is line one
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Open a subprocess and read its output:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* cmd = open("|date")
|
|
|
|
* print cmd.gets
|
|
|
|
* cmd.close
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Wed Apr 9 08:56:31 CDT 2003
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Open a subprocess running the same Ruby program:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* f = open("|-", "w+")
|
|
|
|
* if f == nil
|
|
|
|
* puts "in Child"
|
|
|
|
* exit
|
|
|
|
* else
|
|
|
|
* puts "Got: #{f.gets}"
|
|
|
|
* end
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Got: in Child
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Open a subprocess using a block to receive the I/O object:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* open("|-") do |f|
|
|
|
|
* if f == nil
|
|
|
|
* puts "in Child"
|
|
|
|
* else
|
|
|
|
* puts "Got: #{f.gets}"
|
|
|
|
* end
|
|
|
|
* end
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Got: in Child
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_open(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-06-07 16:38:03 +04:00
|
|
|
ID to_open = 0;
|
2007-12-01 08:22:15 +03:00
|
|
|
int redirect = Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-12-01 08:22:15 +03:00
|
|
|
if (argc >= 1) {
|
2008-06-09 13:25:32 +04:00
|
|
|
CONST_ID(to_open, "to_open");
|
2004-04-05 19:55:09 +04:00
|
|
|
if (rb_respond_to(argv[0], to_open)) {
|
2007-12-01 08:22:15 +03:00
|
|
|
redirect = Qtrue;
|
2004-04-05 19:55:09 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-12-09 06:18:21 +03:00
|
|
|
VALUE tmp = argv[0];
|
|
|
|
FilePathValue(tmp);
|
2007-12-01 08:22:15 +03:00
|
|
|
if (NIL_P(tmp)) {
|
|
|
|
redirect = Qtrue;
|
|
|
|
}
|
|
|
|
else {
|
2008-08-23 05:45:49 +04:00
|
|
|
VALUE cmd = check_pipe_command(tmp);
|
|
|
|
if (!NIL_P(cmd)) {
|
|
|
|
argv[0] = cmd;
|
2004-10-31 20:37:52 +03:00
|
|
|
return rb_io_s_popen(argc, argv, rb_cIO);
|
2004-04-07 06:51:05 +04:00
|
|
|
}
|
2004-04-05 19:55:09 +04:00
|
|
|
}
|
2000-05-24 08:34:26 +04:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2007-12-01 08:22:15 +03:00
|
|
|
if (redirect) {
|
|
|
|
VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1);
|
|
|
|
|
|
|
|
if (rb_block_given_p()) {
|
|
|
|
return rb_ensure(rb_yield, io, io_close, io);
|
|
|
|
}
|
|
|
|
return io;
|
|
|
|
}
|
2002-01-18 17:24:01 +03:00
|
|
|
return rb_io_s_open(argc, argv, rb_cFile);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
2008-09-04 15:20:53 +04:00
|
|
|
rb_io_open(VALUE filename, VALUE vmode, VALUE vperm, VALUE opt)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2008-08-23 05:45:49 +04:00
|
|
|
VALUE cmd;
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags, fmode;
|
2008-08-20 18:56:23 +04:00
|
|
|
convconfig_t convconfig;
|
2008-08-24 14:18:32 +04:00
|
|
|
mode_t perm;
|
|
|
|
|
2008-09-17 20:39:47 +04:00
|
|
|
rb_io_extract_modeenc(&vmode, &vperm, opt, &oflags, &fmode, &convconfig);
|
2008-08-24 14:18:32 +04:00
|
|
|
perm = NIL_P(vperm) ? 0666 : NUM2UINT(vperm);
|
2008-08-20 18:56:23 +04:00
|
|
|
|
2008-08-23 05:45:49 +04:00
|
|
|
if (!NIL_P(cmd = check_pipe_command(filename))) {
|
2008-09-05 15:30:35 +04:00
|
|
|
return pipe_open_s(cmd, rb_io_oflags_modestr(oflags), fmode, &convconfig);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-08-22 00:12:29 +04:00
|
|
|
return rb_file_open_generic(io_alloc(rb_cFile), filename,
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags, fmode, &convconfig, perm);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-04 08:36:08 +03:00
|
|
|
static VALUE
|
|
|
|
rb_io_open_with_args(int argc, VALUE *argv)
|
|
|
|
{
|
2008-08-20 15:33:36 +04:00
|
|
|
VALUE io;
|
2008-03-04 08:36:08 +03:00
|
|
|
|
2008-08-20 15:33:36 +04:00
|
|
|
io = io_alloc(rb_cFile);
|
|
|
|
rb_open_file(argc, argv, io);
|
|
|
|
return io;
|
2008-03-04 08:36:08 +03:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_reopen(VALUE io, VALUE nfile)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr, *orig;
|
2003-07-26 22:10:47 +04:00
|
|
|
int fd, fd2;
|
2002-05-29 09:20:39 +04:00
|
|
|
off_t pos = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
nfile = rb_io_get_io(nfile);
|
* object.c (rb_obj_untrusted): new method Object#untrusted?.
(rb_obj_untrust): new method Object#untrust.
(rb_obj_trust): new method Object#trust.
* array.c, debug.c, time.c, include/ruby/ruby.h, re.c, variable.c,
string.c, io.c, dir.c, vm_method.c, struct.c, class.c, hash.c,
ruby.c, marshal.c: fixes for Object#untrusted?.
* test/ruby/test_module.rb, test/ruby/test_array.rb,
test/ruby/test_object.rb, test/ruby/test_string.rb,
test/ruby/test_marshal.rb, test/ruby/test_hash.rb: added tests for
Object#untrusted?.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18568 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-13 11:25:05 +04:00
|
|
|
if (rb_safe_level() >= 4 &&
|
|
|
|
(!OBJ_UNTRUSTED(io) || !OBJ_UNTRUSTED(nfile))) {
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't reopen");
|
|
|
|
}
|
|
|
|
GetOpenFile(io, fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(nfile, orig);
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (fptr == orig) return io;
|
2006-08-06 12:14:05 +04:00
|
|
|
if (IS_PREP_STDIO(fptr)) {
|
2008-02-14 15:01:50 +03:00
|
|
|
if ((fptr->stdio_file == stdin && !(orig->mode & FMODE_READABLE)) ||
|
|
|
|
(fptr->stdio_file == stdout && !(orig->mode & FMODE_WRITABLE)) ||
|
|
|
|
(fptr->stdio_file == stderr && !(orig->mode & FMODE_WRITABLE))) {
|
2004-12-23 20:53:58 +03:00
|
|
|
rb_raise(rb_eArgError,
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
"%s can't change access mode from \"%s\" to \"%s\"",
|
2008-09-05 15:30:35 +04:00
|
|
|
PREP_STDIO_NAME(fptr), rb_io_fmode_modestr(fptr->mode),
|
|
|
|
rb_io_fmode_modestr(orig->mode));
|
2004-12-23 20:53:58 +03:00
|
|
|
}
|
|
|
|
}
|
2000-06-14 12:08:50 +04:00
|
|
|
if (orig->mode & FMODE_READABLE) {
|
2002-10-02 18:59:25 +04:00
|
|
|
pos = io_tell(orig);
|
2000-06-14 12:08:50 +04:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (orig->mode & FMODE_WRITABLE) {
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(orig) < 0)
|
|
|
|
rb_sys_fail(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2003-05-21 21:42:56 +04:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
2003-05-21 21:42:56 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
/* copy rb_io_t structure */
|
2008-02-14 15:01:50 +03:00
|
|
|
fptr->mode = orig->mode | (fptr->mode & FMODE_PREP);
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->pid = orig->pid;
|
|
|
|
fptr->lineno = orig->lineno;
|
2009-04-26 13:35:34 +04:00
|
|
|
if (RTEST(orig->pathv)) fptr->pathv = orig->pathv;
|
|
|
|
else if (!IS_PREP_STDIO(fptr)) fptr->pathv = Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->finalize = orig->finalize;
|
2009-01-13 15:45:43 +03:00
|
|
|
#if defined (__CYGWIN__) || !defined(HAVE_FORK)
|
|
|
|
if (fptr->finalize == pipe_finalize)
|
|
|
|
pipe_add_fptr(fptr);
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fd = fptr->fd;
|
|
|
|
fd2 = orig->fd;
|
2003-07-26 22:10:47 +04:00
|
|
|
if (fd != fd2) {
|
2006-08-06 12:14:05 +04:00
|
|
|
if (IS_PREP_STDIO(fptr)) {
|
2003-07-26 22:10:47 +04:00
|
|
|
/* need to keep stdio objects */
|
|
|
|
if (dup2(fd2, fd) < 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(orig->pathv);
|
2003-07-26 22:10:47 +04:00
|
|
|
}
|
|
|
|
else {
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->stdio_file)
|
|
|
|
fclose(fptr->stdio_file);
|
|
|
|
else
|
|
|
|
close(fptr->fd);
|
|
|
|
fptr->stdio_file = 0;
|
|
|
|
fptr->fd = -1;
|
2003-07-26 22:10:47 +04:00
|
|
|
if (dup2(fd2, fd) < 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(orig->pathv);
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->fd = fd;
|
2003-07-26 22:10:47 +04:00
|
|
|
}
|
|
|
|
rb_thread_fd_close(fd);
|
|
|
|
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
|
2004-06-23 17:18:32 +04:00
|
|
|
if (io_seek(fptr, pos, SEEK_SET) < 0) {
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2004-06-23 17:18:32 +04:00
|
|
|
}
|
|
|
|
if (io_seek(orig, pos, SEEK_SET) < 0) {
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(orig->pathv);
|
2004-06-23 17:18:32 +04:00
|
|
|
}
|
2003-07-26 22:10:47 +04:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (fptr->mode & FMODE_BINMODE) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_binmode(io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-08-06 00:08:33 +04:00
|
|
|
RBASIC(io)->klass = rb_obj_class(nfile);
|
1998-01-16 15:13:05 +03:00
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-06-29 05:17:39 +04:00
|
|
|
* ios.reopen(other_IO) => ios
|
2003-12-27 03:44:05 +03:00
|
|
|
* ios.reopen(path, mode_str) => ios
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Reassociates <em>ios</em> with the I/O stream given in
|
|
|
|
* <i>other_IO</i> or to a new stream opened on <i>path</i>. This may
|
|
|
|
* dynamically change the actual class of this stream.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f1 = File.new("testfile")
|
|
|
|
* f2 = File.new("testfile")
|
|
|
|
* f2.readlines[0] #=> "This is line one\n"
|
|
|
|
* f2.reopen(f1) #=> #<File:testfile>
|
|
|
|
* f2.readlines[0] #=> "This is line one\n"
|
|
|
|
*/
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_reopen(int argc, VALUE *argv, VALUE file)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
VALUE fname, nmode;
|
2008-09-05 15:30:35 +04:00
|
|
|
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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
rb_secure(4);
|
|
|
|
if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
|
2004-04-07 06:51:05 +04:00
|
|
|
VALUE tmp = rb_io_check_io(fname);
|
|
|
|
if (!NIL_P(tmp)) {
|
|
|
|
return io_reopen(file, tmp);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-07 10:30:15 +04:00
|
|
|
FilePathValue(fname);
|
2003-05-09 12:12:52 +04:00
|
|
|
rb_io_taint_check(file);
|
|
|
|
fptr = RFILE(file)->fptr;
|
2003-06-23 12:41:07 +04:00
|
|
|
if (!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 13:30:50 +03:00
|
|
|
fptr = RFILE(file)->fptr = ALLOC(rb_io_t);
|
|
|
|
MEMZERO(fptr, rb_io_t, 1);
|
2003-06-23 12:41:07 +04:00
|
|
|
}
|
2003-05-09 12:12:52 +04:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (!NIL_P(nmode)) {
|
2008-09-05 15:30:35 +04:00
|
|
|
int fmode = rb_io_modestr_fmode(StringValueCStr(nmode));
|
2004-12-23 20:53:58 +03:00
|
|
|
if (IS_PREP_STDIO(fptr) &&
|
2008-09-05 15:30:35 +04:00
|
|
|
((fptr->mode & FMODE_READWRITE) & (fmode & FMODE_READWRITE)) !=
|
2006-07-02 06:25:11 +04:00
|
|
|
(fptr->mode & FMODE_READWRITE)) {
|
2004-12-23 20:53:58 +03:00
|
|
|
rb_raise(rb_eArgError,
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
"%s can't change access mode from \"%s\" to \"%s\"",
|
2008-09-05 15:30:35 +04:00
|
|
|
PREP_STDIO_NAME(fptr), rb_io_fmode_modestr(fptr->mode),
|
|
|
|
rb_io_fmode_modestr(fmode));
|
2004-12-23 20:53:58 +03:00
|
|
|
}
|
2008-09-05 15:30:35 +04:00
|
|
|
fptr->mode = fmode;
|
2007-12-23 19:48:28 +03:00
|
|
|
rb_io_mode_enc(fptr, StringValueCStr(nmode));
|
2008-09-04 14:22:11 +04:00
|
|
|
fptr->encs.ecflags = 0;
|
2008-09-03 22:18:10 +04:00
|
|
|
fptr->encs.ecopts = Qnil;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2008-08-23 04:47:54 +04:00
|
|
|
fptr->pathv = rb_str_new_frozen(fname);
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = rb_io_fmode_oflags(fptr->mode);
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->fd < 0) {
|
2009-02-25 11:36:45 +03:00
|
|
|
fptr->fd = rb_sysopen(fptr->pathv, oflags, 0666);
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->stdio_file = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2006-02-20 12:23:26 +03:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
2008-12-25 10:25:06 +03:00
|
|
|
if (io_fflush(fptr) < 0)
|
|
|
|
rb_sys_fail(0);
|
2006-02-20 12:23:26 +03:00
|
|
|
}
|
2008-06-11 21:25:57 +04:00
|
|
|
fptr->rbuf_off = fptr->rbuf_len = 0;
|
2006-02-20 12:23:26 +03:00
|
|
|
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->stdio_file) {
|
2008-09-05 15:30:35 +04:00
|
|
|
if (freopen(RSTRING_PTR(fptr->pathv), rb_io_oflags_modestr(oflags), fptr->stdio_file) == 0) {
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2004-12-08 16:26:27 +03:00
|
|
|
}
|
|
|
|
fptr->fd = fileno(fptr->stdio_file);
|
2001-05-02 08:22:21 +04:00
|
|
|
#ifdef USE_SETVBUF
|
2004-12-08 16:26:27 +03:00
|
|
|
if (setvbuf(fptr->stdio_file, NULL, _IOFBF, 0) != 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_warn("setvbuf() can't be honoured for %s", RSTRING_PTR(fptr->pathv));
|
2001-05-02 08:22:21 +04:00
|
|
|
#endif
|
2004-12-08 16:26:27 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (close(fptr->fd) < 0)
|
2008-08-23 04:47:54 +04:00
|
|
|
rb_sys_fail_path(fptr->pathv);
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->fd = -1;
|
2009-03-11 23:22:52 +03:00
|
|
|
fptr->fd = rb_sysopen(fptr->pathv, oflags, 0666);
|
2004-12-08 16:26:27 +03:00
|
|
|
}
|
2001-05-02 08:22:21 +04:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2004-01-18 17:16:47 +03:00
|
|
|
/* :nodoc: */
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_init_copy(VALUE dest, VALUE io)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr, *orig;
|
1998-01-16 15:13:05 +03:00
|
|
|
int fd;
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE write_io;
|
2008-12-23 18:22:18 +03:00
|
|
|
off_t pos;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-08-27 12:31:08 +04:00
|
|
|
io = rb_io_get_io(io);
|
2002-12-10 09:23:44 +03:00
|
|
|
if (dest == io) return dest;
|
1998-01-16 15:13:05 +03:00
|
|
|
GetOpenFile(io, orig);
|
2002-12-10 09:23:44 +03:00
|
|
|
MakeOpenFile(dest, fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
rb_io_flush(io);
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
/* copy rb_io_t structure */
|
2005-10-08 14:33:24 +04:00
|
|
|
fptr->mode = orig->mode & ~FMODE_PREP;
|
2008-08-24 14:40:37 +04:00
|
|
|
fptr->encs = orig->encs;
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->pid = orig->pid;
|
|
|
|
fptr->lineno = orig->lineno;
|
2008-08-23 04:47:54 +04:00
|
|
|
if (!NIL_P(orig->pathv)) fptr->pathv = orig->pathv;
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->finalize = orig->finalize;
|
2009-01-13 15:45:43 +03:00
|
|
|
#if defined (__CYGWIN__) || !defined(HAVE_FORK)
|
|
|
|
if (fptr->finalize == pipe_finalize)
|
|
|
|
pipe_add_fptr(fptr);
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
fd = ruby_dup(orig->fd);
|
|
|
|
fptr->fd = fd;
|
2008-12-23 18:22:18 +03:00
|
|
|
pos = io_tell(orig);
|
|
|
|
if (0 <= pos)
|
|
|
|
io_seek(fptr, pos, SEEK_SET);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (fptr->mode & FMODE_BINMODE) {
|
2002-12-10 09:23:44 +03:00
|
|
|
rb_io_binmode(dest);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (io != write_io) {
|
|
|
|
write_io = rb_obj_dup(write_io);
|
|
|
|
fptr->tied_io_for_writing = write_io;
|
|
|
|
rb_ivar_set(dest, rb_intern("@tied_io_for_writing"), write_io);
|
|
|
|
}
|
|
|
|
|
2002-12-10 09:23:44 +03:00
|
|
|
return dest;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.printf(format_string [, obj, ...] ) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Formats and writes to <em>ios</em>, converting parameters under
|
|
|
|
* control of the format string. See <code>Kernel#sprintf</code>
|
|
|
|
* for details.
|
|
|
|
*/
|
|
|
|
|
2002-02-20 09:35:37 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_printf(int argc, VALUE *argv, VALUE out)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_io_write(out, rb_f_sprintf(argc, argv));
|
1998-01-16 15:13:05 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* printf(io, string [, obj ... ] ) => nil
|
|
|
|
* printf(string [, obj ... ] ) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Equivalent to:
|
|
|
|
* io.write(sprintf(string, obj, ...)
|
|
|
|
* or
|
2004-01-26 16:54:41 +03:00
|
|
|
* $stdout.write(sprintf(string, obj, ...)
|
2003-12-30 19:38:32 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_printf(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE out;
|
|
|
|
|
|
|
|
if (argc == 0) return Qnil;
|
|
|
|
if (TYPE(argv[0]) == T_STRING) {
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
out = rb_stdout;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-08-24 12:21:56 +04:00
|
|
|
else {
|
1998-01-16 15:13:05 +03:00
|
|
|
out = argv[0];
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_io_write(out, rb_f_sprintf(argc, argv));
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.print() => nil
|
|
|
|
* ios.print(obj, ...) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Writes the given object(s) to <em>ios</em>. The stream must be
|
2005-09-27 11:08:58 +04:00
|
|
|
* opened for writing. If the output record separator (<code>$\\</code>)
|
2003-12-27 03:44:05 +03:00
|
|
|
* is not <code>nil</code>, it will be appended to the output. If no
|
|
|
|
* arguments are given, prints <code>$_</code>. Objects that aren't
|
|
|
|
* strings will be converted by calling their <code>to_s</code> method.
|
|
|
|
* With no argument, prints the contents of the variable <code>$_</code>.
|
|
|
|
* Returns <code>nil</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* $stdout.print("This is ", 100, " percent.\n")
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* This is 100 percent.
|
|
|
|
*/
|
|
|
|
|
2002-02-20 09:35:37 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_print(int argc, VALUE *argv, VALUE out)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
int i;
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE line;
|
|
|
|
|
|
|
|
/* if no argument given, print `$_' */
|
|
|
|
if (argc == 0) {
|
|
|
|
argc = 1;
|
1999-01-20 07:59:39 +03:00
|
|
|
line = rb_lastline_get();
|
1998-01-16 15:13:05 +03:00
|
|
|
argv = &line;
|
|
|
|
}
|
|
|
|
for (i=0; i<argc; i++) {
|
2006-09-24 01:55:46 +04:00
|
|
|
rb_io_write(out, argv[i]);
|
|
|
|
if (!NIL_P(rb_output_fs)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, rb_output_fs);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2006-09-24 01:55:46 +04:00
|
|
|
if (argc > 0 && !NIL_P(rb_output_rs)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, rb_output_rs);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* print(obj, ...) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2004-01-26 16:54:41 +03:00
|
|
|
* Prints each object in turn to <code>$stdout</code>. If the output
|
2003-12-30 19:38:32 +03:00
|
|
|
* field separator (<code>$,</code>) is not +nil+, its
|
|
|
|
* contents will appear between each field. If the output record
|
2005-09-27 11:08:58 +04:00
|
|
|
* separator (<code>$\\</code>) is not +nil+, it will be
|
2003-12-30 19:38:32 +03:00
|
|
|
* appended to the output. If no arguments are given, prints
|
|
|
|
* <code>$_</code>. Objects that aren't strings will be converted by
|
|
|
|
* calling their <code>to_s</code> method.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* print "cat", [1,2,3], 99, "\n"
|
|
|
|
* $, = ", "
|
|
|
|
* $\ = "\n"
|
|
|
|
* print "cat", [1,2,3], 99
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* cat12399
|
|
|
|
* cat, 1, 2, 3, 99
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_print(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
rb_io_print(argc, argv, rb_stdout);
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.putc(obj) => obj
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* If <i>obj</i> is <code>Numeric</code>, write the character whose
|
|
|
|
* code is <i>obj</i>, otherwise write the first character of the
|
|
|
|
* string representation of <i>obj</i> to <em>ios</em>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* $stdout.putc "A"
|
|
|
|
* $stdout.putc 65
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* AA
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_putc(VALUE io, VALUE ch)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2002-08-21 12:30:09 +04:00
|
|
|
char c = NUM2CHR(ch);
|
|
|
|
|
|
|
|
rb_io_write(io, rb_str_new(&c, 1));
|
1999-01-20 07:59:39 +03:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* putc(int) => int
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Equivalent to:
|
|
|
|
*
|
2004-01-26 16:54:41 +03:00
|
|
|
* $stdout.putc(int)
|
2003-12-30 19:38:32 +03:00
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_putc(VALUE recv, VALUE ch)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2008-03-19 17:52:43 +03:00
|
|
|
if (recv == rb_stdout) {
|
|
|
|
return rb_io_putc(recv, ch);
|
|
|
|
}
|
2008-02-21 10:47:12 +03:00
|
|
|
return rb_funcall2(rb_stdout, rb_intern("putc"), 1, &ch);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2001-12-10 10:18:16 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_puts_ary(VALUE ary, VALUE out, int recur)
|
2001-12-10 10:18:16 +03:00
|
|
|
{
|
|
|
|
VALUE tmp;
|
2002-08-21 19:47:54 +04:00
|
|
|
long i;
|
2001-12-10 10:18:16 +03:00
|
|
|
|
2008-05-07 12:43:24 +04:00
|
|
|
if (recur) {
|
|
|
|
tmp = rb_str_new2("[...]");
|
|
|
|
rb_io_puts(1, &tmp, out);
|
|
|
|
return Qnil;
|
|
|
|
}
|
2006-09-02 18:42:08 +04:00
|
|
|
for (i=0; i<RARRAY_LEN(ary); i++) {
|
|
|
|
tmp = RARRAY_PTR(ary)[i];
|
2001-12-10 10:18:16 +03:00
|
|
|
rb_io_puts(1, &tmp, out);
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.puts(obj, ...) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Writes the given objects to <em>ios</em> as with
|
|
|
|
* <code>IO#print</code>. Writes a record separator (typically a
|
|
|
|
* newline) after any that do not already end with a newline sequence.
|
|
|
|
* If called with an array argument, writes each element on a new line.
|
|
|
|
* If called without arguments, outputs a single record separator.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* $stdout.puts("this", "is", "a", "test")
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* this
|
|
|
|
* is
|
|
|
|
* a
|
|
|
|
* test
|
|
|
|
*/
|
|
|
|
|
2002-02-20 09:35:37 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_puts(int argc, VALUE *argv, VALUE out)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
int i;
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE line;
|
|
|
|
|
|
|
|
/* if no argument given, print newline. */
|
|
|
|
if (argc == 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, rb_default_rs);
|
1998-01-16 15:19:22 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
for (i=0; i<argc; i++) {
|
2006-08-31 14:47:44 +04:00
|
|
|
line = rb_check_array_type(argv[i]);
|
|
|
|
if (!NIL_P(line)) {
|
|
|
|
rb_exec_recursive(io_puts_ary, line, out);
|
|
|
|
continue;
|
2001-10-30 11:43:28 +03:00
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
line = rb_obj_as_string(argv[i]);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, line);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(line) == 0 ||
|
|
|
|
RSTRING_PTR(line)[RSTRING_LEN(line)-1] != '\n') {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, rb_default_rs);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* puts(obj, ...) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
|
|
|
* Equivalent to
|
2003-12-30 19:38:32 +03:00
|
|
|
*
|
2004-01-26 16:54:41 +03:00
|
|
|
* $stdout.puts(obj, ...)
|
2003-12-30 19:38:32 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
2008-03-19 17:52:43 +03:00
|
|
|
rb_f_puts(int argc, VALUE *argv, VALUE recv)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2008-03-19 17:52:43 +03:00
|
|
|
if (recv == rb_stdout) {
|
|
|
|
return rb_io_puts(argc, argv, recv);
|
|
|
|
}
|
2008-02-21 10:47:12 +03:00
|
|
|
return rb_funcall2(rb_stdout, rb_intern("puts"), argc, argv);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
void
|
2006-03-01 13:06:03 +03:00
|
|
|
rb_p(VALUE obj) /* for debug print within C code */
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2008-06-09 12:48:41 +04:00
|
|
|
VALUE str = rb_obj_as_string(rb_inspect(obj));
|
2008-09-23 15:55:48 +04:00
|
|
|
if (TYPE(rb_stdout) == T_FILE &&
|
|
|
|
rb_method_basic_definition_p(CLASS_OF(rb_stdout), id_write)) {
|
|
|
|
io_write(rb_stdout, str, 1);
|
|
|
|
io_write(rb_stdout, rb_default_rs, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_io_write(rb_stdout, str);
|
|
|
|
rb_io_write(rb_stdout, rb_default_rs);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2007-12-14 11:38:18 +03:00
|
|
|
* p(obj) => obj
|
|
|
|
* p(obj1, obj2, ...) => [obj, ...]
|
|
|
|
* p() => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* For each object, directly writes
|
|
|
|
* _obj_.+inspect+ followed by the current output
|
2005-01-25 07:03:02 +03:00
|
|
|
* record separator to the program's standard output.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* S = Struct.new(:name, :state)
|
|
|
|
* s = S['dave', 'TX']
|
|
|
|
* p s
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* #<S name="dave", state="TX">
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2007-06-05 11:35:34 +04:00
|
|
|
rb_f_p(int argc, VALUE *argv, VALUE self)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
int i;
|
2007-06-05 11:35:34 +04:00
|
|
|
VALUE ret = Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
for (i=0; i<argc; i++) {
|
|
|
|
rb_p(argv[i]);
|
|
|
|
}
|
2007-06-05 11:35:34 +04:00
|
|
|
if (argc == 1) {
|
|
|
|
ret = argv[0];
|
|
|
|
}
|
2007-07-24 05:37:07 +04:00
|
|
|
else if (argc > 1) {
|
2007-06-05 11:35:34 +04:00
|
|
|
ret = rb_ary_new4(argc, argv);
|
|
|
|
}
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
if (TYPE(rb_stdout) == T_FILE) {
|
|
|
|
rb_io_flush(rb_stdout);
|
2000-12-26 11:08:50 +03:00
|
|
|
}
|
2007-06-05 11:35:34 +04:00
|
|
|
return ret;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* obj.display(port=$>) => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Prints <i>obj</i> on the given port (default <code>$></code>).
|
|
|
|
* Equivalent to:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* def display(port=$>)
|
|
|
|
* port.write self
|
|
|
|
* end
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* For example:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* 1.display
|
|
|
|
* "cat".display
|
|
|
|
* [ 4, 5, 6 ].display
|
|
|
|
* puts
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* 1cat456
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_display(int argc, VALUE *argv, VALUE self)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE out;
|
|
|
|
|
2008-03-05 08:22:17 +03:00
|
|
|
if (argc == 0) {
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
out = rb_stdout;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2008-03-05 08:22:17 +03:00
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "01", &out);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, self);
|
|
|
|
|
|
|
|
return Qnil;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-05-13 09:53:08 +04:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_write_error2(const char *mesg, long len)
|
2003-05-13 09:53:08 +04:00
|
|
|
{
|
2006-02-13 07:53:22 +03:00
|
|
|
if (rb_stderr == orig_stderr || RFILE(orig_stderr)->fptr->fd < 0) {
|
2009-02-18 09:21:04 +03:00
|
|
|
(void)fwrite(mesg, sizeof(char), len, stderr);
|
2006-02-13 07:53:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_io_write(rb_stderr, rb_str_new(mesg, len));
|
|
|
|
}
|
2003-05-13 09:53:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_write_error(const char *mesg)
|
2003-05-13 09:53:08 +04:00
|
|
|
{
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
rb_write_error2(mesg, strlen(mesg));
|
2003-05-13 09:53:08 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
must_respond_to(ID mid, VALUE val, ID id)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-04-10 21:41:40 +04:00
|
|
|
if (!rb_respond_to(val, mid)) {
|
|
|
|
rb_raise(rb_eTypeError, "%s must have %s method, %s given",
|
|
|
|
rb_id2name(id), rb_id2name(mid),
|
2003-01-31 07:00:17 +03:00
|
|
|
rb_obj_classname(val));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2003-04-10 21:41:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
stdout_setter(VALUE val, ID id, VALUE *variable)
|
2003-04-10 21:41:40 +04:00
|
|
|
{
|
|
|
|
must_respond_to(id_write, val, id);
|
2003-05-13 09:53:08 +04:00
|
|
|
*variable = val;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
prep_io(int fd, int fmode, VALUE klass, const char *path)
|
1998-01-16 15:13:05 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fp;
|
2002-12-20 11:33:17 +03:00
|
|
|
VALUE io = io_alloc(klass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
MakeOpenFile(io, fp);
|
2004-12-23 21:06:19 +03:00
|
|
|
fp->fd = fd;
|
2003-02-15 21:16:52 +03:00
|
|
|
#ifdef __CYGWIN__
|
2004-12-23 21:06:19 +03:00
|
|
|
if (!isatty(fd)) {
|
2008-09-05 15:30:35 +04:00
|
|
|
fmode |= FMODE_BINMODE;
|
2004-12-23 21:06:19 +03:00
|
|
|
setmode(fd, O_BINARY);
|
2003-03-12 10:59:28 +03:00
|
|
|
}
|
2003-02-15 21:16:52 +03:00
|
|
|
#endif
|
2008-09-05 15:30:35 +04:00
|
|
|
fp->mode = fmode;
|
2005-02-07 17:18:41 +03:00
|
|
|
io_check_tty(fp);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (path) fp->pathv = rb_obj_freeze(rb_str_new_cstr(path));
|
2004-12-23 21:06:19 +03:00
|
|
|
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:29:32 +04:00
|
|
|
VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
rb_io_fdopen(int fd, int oflags, const char *path)
|
2007-09-29 00:29:32 +04:00
|
|
|
{
|
|
|
|
VALUE klass = rb_cIO;
|
|
|
|
|
|
|
|
if (path && strcmp(path, "-")) klass = rb_cFile;
|
2008-09-05 15:30:35 +04:00
|
|
|
return prep_io(fd, rb_io_oflags_fmode(oflags), klass, path);
|
2007-09-29 00:29:32 +04:00
|
|
|
}
|
|
|
|
|
2004-12-23 21:06:19 +03:00
|
|
|
static VALUE
|
2008-09-05 15:30:35 +04:00
|
|
|
prep_stdio(FILE *f, int fmode, VALUE klass, const char *path)
|
2004-12-23 21:06:19 +03: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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2008-09-05 15:30:35 +04:00
|
|
|
VALUE io = prep_io(fileno(f), fmode|FMODE_PREP, klass, path);
|
2004-12-23 21:06:19 +03:00
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
fptr->stdio_file = f;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-01-18 17:24:01 +03:00
|
|
|
return io;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
FILE *
|
|
|
|
rb_io_stdio_file(rb_io_t *fptr)
|
2004-12-08 16:26:27 +03:00
|
|
|
{
|
|
|
|
if (!fptr->stdio_file) {
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags = rb_io_fmode_oflags(fptr->mode);
|
|
|
|
fptr->stdio_file = rb_fdopen(fptr->fd, rb_io_oflags_modestr(oflags));
|
2004-12-08 16:26:27 +03:00
|
|
|
}
|
|
|
|
return fptr->stdio_file;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.new(fd [, mode] [, opt]) => io
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Returns a new <code>IO</code> object (a stream) for the given
|
2004-02-25 15:17:39 +03:00
|
|
|
* <code>IO</code> object or integer file descriptor and mode
|
|
|
|
* string. See also <code>IO#fileno</code> and
|
2008-12-03 18:02:49 +03:00
|
|
|
* <code>IO.for_fd</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-12-23 14:30:44 +03:00
|
|
|
* === Parameters
|
|
|
|
* fd:: numeric file descriptor
|
|
|
|
* mode:: file mode. a string or an integer
|
|
|
|
* opt:: hash for specifiying mode by name.
|
|
|
|
*
|
|
|
|
* ==== Mode
|
|
|
|
* When <code>mode</code> is an integer it must be combination of
|
|
|
|
* the modes defined in <code>File::Constants</code>.
|
|
|
|
*
|
2009-02-22 17:23:33 +03:00
|
|
|
* When <code>mode</code> is a string it must be in one of the
|
2008-12-23 14:30:44 +03:00
|
|
|
* following forms:
|
|
|
|
* - "fmode",
|
|
|
|
* - "fmode:extern",
|
|
|
|
* - "fmode:extern:intern".
|
2009-02-22 17:23:33 +03:00
|
|
|
* <code>extern</code> is the external encoding name for the IO.
|
2008-12-23 14:30:44 +03:00
|
|
|
* <code>intern</code> is the internal encoding.
|
|
|
|
* <code>fmode</code> must be combination of the directives. See
|
|
|
|
* the description of class +IO+ for a description of the directives.
|
|
|
|
*
|
|
|
|
* ==== Options
|
|
|
|
* <code>opt</code> can have the following keys
|
|
|
|
* :mode ::
|
|
|
|
* same as <code>mode</code> parameter
|
2009-02-22 17:23:33 +03:00
|
|
|
* :external_encoding ::
|
|
|
|
* external encoding for the IO. "-" is a
|
2008-12-23 14:30:44 +03:00
|
|
|
* synonym for the default external encoding.
|
|
|
|
* :internal_encoding ::
|
2009-02-22 17:23:33 +03:00
|
|
|
* internal encoding for the IO.
|
2008-12-23 14:30:44 +03:00
|
|
|
* "-" is a synonym for the default internal encoding.
|
2009-02-22 17:23:33 +03:00
|
|
|
* If the value is nil no conversion occurs.
|
|
|
|
* :encoding ::
|
2008-12-23 14:30:44 +03:00
|
|
|
* specifies external and internal encodings as "extern:intern".
|
|
|
|
* :textmode ::
|
|
|
|
* If the value is truth value, same as "b" in argument <code>mode</code>.
|
|
|
|
* :binmode ::
|
|
|
|
* If the value is truth value, same as "t" in argument <code>mode</code>.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2008-12-23 14:30:44 +03:00
|
|
|
* Also <code>opt</code> can have same keys in <code>String#encode</code> for
|
|
|
|
* controlling conversion between the external encoding and the internal encoding.
|
|
|
|
*
|
|
|
|
* === Example1
|
2004-02-25 15:17:39 +03:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* a = IO.new(2,"w") # '2' is standard error
|
|
|
|
* $stderr.puts "Hello"
|
|
|
|
* a.puts "World"
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Hello
|
|
|
|
* World
|
2008-12-23 14:30:44 +03:00
|
|
|
*
|
|
|
|
* === Example2
|
|
|
|
* io = IO.new(2, mode: 'w:UTF-16LE', cr_newline: true)
|
|
|
|
* io.puts "Hello, World!"
|
|
|
|
*
|
|
|
|
* io = IO.new(2, mode: 'w', cr_newline: true, external_encoding: Encoding::UTF_16LE)
|
|
|
|
* io.puts "Hello, World!"
|
|
|
|
*
|
2009-02-22 17:23:33 +03:00
|
|
|
* both of aboves print "Hello, World!" in UTF-16LE to standard error output with
|
2008-12-23 14:30:44 +03:00
|
|
|
* converting EOL generated by <code>puts</code> to CR.
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
2000-03-23 11:37:35 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-09-04 15:20:53 +04:00
|
|
|
VALUE fnum, vmode;
|
2008-08-27 19:09:47 +04:00
|
|
|
rb_io_t *fp;
|
2008-09-05 15:30:35 +04:00
|
|
|
int fd, fmode, oflags = O_RDONLY;
|
2008-08-21 21:09:56 +04:00
|
|
|
convconfig_t convconfig;
|
|
|
|
VALUE opt;
|
2008-12-25 11:07:01 +03:00
|
|
|
struct stat st;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-03-25 06:11:27 +03:00
|
|
|
rb_secure(4);
|
2008-08-21 21:09:56 +04:00
|
|
|
|
2008-10-21 17:57:16 +04:00
|
|
|
opt = pop_last_hash(&argc, argv);
|
2008-09-04 15:20:53 +04:00
|
|
|
rb_scan_args(argc, argv, "11", &fnum, &vmode);
|
2008-09-17 20:39:47 +04:00
|
|
|
rb_io_extract_modeenc(&vmode, 0, opt, &oflags, &fmode, &convconfig);
|
2008-08-27 19:09:47 +04:00
|
|
|
|
|
|
|
fd = NUM2INT(fnum);
|
2008-12-25 11:07:01 +03:00
|
|
|
if (fstat(fd, &st) == -1) rb_sys_fail(0);
|
2008-08-27 19:09:47 +04:00
|
|
|
UPDATE_MAXFD(fd);
|
2009-01-22 09:55:20 +03:00
|
|
|
if (NIL_P(vmode)) {
|
2009-01-22 10:13:40 +03:00
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFL)
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags = fcntl(fd, F_GETFL);
|
|
|
|
if (oflags == -1) rb_sys_fail(0);
|
|
|
|
fmode = rb_io_oflags_fmode(oflags);
|
2009-01-22 09:55:20 +03:00
|
|
|
#endif
|
2009-01-22 10:13:40 +03:00
|
|
|
}
|
2008-08-27 19:09:47 +04:00
|
|
|
MakeOpenFile(io, fp);
|
|
|
|
fp->fd = fd;
|
2008-09-05 15:30:35 +04:00
|
|
|
fp->mode = fmode;
|
2008-08-27 19:09:47 +04:00
|
|
|
fp->encs = convconfig;
|
|
|
|
clear_codeconv(fp);
|
|
|
|
io_check_tty(fp);
|
2009-01-13 12:21:14 +03:00
|
|
|
if (fileno(stdin) == fd)
|
|
|
|
fp->stdio_file = stdin;
|
|
|
|
else if (fileno(stdout) == fd)
|
|
|
|
fp->stdio_file = stdout;
|
|
|
|
else if (fileno(stderr) == fd)
|
|
|
|
fp->stdio_file = stderr;
|
2000-03-23 11:37:35 +03:00
|
|
|
|
2009-07-09 18:47:48 +04:00
|
|
|
if (fmode & FMODE_STRIP_BOM) io_set_encoding_by_bom(io);
|
2000-03-23 11:37:35 +03:00
|
|
|
return io;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* File.new(filename, mode="r" [, opt]) => file
|
|
|
|
* File.new(filename [, mode [, perm]] [, opt]) => file
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Opens the file named by _filename_ according to
|
|
|
|
* _mode_ (default is ``r'') and returns a new
|
2009-02-22 17:23:33 +03:00
|
|
|
* <code>File</code> object.
|
|
|
|
*
|
2008-12-23 14:30:44 +03:00
|
|
|
* === Parameters
|
2009-02-22 17:23:33 +03:00
|
|
|
* See the description of class +IO+ for a description of _mode_.
|
|
|
|
* The file mode may optionally be specified as a +Fixnum+
|
|
|
|
* by _or_-ing together the flags (O_RDONLY etc,
|
|
|
|
* again described under +IO+).
|
2008-12-23 14:30:44 +03:00
|
|
|
*
|
2009-02-22 17:23:33 +03:00
|
|
|
* Optional permission bits may be given in _perm_.
|
|
|
|
* These mode and permission bits are platform dependent;
|
2008-12-23 14:30:44 +03:00
|
|
|
* on Unix systems, see <code>open(2)</code> for details.
|
|
|
|
*
|
|
|
|
* Optional _opt_ parameter is same as in <code.IO.open</code>.
|
|
|
|
*
|
|
|
|
* === Examples
|
2003-12-30 19:38:32 +03:00
|
|
|
*
|
|
|
|
* f = File.new("testfile", "r")
|
|
|
|
* f = File.new("newfile", "w+")
|
|
|
|
* f = File.new("newfile", File::CREAT|File::TRUNC|File::RDWR, 0644)
|
|
|
|
*/
|
|
|
|
|
2000-05-24 08:34:26 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_file_initialize(int argc, VALUE *argv, VALUE io)
|
2000-05-24 08:34:26 +04:00
|
|
|
{
|
2000-07-06 11:21:26 +04:00
|
|
|
if (RFILE(io)->fptr) {
|
2004-12-02 18:17:35 +03:00
|
|
|
rb_raise(rb_eRuntimeError, "reinitializing File");
|
2000-07-06 11:21:26 +04:00
|
|
|
}
|
2002-02-05 10:56:31 +03:00
|
|
|
if (0 < argc && argc < 3) {
|
|
|
|
VALUE fd = rb_check_convert_type(argv[0], T_FIXNUM, "Fixnum", "to_int");
|
|
|
|
|
|
|
|
if (!NIL_P(fd)) {
|
|
|
|
argv[0] = fd;
|
|
|
|
return rb_io_initialize(argc, argv, io);
|
|
|
|
}
|
|
|
|
}
|
2001-06-05 11:19:39 +04:00
|
|
|
rb_open_file(argc, argv, io);
|
2000-05-24 08:34:26 +04:00
|
|
|
|
2001-06-05 11:19:39 +04:00
|
|
|
return io;
|
2000-05-24 08:34:26 +04:00
|
|
|
}
|
|
|
|
|
2001-02-13 08:09:11 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_new(int argc, VALUE *argv, VALUE klass)
|
2001-02-13 08:09:11 +03:00
|
|
|
{
|
2002-01-18 17:24:01 +03:00
|
|
|
if (rb_block_given_p()) {
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *cname = rb_class2name(klass);
|
2001-10-03 11:19:19 +04:00
|
|
|
|
2002-04-01 11:39:09 +04:00
|
|
|
rb_warn("%s::new() does not take block; use %s::open() instead",
|
2002-01-18 17:24:01 +03:00
|
|
|
cname, cname);
|
2001-02-13 08:09:11 +03:00
|
|
|
}
|
2002-01-18 17:24:01 +03:00
|
|
|
return rb_class_new_instance(argc, argv, klass);
|
2001-02-13 08:09:11 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.for_fd(fd, mode [, opt]) => io
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2008-12-03 18:02:49 +03:00
|
|
|
* Synonym for <code>IO.new</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
2003-04-03 09:25:00 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_for_fd(int argc, VALUE *argv, VALUE klass)
|
2003-04-03 09:25:00 +04:00
|
|
|
{
|
|
|
|
VALUE io = rb_obj_alloc(klass);
|
|
|
|
rb_io_initialize(argc, argv, io);
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
static void
|
|
|
|
argf_mark(void *ptr)
|
|
|
|
{
|
|
|
|
struct argf *p = ptr;
|
|
|
|
rb_gc_mark(p->filename);
|
|
|
|
rb_gc_mark(p->current_file);
|
|
|
|
rb_gc_mark(p->argv);
|
2008-09-04 20:22:57 +04:00
|
|
|
rb_gc_mark(p->encs.ecopts);
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
argf_free(void *ptr)
|
|
|
|
{
|
|
|
|
struct argf *p = ptr;
|
|
|
|
free(p->inplace);
|
|
|
|
}
|
|
|
|
|
2008-03-19 18:21:15 +03:00
|
|
|
static inline void
|
|
|
|
argf_init(struct argf *p, VALUE v)
|
|
|
|
{
|
|
|
|
p->filename = Qnil;
|
|
|
|
p->current_file = Qnil;
|
2009-06-26 22:10:12 +04:00
|
|
|
p->lineno = 0;
|
2008-03-19 18:21:15 +03:00
|
|
|
p->argv = v;
|
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
static VALUE
|
|
|
|
argf_alloc(VALUE klass)
|
|
|
|
{
|
|
|
|
struct argf *p;
|
|
|
|
VALUE argf = Data_Make_Struct(klass, struct argf, argf_mark, argf_free, p);
|
|
|
|
|
2008-03-19 18:21:15 +03:00
|
|
|
argf_init(p, Qnil);
|
2008-03-01 11:59:04 +03:00
|
|
|
return argf;
|
|
|
|
}
|
|
|
|
|
2008-04-15 14:21:01 +04:00
|
|
|
#undef rb_argv
|
1999-08-13 09:45:20 +04:00
|
|
|
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_initialize(VALUE argf, VALUE argv)
|
|
|
|
{
|
2008-03-19 18:21:15 +03:00
|
|
|
memset(&ARGF, 0, sizeof(ARGF));
|
|
|
|
argf_init(&ARGF, argv);
|
|
|
|
|
|
|
|
return argf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_initialize_copy(VALUE argf, VALUE orig)
|
|
|
|
{
|
|
|
|
ARGF = argf_of(orig);
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.argv = rb_obj_dup(ARGF.argv);
|
2008-03-19 18:21:15 +03:00
|
|
|
if (ARGF.inplace) {
|
|
|
|
const char *inplace = ARGF.inplace;
|
|
|
|
ARGF.inplace = 0;
|
|
|
|
ARGF.inplace = ruby_strdup(inplace);
|
|
|
|
}
|
2008-03-01 11:59:04 +03:00
|
|
|
return argf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_set_lineno(VALUE argf, VALUE val)
|
|
|
|
{
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.lineno = NUM2INT(val);
|
|
|
|
ARGF.last_lineno = ARGF.lineno;
|
2008-03-01 11:59:04 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_lineno(VALUE argf)
|
|
|
|
{
|
2009-06-26 22:10:12 +04:00
|
|
|
return INT2FIX(ARGF.lineno);
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_forward(int argc, VALUE *argv, VALUE argf)
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_funcall3(ARGF.current_file, rb_frame_this_func(), argc, argv);
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
#define next_argv() argf_next_argv(argf)
|
|
|
|
#define ARGF_GENERIC_INPUT_P() \
|
2008-09-04 07:33:27 +04:00
|
|
|
(ARGF.current_file == rb_stdin && TYPE(ARGF.current_file) != T_FILE)
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
#define ARGF_FORWARD(argc, argv) do {\
|
2008-03-01 11:59:04 +03:00
|
|
|
if (ARGF_GENERIC_INPUT_P())\
|
|
|
|
return argf_forward(argc, argv, argf);\
|
2004-10-27 13:29:26 +04:00
|
|
|
} while (0)
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
#define NEXT_ARGF_FORWARD(argc, argv) do {\
|
2008-03-01 11:59:04 +03:00
|
|
|
if (!next_argv()) return Qnil;\
|
|
|
|
ARGF_FORWARD(argc, argv);\
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
argf_close(VALUE file)
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
{
|
2007-08-14 15:03:29 +04:00
|
|
|
rb_funcall3(file, rb_intern("close"), 0, 0);
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_next_argv(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
char *fn;
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
int stdout_binmode = 0;
|
2003-01-12 12:24:28 +03:00
|
|
|
|
2003-08-19 06:21:04 +04:00
|
|
|
if (TYPE(rb_stdout) == T_FILE) {
|
|
|
|
GetOpenFile(rb_stdout, fptr);
|
|
|
|
if (fptr->mode & FMODE_BINMODE)
|
|
|
|
stdout_binmode = 1;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.init_p == 0) {
|
|
|
|
if (!NIL_P(ARGF.argv) && RARRAY_LEN(ARGF.argv) > 0) {
|
|
|
|
ARGF.next_p = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.next_p = -1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.init_p = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.next_p == 1) {
|
|
|
|
ARGF.next_p = 0;
|
2003-12-26 20:05:20 +03:00
|
|
|
retry:
|
2008-09-04 07:33:27 +04:00
|
|
|
if (RARRAY_LEN(ARGF.argv) > 0) {
|
|
|
|
ARGF.filename = rb_ary_shift(ARGF.argv);
|
|
|
|
fn = StringValueCStr(ARGF.filename);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (strlen(fn) == 1 && fn[0] == '-') {
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.current_file = rb_stdin;
|
|
|
|
if (ARGF.inplace) {
|
2003-12-26 20:05:20 +03:00
|
|
|
rb_warn("Can't do inplace edit for stdio; skipping");
|
|
|
|
goto retry;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-02-25 11:36:45 +03:00
|
|
|
int fr = rb_sysopen(ARGF.filename, O_RDONLY, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.inplace) {
|
2007-08-25 10:20:48 +04:00
|
|
|
struct stat st;
|
|
|
|
#ifndef NO_SAFE_RENAME
|
|
|
|
struct stat st2;
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE str;
|
2004-12-23 21:06:19 +03:00
|
|
|
int fw;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
if (TYPE(rb_stdout) == T_FILE && rb_stdout != orig_stdout) {
|
|
|
|
rb_io_close(rb_stdout);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-12-23 21:06:19 +03:00
|
|
|
fstat(fr, &st);
|
2008-09-04 07:33:27 +04:00
|
|
|
if (*ARGF.inplace) {
|
1999-01-20 07:59:39 +03:00
|
|
|
str = rb_str_new2(fn);
|
2000-08-25 12:26:06 +04:00
|
|
|
#ifdef NO_LONG_FNAME
|
2008-09-04 07:33:27 +04:00
|
|
|
ruby_add_suffix(str, ARGF.inplace);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2008-09-04 07:33:27 +04:00
|
|
|
rb_str_cat2(str, ARGF.inplace);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2000-08-25 12:26:06 +04:00
|
|
|
#ifdef NO_SAFE_RENAME
|
2004-12-23 21:06:19 +03:00
|
|
|
(void)close(fr);
|
2006-08-31 14:47:44 +04:00
|
|
|
(void)unlink(RSTRING_PTR(str));
|
|
|
|
(void)rename(fn, RSTRING_PTR(str));
|
2009-02-25 11:36:45 +03:00
|
|
|
fr = rb_sysopen(str, O_RDONLY, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2006-08-31 14:47:44 +04:00
|
|
|
if (rename(fn, RSTRING_PTR(str)) < 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_warn("Can't rename %s to %s: %s, skipping file",
|
2006-08-31 14:47:44 +04:00
|
|
|
fn, RSTRING_PTR(str), strerror(errno));
|
2004-12-23 21:06:19 +03:00
|
|
|
close(fr);
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
2000-08-25 12:26:06 +04:00
|
|
|
#ifdef NO_SAFE_RENAME
|
|
|
|
rb_fatal("Can't do inplace edit without backup");
|
|
|
|
#else
|
1998-01-16 15:13:05 +03:00
|
|
|
if (unlink(fn) < 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_warn("Can't remove %s: %s, skipping file",
|
|
|
|
fn, strerror(errno));
|
2004-12-23 21:06:19 +03:00
|
|
|
close(fr);
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2009-02-25 11:36:45 +03:00
|
|
|
fw = rb_sysopen(ARGF.filename, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
2000-08-25 12:26:06 +04:00
|
|
|
#ifndef NO_SAFE_RENAME
|
2004-12-23 21:06:19 +03:00
|
|
|
fstat(fw, &st2);
|
2000-11-13 08:39:35 +03:00
|
|
|
#ifdef HAVE_FCHMOD
|
2004-12-23 21:06:19 +03:00
|
|
|
fchmod(fw, st.st_mode);
|
2000-11-13 08:39:35 +03:00
|
|
|
#else
|
|
|
|
chmod(fn, st.st_mode);
|
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
|
2009-02-18 09:21:04 +03:00
|
|
|
#ifdef HAVE_FCHOWN
|
|
|
|
(void)fchown(fw, st.st_uid, st.st_gid);
|
2009-02-22 17:23:33 +03:00
|
|
|
#else
|
2009-02-18 09:21:04 +03:00
|
|
|
(void)chown(fn, st.st_uid, st.st_gid);
|
2009-02-22 17:23:33 +03:00
|
|
|
#endif
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
#endif
|
2004-12-23 21:06:19 +03:00
|
|
|
rb_stdout = prep_io(fw, FMODE_WRITABLE, rb_cFile, fn);
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
if (stdout_binmode) rb_io_binmode(rb_stdout);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.current_file = prep_io(fr, FMODE_READABLE, rb_cFile, fn);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2009-06-25 13:01:45 +04:00
|
|
|
if (ARGF.binmode) rb_io_ascii8bit_binmode(ARGF.current_file);
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.encs.enc) {
|
2007-12-24 21:17:35 +03:00
|
|
|
rb_io_t *fptr;
|
|
|
|
|
2008-09-04 07:33:27 +04:00
|
|
|
GetOpenFile(ARGF.current_file, fptr);
|
2008-09-04 05:33:47 +04:00
|
|
|
fptr->encs = ARGF.encs;
|
2008-08-18 16:06:42 +04:00
|
|
|
clear_codeconv(fptr);
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.next_p = 1;
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
else if (ARGF.next_p == -1) {
|
|
|
|
ARGF.current_file = rb_stdin;
|
|
|
|
ARGF.filename = rb_str_new2("-");
|
|
|
|
if (ARGF.inplace) {
|
2003-12-26 20:05:20 +03:00
|
|
|
rb_warn("Can't do inplace edit for stdio");
|
|
|
|
rb_stdout = orig_stdout;
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-20 15:46:35 +03:00
|
|
|
argf_getline(int argc, VALUE *argv, VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE line;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
if (!next_argv()) return Qnil;
|
2008-03-01 11:59:04 +03:00
|
|
|
if (ARGF_GENERIC_INPUT_P()) {
|
2008-09-04 07:33:27 +04:00
|
|
|
line = rb_funcall3(ARGF.current_file, rb_intern("gets"), argc, argv);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
else {
|
2007-08-14 15:03:29 +04:00
|
|
|
if (argc == 0 && rb_rs == rb_default_rs) {
|
2008-09-04 07:33:27 +04:00
|
|
|
line = rb_io_gets(ARGF.current_file);
|
2007-08-14 15:03:29 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
line = rb_io_getline(argc, argv, ARGF.current_file);
|
2007-08-14 15:03:29 +04:00
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
if (NIL_P(line) && ARGF.next_p != -1) {
|
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
2007-08-14 15:03:29 +04:00
|
|
|
goto retry;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2003-02-04 10:27:43 +03:00
|
|
|
if (!NIL_P(line)) {
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.lineno++;
|
|
|
|
ARGF.last_lineno = ARGF.lineno;
|
2003-02-04 10:27:43 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
static VALUE
|
|
|
|
argf_lineno_getter(ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
VALUE argf = *var;
|
2009-06-26 22:10:12 +04:00
|
|
|
return INT2FIX(ARGF.last_lineno);
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
argf_lineno_setter(VALUE val, ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
VALUE argf = *var;
|
|
|
|
int n = NUM2INT(val);
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.last_lineno = ARGF.lineno = n;
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
|
2008-05-13 03:27:17 +04:00
|
|
|
static VALUE argf_gets(int, VALUE *, VALUE);
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-12-29 22:21:50 +03:00
|
|
|
* gets(sep=$/) => string or nil
|
|
|
|
* gets(limit) => string or nil
|
|
|
|
* gets(sep,limit) => string or nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Returns (and assigns to <code>$_</code>) the next line from the list
|
2006-12-29 22:21:50 +03:00
|
|
|
* of files in +ARGV+ (or <code>$*</code>), or from standard input if
|
|
|
|
* no files are present on the command line. Returns +nil+ at end of
|
|
|
|
* file. The optional argument specifies the record separator. The
|
|
|
|
* separator is included with the contents of each record. A separator
|
|
|
|
* of +nil+ reads the entire contents, and a zero-length separator
|
|
|
|
* reads the input one paragraph at a time, where paragraphs are
|
|
|
|
* divided by two consecutive newlines. If the first argument is an
|
|
|
|
* integer, or optional second argument is given, the returning string
|
2008-09-16 13:29:40 +04:00
|
|
|
* would not be longer than the given value in bytes. If multiple
|
|
|
|
* filenames are present in +ARGV+, +gets(nil)+ will read the contents
|
|
|
|
* one file at a time.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* ARGV << "testfile"
|
|
|
|
* print while gets
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* This is line one
|
|
|
|
* This is line two
|
|
|
|
* This is line three
|
|
|
|
* And so on...
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* The style of programming using <code>$_</code> as an implicit
|
|
|
|
* parameter is gradually losing favor in the Ruby community.
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
static VALUE
|
2008-03-21 15:32:33 +03:00
|
|
|
rb_f_gets(int argc, VALUE *argv, VALUE recv)
|
|
|
|
{
|
|
|
|
if (recv == argf) {
|
|
|
|
return argf_gets(argc, argv, argf);
|
|
|
|
}
|
|
|
|
return rb_funcall2(argf, rb_intern("gets"), argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_gets(int argc, VALUE *argv, VALUE argf)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
VALUE line;
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2008-03-20 15:46:35 +03:00
|
|
|
line = argf_getline(argc, argv, argf);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_lastline_set(line);
|
2009-06-26 22:10:12 +04:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_gets(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE line;
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (rb_rs != rb_default_rs) {
|
2008-03-21 15:32:33 +03:00
|
|
|
return rb_f_gets(0, 0, argf);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
retry:
|
|
|
|
if (!next_argv()) return Qnil;
|
2008-09-04 07:33:27 +04:00
|
|
|
line = rb_io_gets(ARGF.current_file);
|
|
|
|
if (NIL_P(line) && ARGF.next_p != -1) {
|
|
|
|
rb_io_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
1999-01-20 07:59:39 +03:00
|
|
|
goto retry;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_lastline_set(line);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!NIL_P(line)) {
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.lineno++;
|
|
|
|
ARGF.last_lineno = ARGF.lineno;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-05-13 03:27:17 +04:00
|
|
|
static VALUE argf_readline(int, VALUE *, VALUE);
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-12-29 22:21:50 +03:00
|
|
|
* readline(sep=$/) => string
|
|
|
|
* readline(limit) => string
|
|
|
|
* readline(sep, limit) => string
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Equivalent to <code>Kernel::gets</code>, except
|
|
|
|
* +readline+ raises +EOFError+ at end of file.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2008-03-21 15:32:33 +03:00
|
|
|
rb_f_readline(int argc, VALUE *argv, VALUE recv)
|
|
|
|
{
|
|
|
|
if (recv == argf) {
|
|
|
|
return argf_readline(argc, argv, argf);
|
|
|
|
}
|
|
|
|
return rb_funcall2(argf, rb_intern("readline"), argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_readline(int argc, VALUE *argv, VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
VALUE line;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-12-30 22:29:56 +03:00
|
|
|
if (!next_argv()) rb_eof_error();
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(argc, argv);
|
2008-03-21 15:32:33 +03:00
|
|
|
line = argf_gets(argc, argv, argf);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (NIL_P(line)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_eof_error();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2008-05-13 03:27:17 +04:00
|
|
|
static VALUE argf_readlines(int, VALUE *, VALUE);
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2006-12-29 22:21:50 +03:00
|
|
|
* readlines(sep=$/) => array
|
|
|
|
* readlines(limit) => array
|
|
|
|
* readlines(sep,limit) => array
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Returns an array containing the lines returned by calling
|
2006-12-29 22:21:50 +03:00
|
|
|
* <code>Kernel.gets(<i>sep</i>)</code> until the end of file.
|
2003-12-30 19:38:32 +03:00
|
|
|
*/
|
|
|
|
|
2008-03-21 15:32:33 +03:00
|
|
|
static VALUE
|
|
|
|
rb_f_readlines(int argc, VALUE *argv, VALUE recv)
|
|
|
|
{
|
|
|
|
if (recv == argf) {
|
|
|
|
return argf_readlines(argc, argv, argf);
|
|
|
|
}
|
|
|
|
return rb_funcall2(argf, rb_intern("readlines"), argc, argv);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2008-03-21 15:32:33 +03:00
|
|
|
argf_readlines(int argc, VALUE *argv, VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE line, ary;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
ary = rb_ary_new();
|
2008-03-20 15:46:35 +03:00
|
|
|
while (!NIL_P(line = argf_getline(argc, argv, argf))) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_push(ary, line);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* `cmd` => string
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Returns the standard output of running _cmd_ in a subshell.
|
|
|
|
* The built-in syntax <code>%x{...}</code> uses
|
|
|
|
* this method. Sets <code>$?</code> to the process status.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* `date` #=> "Wed Apr 9 08:56:30 CDT 2003\n"
|
|
|
|
* `ls testdir`.split[1] #=> "main.rb"
|
|
|
|
* `echo oops && exit 99` #=> "oops\n"
|
|
|
|
* $?.exitstatus #=> 99
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_backquote(VALUE obj, VALUE str)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2005-12-19 20:11:20 +03:00
|
|
|
volatile VALUE port;
|
|
|
|
VALUE result;
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(str);
|
2008-08-20 22:14:07 +04:00
|
|
|
port = pipe_open_s(str, "r", FMODE_READABLE, NULL);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (NIL_P(port)) return rb_str_new(0,0);
|
2002-03-25 17:50:40 +03:00
|
|
|
|
|
|
|
GetOpenFile(port, fptr);
|
2002-12-11 12:32:41 +03:00
|
|
|
result = read_all(fptr, remain_size(fptr), Qnil);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_close(port);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
#include <sys/select.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2005-06-03 18:23:17 +04:00
|
|
|
VALUE res, list;
|
2009-04-01 08:56:51 +04:00
|
|
|
rb_fdset_t *rp, *wp, *ep;
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-08-21 19:47:54 +04:00
|
|
|
long i;
|
|
|
|
int max = 0, n;
|
1999-01-20 07:59:39 +03:00
|
|
|
int interrupt_flag = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
int pending = 0;
|
2005-06-03 18:23:17 +04:00
|
|
|
struct timeval timerec;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (!NIL_P(read)) {
|
|
|
|
Check_Type(read, T_ARRAY);
|
2006-09-02 18:42:08 +04:00
|
|
|
for (i=0; i<RARRAY_LEN(read); i++) {
|
|
|
|
GetOpenFile(rb_io_get_io(RARRAY_PTR(read)[i]), fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_set(fptr->fd, &fds[0]);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (READ_DATA_PENDING(fptr)) { /* check for buffered data */
|
1998-01-16 15:13:05 +03:00
|
|
|
pending++;
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_set(fptr->fd, &fds[3]);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (max < fptr->fd) max = fptr->fd;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
if (pending) { /* no blocking if there's buffered data */
|
|
|
|
timerec.tv_sec = timerec.tv_usec = 0;
|
|
|
|
tp = &timerec;
|
|
|
|
}
|
2009-04-01 08:56:51 +04:00
|
|
|
rp = &fds[0];
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else
|
2000-07-06 11:21:26 +04:00
|
|
|
rp = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (!NIL_P(write)) {
|
|
|
|
Check_Type(write, T_ARRAY);
|
2006-09-02 18:42:08 +04:00
|
|
|
for (i=0; i<RARRAY_LEN(write); i++) {
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE write_io = GetWriteIO(rb_io_get_io(RARRAY_PTR(write)[i]));
|
|
|
|
GetOpenFile(write_io, fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_set(fptr->fd, &fds[1]);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (max < fptr->fd) max = fptr->fd;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2009-04-01 08:56:51 +04:00
|
|
|
wp = &fds[1];
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else
|
2000-07-06 11:21:26 +04:00
|
|
|
wp = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (!NIL_P(except)) {
|
|
|
|
Check_Type(except, T_ARRAY);
|
2006-09-02 18:42:08 +04:00
|
|
|
for (i=0; i<RARRAY_LEN(except); i++) {
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE io = rb_io_get_io(RARRAY_PTR(except)[i]);
|
|
|
|
VALUE write_io = GetWriteIO(io);
|
|
|
|
GetOpenFile(io, fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_set(fptr->fd, &fds[2]);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
if (max < fptr->fd) max = fptr->fd;
|
2007-11-20 06:16:53 +03:00
|
|
|
if (io != write_io) {
|
|
|
|
GetOpenFile(write_io, fptr);
|
|
|
|
rb_fd_set(fptr->fd, &fds[2]);
|
|
|
|
if (max < fptr->fd) max = fptr->fd;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2009-04-01 08:56:51 +04:00
|
|
|
ep = &fds[2];
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-07-06 11:21:26 +04:00
|
|
|
else {
|
|
|
|
ep = 0;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
max++;
|
|
|
|
|
2009-04-01 08:56:51 +04:00
|
|
|
n = rb_thread_fd_select(max, rp, wp, ep, tp);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (n < 0) {
|
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
|
|
|
if (!pending && n == 0) return Qnil; /* returns nil on timeout */
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
res = rb_ary_new2(3);
|
|
|
|
rb_ary_push(res, rp?rb_ary_new():rb_ary_new2(0));
|
|
|
|
rb_ary_push(res, wp?rb_ary_new():rb_ary_new2(0));
|
|
|
|
rb_ary_push(res, ep?rb_ary_new():rb_ary_new2(0));
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (interrupt_flag == 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
if (rp) {
|
2006-09-02 18:42:08 +04:00
|
|
|
list = RARRAY_PTR(res)[0];
|
|
|
|
for (i=0; i< RARRAY_LEN(read); i++) {
|
2007-12-20 19:12:38 +03:00
|
|
|
VALUE obj = rb_ary_entry(read, i);
|
|
|
|
VALUE io = rb_io_get_io(obj);
|
2007-11-20 06:16:53 +03:00
|
|
|
GetOpenFile(io, fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
if (rb_fd_isset(fptr->fd, &fds[0]) ||
|
|
|
|
rb_fd_isset(fptr->fd, &fds[3])) {
|
2007-12-20 19:12:38 +03:00
|
|
|
rb_ary_push(list, obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wp) {
|
2006-09-02 18:42:08 +04:00
|
|
|
list = RARRAY_PTR(res)[1];
|
|
|
|
for (i=0; i< RARRAY_LEN(write); i++) {
|
2007-12-20 19:12:38 +03:00
|
|
|
VALUE obj = rb_ary_entry(write, i);
|
|
|
|
VALUE io = rb_io_get_io(obj);
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE write_io = GetWriteIO(io);
|
|
|
|
GetOpenFile(write_io, fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
if (rb_fd_isset(fptr->fd, &fds[1])) {
|
2007-12-20 19:12:38 +03:00
|
|
|
rb_ary_push(list, obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ep) {
|
2006-09-02 18:42:08 +04:00
|
|
|
list = RARRAY_PTR(res)[2];
|
|
|
|
for (i=0; i< RARRAY_LEN(except); i++) {
|
2008-01-30 18:21:40 +03:00
|
|
|
VALUE obj = rb_ary_entry(except, i);
|
2007-12-20 19:12:38 +03:00
|
|
|
VALUE io = rb_io_get_io(obj);
|
2007-11-20 06:16:53 +03:00
|
|
|
VALUE write_io = GetWriteIO(io);
|
|
|
|
GetOpenFile(io, fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
if (rb_fd_isset(fptr->fd, &fds[2])) {
|
2007-12-20 19:12:38 +03:00
|
|
|
rb_ary_push(list, obj);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2007-11-20 06:16:53 +03:00
|
|
|
else if (io != write_io) {
|
|
|
|
GetOpenFile(write_io, fptr);
|
|
|
|
if (rb_fd_isset(fptr->fd, &fds[2])) {
|
2007-12-20 19:12:38 +03:00
|
|
|
rb_ary_push(list, obj);
|
2007-11-20 06:16:53 +03:00
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res; /* returns an empty array on interrupt */
|
|
|
|
}
|
|
|
|
|
2005-06-03 18:23:17 +04:00
|
|
|
struct select_args {
|
|
|
|
VALUE read, write, except;
|
|
|
|
struct timeval *timeout;
|
|
|
|
rb_fdset_t fdsets[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef HAVE_RB_FD_INIT
|
|
|
|
static VALUE
|
2006-03-01 13:06:03 +03:00
|
|
|
select_call(VALUE arg)
|
2005-06-03 18:23:17 +04:00
|
|
|
{
|
|
|
|
struct select_args *p = (struct select_args *)arg;
|
|
|
|
|
|
|
|
return select_internal(p->read, p->write, p->except, p->timeout, p->fdsets);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-03-01 13:06:03 +03:00
|
|
|
select_end(VALUE arg)
|
2005-06-03 18:23:17 +04:00
|
|
|
{
|
|
|
|
struct select_args *p = (struct select_args *)arg;
|
|
|
|
int i;
|
|
|
|
|
2009-04-26 13:46:41 +04:00
|
|
|
for (i = 0; i < numberof(p->fdsets); ++i)
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_term(&p->fdsets[i]);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.select(read_array
|
|
|
|
* [, write_array
|
|
|
|
* [, error_array
|
|
|
|
* [, timeout]]] ) => array or nil
|
|
|
|
*
|
|
|
|
* See <code>Kernel#select</code>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_select(int argc, VALUE *argv, VALUE obj)
|
2005-06-03 18:23:17 +04:00
|
|
|
{
|
|
|
|
VALUE timeout;
|
|
|
|
struct select_args args;
|
|
|
|
struct timeval timerec;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "13", &args.read, &args.write, &args.except, &timeout);
|
|
|
|
if (NIL_P(timeout)) {
|
|
|
|
args.timeout = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
timerec = rb_time_interval(timeout);
|
|
|
|
args.timeout = &timerec;
|
|
|
|
}
|
|
|
|
|
2009-04-26 13:46:41 +04:00
|
|
|
for (i = 0; i < numberof(args.fdsets); ++i)
|
2005-06-03 18:23:17 +04:00
|
|
|
rb_fd_init(&args.fdsets[i]);
|
|
|
|
|
|
|
|
#ifdef HAVE_RB_FD_INIT
|
|
|
|
return rb_ensure(select_call, (VALUE)&args, select_end, (VALUE)&args);
|
|
|
|
#else
|
|
|
|
return select_internal(args.read, args.write, args.except,
|
|
|
|
args.timeout, args.fdsets);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-11-27 12:23:38 +03:00
|
|
|
static int
|
2009-04-26 13:46:41 +04:00
|
|
|
io_cntl(int fd, unsigned long cmd, long narg, int io_p)
|
2000-11-27 12:23:38 +03:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL
|
|
|
|
# if defined(__CYGWIN__)
|
|
|
|
retval = io_p?ioctl(fd, cmd, (void*)narg):fcntl(fd, cmd, narg);
|
|
|
|
# else
|
2009-04-26 13:46:41 +04:00
|
|
|
retval = io_p?ioctl(fd, cmd, narg):fcntl(fd, (int)cmd, narg);
|
2000-11-27 12:23:38 +03:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
if (!io_p) {
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
retval = ioctl(fd, cmd, narg);
|
|
|
|
#endif
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2009-04-26 13:46:41 +04:00
|
|
|
unsigned long cmd = NUM2ULONG(req);
|
* 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 13:30:50 +03:00
|
|
|
rb_io_t *fptr;
|
2002-08-21 19:47:54 +04:00
|
|
|
long len = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
long narg = 0;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
rb_secure(2);
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (NIL_P(arg) || arg == Qfalse) {
|
1998-01-16 15:13:05 +03:00
|
|
|
narg = 0;
|
|
|
|
}
|
|
|
|
else if (FIXNUM_P(arg)) {
|
2002-08-21 19:47:54 +04:00
|
|
|
narg = FIX2LONG(arg);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
else if (arg == Qtrue) {
|
1998-01-16 15:13:05 +03:00
|
|
|
narg = 1;
|
|
|
|
}
|
|
|
|
else {
|
2003-06-07 19:34:31 +04:00
|
|
|
VALUE tmp = rb_check_string_type(arg);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-06-07 19:34:31 +04:00
|
|
|
if (NIL_P(tmp)) {
|
|
|
|
narg = NUM2LONG(arg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
arg = tmp;
|
1998-01-16 15:13:05 +03:00
|
|
|
#ifdef IOCPARM_MASK
|
|
|
|
#ifndef IOCPARM_LEN
|
|
|
|
#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef IOCPARM_LEN
|
2003-06-07 19:34:31 +04:00
|
|
|
len = IOCPARM_LEN(cmd); /* on BSDish systems we're safe */
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2003-06-07 19:34:31 +04:00
|
|
|
len = 256; /* otherwise guess at what's safe */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
2003-06-07 19:34:31 +04:00
|
|
|
rb_str_modify(arg);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2006-08-31 14:47:44 +04:00
|
|
|
if (len <= RSTRING_LEN(arg)) {
|
|
|
|
len = RSTRING_LEN(arg);
|
2003-06-07 19:34:31 +04:00
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(arg) < len) {
|
2003-06-07 19:34:31 +04:00
|
|
|
rb_str_resize(arg, len+1);
|
|
|
|
}
|
2006-08-31 14:47:44 +04:00
|
|
|
RSTRING_PTR(arg)[len] = 17; /* a little sanity check here */
|
|
|
|
narg = (long)RSTRING_PTR(arg);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-12-02 03:27:27 +03:00
|
|
|
GetOpenFile(io, fptr);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
retval = io_cntl(fptr->fd, cmd, narg, io_p);
|
2008-08-23 04:47:54 +04:00
|
|
|
if (retval < 0) rb_sys_fail_path(fptr->pathv);
|
2006-08-31 14:47:44 +04:00
|
|
|
if (TYPE(arg) == T_STRING && RSTRING_PTR(arg)[len] != 17) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_raise(rb_eArgError, "return value overflowed string");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-11-27 12:23:38 +03:00
|
|
|
|
2005-07-20 13:14:30 +04:00
|
|
|
if (!io_p && cmd == F_SETFL) {
|
2009-04-26 13:46:41 +04:00
|
|
|
if (narg & O_NONBLOCK) {
|
|
|
|
fptr->mode |= FMODE_WSPLIT_INITIALIZED;
|
|
|
|
fptr->mode &= ~FMODE_WSPLIT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fptr->mode &= ~(FMODE_WSPLIT_INITIALIZED|FMODE_WSPLIT);
|
|
|
|
}
|
2005-07-20 13:14:30 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
return INT2NUM(retval);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.ioctl(integer_cmd, arg) => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Provides a mechanism for issuing low-level commands to control or
|
|
|
|
* query I/O devices. Arguments and results are platform dependent. If
|
|
|
|
* <i>arg</i> is a number, its value is passed directly. If it is a
|
|
|
|
* string, it is interpreted as a binary sequence of bytes. On Unix
|
|
|
|
* platforms, see <code>ioctl(2)</code> for details. Not implemented on
|
|
|
|
* all platforms.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_ioctl(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE req, arg;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &req, &arg);
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_io_ctl(io, req, arg, 1);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2009-04-16 20:58:06 +04:00
|
|
|
#ifdef HAVE_FCNTL
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.fcntl(integer_cmd, arg) => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Provides a mechanism for issuing low-level commands to control or
|
|
|
|
* query file-oriented I/O streams. Arguments and results are platform
|
|
|
|
* dependent. If <i>arg</i> is a number, its value is passed
|
|
|
|
* directly. If it is a string, it is interpreted as a binary sequence
|
|
|
|
* of bytes (<code>Array#pack</code> might be a useful way to build this
|
|
|
|
* string). On Unix platforms, see <code>fcntl(2)</code> for details.
|
|
|
|
* Not implemented on all platforms.
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_fcntl(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE req, arg;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &req, &arg);
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_io_ctl(io, req, arg, 0);
|
2009-04-16 20:58:06 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2009-04-16 20:58:06 +04:00
|
|
|
#define rb_io_fcntl rb_f_notimplement
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
2009-06-22 16:23:06 +04:00
|
|
|
#if defined(HAVE_SYSCALL) && SIZEOF_LONG == SIZEOF_INT
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* syscall(fixnum [, args...]) => integer
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* Calls the operating system function identified by _fixnum_,
|
|
|
|
* passing in the arguments, which must be either +String+
|
|
|
|
* objects, or +Integer+ objects that ultimately fit within
|
|
|
|
* a native +long+. Up to nine parameters may be passed (14
|
|
|
|
* on the Atari-ST). The function identified by _fixnum_ is system
|
|
|
|
* dependent. On some Unix systems, the numbers may be obtained from a
|
|
|
|
* header file called <code>syscall.h</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-30 19:38:32 +03:00
|
|
|
* hello
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_f_syscall(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifdef atarist
|
|
|
|
unsigned long arg[14]; /* yes, we really need that many ! */
|
|
|
|
#else
|
|
|
|
unsigned long arg[8];
|
|
|
|
#endif
|
|
|
|
int retval = -1;
|
|
|
|
int i = 1;
|
|
|
|
int items = argc - 1;
|
|
|
|
|
|
|
|
/* This probably won't work on machines where sizeof(long) != sizeof(int)
|
|
|
|
* or where sizeof(long) != sizeof(char*). But such machines will
|
|
|
|
* not likely have syscall implemented either, so who cares?
|
|
|
|
*/
|
|
|
|
|
|
|
|
rb_secure(2);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (argc == 0)
|
|
|
|
rb_raise(rb_eArgError, "too few arguments for syscall");
|
2009-04-26 13:46:41 +04:00
|
|
|
if (argc > numberof(arg))
|
2007-02-13 09:06:30 +03:00
|
|
|
rb_raise(rb_eArgError, "too many arguments for syscall");
|
2002-08-21 19:47:54 +04:00
|
|
|
arg[0] = NUM2LONG(argv[0]); argv++;
|
1998-01-16 15:13:05 +03:00
|
|
|
while (items--) {
|
2003-05-30 20:08:03 +04:00
|
|
|
VALUE v = rb_check_string_type(*argv);
|
2001-03-28 12:43:25 +04:00
|
|
|
|
2003-05-30 20:08:03 +04:00
|
|
|
if (!NIL_P(v)) {
|
2001-05-02 08:22:21 +04:00
|
|
|
StringValue(v);
|
2001-03-28 12:43:25 +04:00
|
|
|
rb_str_modify(v);
|
2008-01-28 06:32:27 +03:00
|
|
|
arg[i] = (unsigned long)StringValueCStr(v);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2003-05-30 20:08:03 +04:00
|
|
|
else {
|
|
|
|
arg[i] = (unsigned long)NUM2LONG(*argv);
|
|
|
|
}
|
2001-03-28 12:43:25 +04:00
|
|
|
argv++;
|
1998-01-16 15:13:05 +03:00
|
|
|
i++;
|
|
|
|
}
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
switch (argc) {
|
|
|
|
case 1:
|
|
|
|
retval = syscall(arg[0]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
retval = syscall(arg[0],arg[1]);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2]);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3]);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4]);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
|
|
|
|
arg[7]);
|
|
|
|
break;
|
|
|
|
#ifdef atarist
|
|
|
|
case 9:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
|
|
|
|
arg[7], arg[8]);
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
|
|
|
|
arg[7], arg[8], arg[9]);
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
|
|
|
|
arg[7], arg[8], arg[9], arg[10]);
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
|
|
|
|
arg[7], arg[8], arg[9], arg[10], arg[11]);
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
|
|
|
|
arg[7], arg[8], arg[9], arg[10], arg[11], arg[12]);
|
|
|
|
break;
|
|
|
|
case 14:
|
|
|
|
retval = syscall(arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],
|
|
|
|
arg[7], arg[8], arg[9], arg[10], arg[11], arg[12], arg[13]);
|
|
|
|
break;
|
|
|
|
#endif /* atarist */
|
|
|
|
}
|
* include/ruby/signal.h: removed.
* common.mk, class.c, eval.c, eval_intern.h, file.c, gc.c, hash.c,
io.c, process.c, signal.c: vm_core.h: ditto.
Some unused external global variables are also removed.
(rb_prohibit_interrupt, rb_trap_immediate, rb_trap_pending,
rb_thread_critical)
* ext/openssl/ossl_ssl.c, ext/openssl/ossl_x509store.c,
ext/readline/readline.c, ext/socket/depend,
ext/socket/socket.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-03 12:00:05 +04:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (retval < 0) rb_sys_fail(0);
|
|
|
|
return INT2NUM(retval);
|
2009-04-16 20:58:06 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2009-04-16 20:58:06 +04:00
|
|
|
#define rb_f_syscall rb_f_notimplement
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_new_instance(VALUE args)
|
2003-06-23 12:41:07 +04:00
|
|
|
{
|
|
|
|
return rb_class_new_instance(2, (VALUE*)args+1, *(VALUE*)args);
|
|
|
|
}
|
|
|
|
|
2007-12-25 08:11:59 +03:00
|
|
|
static void
|
2008-09-13 14:28:06 +04:00
|
|
|
io_encoding_set(rb_io_t *fptr, VALUE v1, VALUE v2, VALUE opt)
|
2007-12-24 21:17:35 +03:00
|
|
|
{
|
2008-09-12 21:58:58 +04:00
|
|
|
rb_encoding *enc, *enc2;
|
|
|
|
int ecflags;
|
2008-10-07 21:39:44 +04:00
|
|
|
VALUE ecopts, tmp;
|
2008-09-12 21:58:58 +04:00
|
|
|
|
2008-09-13 14:28:06 +04:00
|
|
|
if (!NIL_P(v2)) {
|
2008-09-12 21:58:58 +04:00
|
|
|
enc2 = rb_to_encoding(v1);
|
2008-10-07 21:39:44 +04:00
|
|
|
tmp = rb_check_string_type(v2);
|
|
|
|
if (!NIL_P(tmp)) {
|
|
|
|
char *p = StringValueCStr(tmp);
|
|
|
|
if (*p == '-' && *(p+1) == '\0') {
|
|
|
|
/* Special case - "-" => no transcoding */
|
|
|
|
enc = enc2;
|
|
|
|
enc2 = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
enc = rb_to_encoding(v2);
|
2009-02-09 05:35:38 +03:00
|
|
|
if (enc == enc2) {
|
|
|
|
/* Special case - "-" => no transcoding */
|
|
|
|
enc2 = NULL;
|
|
|
|
}
|
2008-10-07 21:39:44 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
enc = rb_to_encoding(v2);
|
2008-09-12 21:58:58 +04:00
|
|
|
ecflags = rb_econv_prepare_opts(opt, &ecopts);
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
2008-09-13 14:28:06 +04:00
|
|
|
else {
|
2008-01-10 09:44:30 +03:00
|
|
|
if (NIL_P(v1)) {
|
2008-10-07 21:39:44 +04:00
|
|
|
/* Set to default encodings */
|
|
|
|
rb_io_ext_int_to_encs(NULL, NULL, &enc, &enc2);
|
2008-09-12 21:58:58 +04:00
|
|
|
ecflags = 0;
|
|
|
|
ecopts = Qnil;
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-10-07 21:39:44 +04:00
|
|
|
tmp = rb_check_string_type(v1);
|
2008-01-10 09:42:49 +03:00
|
|
|
if (!NIL_P(tmp)) {
|
2008-09-12 21:58:58 +04:00
|
|
|
parse_mode_enc(StringValueCStr(tmp), &enc, &enc2);
|
|
|
|
ecflags = rb_econv_prepare_opts(opt, &ecopts);
|
2008-01-10 09:42:49 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-10-07 21:39:44 +04:00
|
|
|
rb_io_ext_int_to_encs(rb_to_encoding(v1), NULL, &enc, &enc2);
|
2008-09-12 21:58:58 +04:00
|
|
|
ecflags = 0;
|
|
|
|
ecopts = Qnil;
|
2008-01-10 09:42:49 +03:00
|
|
|
}
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
|
|
|
}
|
2008-09-12 21:58:58 +04:00
|
|
|
validate_enc_binmode(fptr->mode, enc, enc2);
|
|
|
|
fptr->encs.enc = enc;
|
|
|
|
fptr->encs.enc2 = enc2;
|
|
|
|
fptr->encs.ecflags = ecflags;
|
|
|
|
fptr->encs.ecopts = ecopts;
|
|
|
|
clear_codeconv(fptr);
|
|
|
|
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
|
|
|
|
2008-12-23 06:00:31 +03:00
|
|
|
static VALUE
|
2009-01-14 06:35:25 +03:00
|
|
|
pipe_pair_close(VALUE rw)
|
2008-12-22 15:27:26 +03:00
|
|
|
{
|
2009-01-14 06:35:25 +03:00
|
|
|
VALUE *rwp = (VALUE *)rw;
|
|
|
|
return rb_ensure(io_close, rwp[0], io_close, rwp[1]);
|
2008-12-22 15:27:26 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.pipe -> [read_io, write_io]
|
|
|
|
* IO.pipe(ext_enc) -> [read_io, write_io]
|
|
|
|
* IO.pipe("ext_enc:int_enc" [, opt]) -> [read_io, write_io]
|
|
|
|
* IO.pipe(ext_enc, int_enc [, opt]) -> [read_io, write_io]
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2008-12-22 15:27:26 +03:00
|
|
|
* IO.pipe(...) {|read_io, write_io| ... }
|
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Creates a pair of pipe endpoints (connected to each other) and
|
|
|
|
* returns them as a two-element array of <code>IO</code> objects:
|
2008-12-22 15:27:26 +03:00
|
|
|
* <code>[</code> <i>read_io</i>, <i>write_io</i> <code>]</code>.
|
|
|
|
*
|
|
|
|
* If a block is given, the block is called and
|
|
|
|
* returns the value of the block.
|
|
|
|
* <i>read_io</i> and <i>write_io</i> are sent to the block as arguments.
|
2009-06-20 23:15:08 +04:00
|
|
|
* If read_io and write_io are not closed when the block exits, they are closed.
|
2009-07-12 21:36:23 +04:00
|
|
|
* i.e. closing read_io and/or write_io doesn't cause an error.
|
2008-12-22 15:27:26 +03:00
|
|
|
*
|
|
|
|
* Not available on all platforms.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2008-01-05 06:35:13 +03:00
|
|
|
* If an encoding (encoding name or encoding object) is specified as an optional argument,
|
|
|
|
* read string from pipe is tagged with the encoding specified.
|
|
|
|
* If the argument is a colon separated two encoding names "A:B",
|
|
|
|
* the read string is converted from encoding A (external encoding)
|
|
|
|
* to encoding B (internal encoding), then tagged with B.
|
|
|
|
* If two optional arguments are specified, those must be
|
|
|
|
* encoding objects or encoding names,
|
|
|
|
* and the first one is the external encoding,
|
|
|
|
* and the second one is the internal encoding.
|
2008-08-24 14:32:59 +04:00
|
|
|
* If the external encoding and the internal encoding is specified,
|
|
|
|
* optional hash argument specify the conversion option.
|
2007-12-23 19:48:28 +03:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* In the example below, the two processes close the ends of the pipe
|
|
|
|
* that they are not using. This is not just a cosmetic nicety. The
|
|
|
|
* read end of a pipe will not generate an end of file condition if
|
|
|
|
* there are any writers with the pipe still open. In the case of the
|
|
|
|
* parent process, the <code>rd.read</code> will never return if it
|
|
|
|
* does not first issue a <code>wr.close</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* rd, wr = IO.pipe
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* if fork
|
|
|
|
* wr.close
|
|
|
|
* puts "Parent got: <#{rd.read}>"
|
|
|
|
* rd.close
|
|
|
|
* Process.wait
|
|
|
|
* else
|
|
|
|
* rd.close
|
|
|
|
* puts "Sending message to parent"
|
|
|
|
* wr.write "Hi Dad"
|
|
|
|
* wr.close
|
|
|
|
* end
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Sending message to parent
|
|
|
|
* Parent got: <Hi Dad>
|
|
|
|
*/
|
|
|
|
|
2003-06-23 12:41:07 +04:00
|
|
|
static VALUE
|
2007-12-23 19:48:28 +03:00
|
|
|
rb_io_s_pipe(int argc, VALUE *argv, VALUE klass)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-06-23 12:41:07 +04:00
|
|
|
int pipes[2], state;
|
2007-12-24 21:17:35 +03:00
|
|
|
VALUE r, w, args[3], v1, v2;
|
2008-08-24 13:40:31 +04:00
|
|
|
VALUE opt;
|
2008-10-28 15:00:42 +03:00
|
|
|
rb_io_t *fptr, *fptr2;
|
|
|
|
int fmode = 0;
|
2008-12-22 15:27:26 +03:00
|
|
|
VALUE ret;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-10-21 17:57:16 +04:00
|
|
|
opt = pop_last_hash(&argc, argv);
|
2007-12-24 21:17:35 +03:00
|
|
|
rb_scan_args(argc, argv, "02", &v1, &v2);
|
2008-07-05 18:12:53 +04:00
|
|
|
if (rb_pipe(pipes) == -1)
|
2008-07-05 17:38:46 +04:00
|
|
|
rb_sys_fail(0);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-06-23 12:41:07 +04:00
|
|
|
args[0] = klass;
|
|
|
|
args[1] = INT2NUM(pipes[0]);
|
|
|
|
args[2] = INT2FIX(O_RDONLY);
|
|
|
|
r = rb_protect(io_new_instance, (VALUE)args, &state);
|
|
|
|
if (state) {
|
|
|
|
close(pipes[0]);
|
|
|
|
close(pipes[1]);
|
|
|
|
rb_jump_tag(state);
|
|
|
|
}
|
2007-12-24 21:17:35 +03:00
|
|
|
GetOpenFile(r, fptr);
|
2008-09-13 14:28:06 +04:00
|
|
|
io_encoding_set(fptr, v1, v2, opt);
|
2003-06-23 12:41:07 +04:00
|
|
|
args[1] = INT2NUM(pipes[1]);
|
|
|
|
args[2] = INT2FIX(O_WRONLY);
|
|
|
|
w = rb_protect(io_new_instance, (VALUE)args, &state);
|
|
|
|
if (state) {
|
|
|
|
close(pipes[1]);
|
|
|
|
if (!NIL_P(r)) rb_io_close(r);
|
|
|
|
rb_jump_tag(state);
|
|
|
|
}
|
2008-10-28 15:00:42 +03:00
|
|
|
GetOpenFile(w, fptr2);
|
|
|
|
rb_io_synchronized(fptr2);
|
|
|
|
|
|
|
|
extract_binmode(opt, &fmode);
|
|
|
|
fptr->mode |= fmode;
|
|
|
|
fptr2->mode |= fmode;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-12-22 15:27:26 +03:00
|
|
|
ret = rb_assoc_new(r, w);
|
|
|
|
if (rb_block_given_p()) {
|
2009-01-14 06:35:25 +03:00
|
|
|
VALUE rw[2];
|
|
|
|
rw[0] = r;
|
|
|
|
rw[1] = w;
|
|
|
|
return rb_ensure(rb_yield, ret, pipe_pair_close, (VALUE)rw);
|
2008-12-22 15:27:26 +03:00
|
|
|
}
|
|
|
|
return ret;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct foreach_arg {
|
|
|
|
int argc;
|
2006-12-29 22:21:50 +03:00
|
|
|
VALUE *argv;
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE io;
|
|
|
|
};
|
|
|
|
|
2007-12-23 19:02:46 +03:00
|
|
|
static void
|
|
|
|
open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
|
|
|
|
{
|
|
|
|
VALUE opt, v;
|
|
|
|
|
|
|
|
FilePathValue(argv[0]);
|
2008-02-15 10:35:11 +03:00
|
|
|
arg->io = 0;
|
2008-08-20 20:57:46 +04:00
|
|
|
arg->argc = argc - 1;
|
2007-12-23 19:02:46 +03:00
|
|
|
arg->argv = argv + 1;
|
|
|
|
if (argc == 1) {
|
|
|
|
no_key:
|
2008-08-24 14:18:32 +04:00
|
|
|
arg->io = rb_io_open(argv[0], INT2NUM(O_RDONLY), INT2FIX(0666), Qnil);
|
2007-12-23 19:02:46 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-10-21 17:57:16 +04:00
|
|
|
opt = pop_last_hash(&arg->argc, arg->argv);
|
2007-12-23 19:02:46 +03:00
|
|
|
if (NIL_P(opt)) goto no_key;
|
|
|
|
|
2008-06-17 01:31:56 +04:00
|
|
|
v = rb_hash_aref(opt, sym_open_args);
|
2007-12-23 19:02:46 +03:00
|
|
|
if (!NIL_P(v)) {
|
|
|
|
VALUE args;
|
2009-04-26 13:46:41 +04:00
|
|
|
long n;
|
2007-12-23 19:02:46 +03:00
|
|
|
|
|
|
|
v = rb_convert_type(v, T_ARRAY, "Array", "to_ary");
|
2009-04-26 13:46:41 +04:00
|
|
|
n = RARRAY_LEN(v) + 1;
|
|
|
|
#if SIZEOF_LONG > SIZEOF_INT
|
|
|
|
if (n > INT_MAX) {
|
|
|
|
rb_raise(rb_eArgError, "too many arguments");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
args = rb_ary_tmp_new(n);
|
2007-12-23 19:02:46 +03:00
|
|
|
rb_ary_push(args, argv[0]);
|
|
|
|
rb_ary_concat(args, v);
|
2009-04-26 13:46:41 +04:00
|
|
|
arg->io = rb_io_open_with_args((int)n, RARRAY_PTR(args));
|
|
|
|
rb_ary_clear(args); /* prevent from GC */
|
2007-12-23 19:02:46 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-09-23 14:48:17 +04:00
|
|
|
arg->io = rb_io_open(argv[0], Qnil, Qnil, opt);
|
2007-12-23 19:02:46 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_s_foreach(struct foreach_arg *arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
|
2006-12-29 22:21:50 +03:00
|
|
|
while (!NIL_P(str = rb_io_gets_m(arg->argc, arg->argv, arg->io))) {
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_yield(str);
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.foreach(name, sep=$/ [, open_args]) {|line| block } => nil
|
|
|
|
* IO.foreach(name, limit [, open_args]) {|line| block } => nil
|
|
|
|
* IO.foreach(name, sep, limit [, open_args]) {|line| block } => nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Executes the block for every line in the named I/O port, where lines
|
2006-12-29 22:21:50 +03:00
|
|
|
* are separated by <em>sep</em>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* IO.foreach("testfile") {|x| print "GOT ", x }
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* <em>produces:</em>
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* GOT This is line one
|
|
|
|
* GOT This is line two
|
|
|
|
* GOT This is line three
|
|
|
|
* GOT And so on...
|
2007-12-23 19:02:46 +03:00
|
|
|
*
|
|
|
|
* If the last argument is a hash, it's the keyword argument to open.
|
|
|
|
* See <code>IO.read</code> for detail.
|
|
|
|
*
|
2004-06-29 05:17:39 +04:00
|
|
|
*/
|
2003-12-27 03:44:05 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_foreach(int argc, VALUE *argv, VALUE self)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct foreach_arg arg;
|
|
|
|
|
2007-12-23 19:02:46 +03:00
|
|
|
rb_scan_args(argc, argv, "13", NULL, NULL, NULL, NULL);
|
2007-08-20 18:46:03 +04:00
|
|
|
RETURN_ENUMERATOR(self, argc, argv);
|
2007-12-23 19:02:46 +03:00
|
|
|
open_key_args(argc, argv, &arg);
|
2004-11-23 20:37:51 +03:00
|
|
|
if (NIL_P(arg.io)) return Qnil;
|
|
|
|
return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_s_readlines(struct foreach_arg *arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2006-12-29 22:21:50 +03:00
|
|
|
return rb_io_readlines(arg->argc, arg->argv, arg->io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.readlines(name, sep=$/ [, open_args]) => array
|
|
|
|
* IO.readlines(name, limit [, open_args]) => array
|
|
|
|
* IO.readlines(name, sep, limit [, open_args]) => array
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Reads the entire file specified by <i>name</i> as individual
|
|
|
|
* lines, and returns those lines in an array. Lines are separated by
|
2006-12-29 22:21:50 +03:00
|
|
|
* <i>sep</i>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* a = IO.readlines("testfile")
|
|
|
|
* a[0] #=> "This is line one\n"
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2007-12-23 19:02:46 +03:00
|
|
|
* If the last argument is a hash, it's the keyword argument to open.
|
|
|
|
* See <code>IO.read</code> for detail.
|
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_readlines(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
struct foreach_arg arg;
|
|
|
|
|
2007-12-23 19:02:46 +03:00
|
|
|
rb_scan_args(argc, argv, "13", NULL, NULL, NULL, NULL);
|
|
|
|
open_key_args(argc, argv, &arg);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (NIL_P(arg.io)) return Qnil;
|
2001-01-18 11:43:14 +03:00
|
|
|
return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
io_s_read(struct foreach_arg *arg)
|
2001-01-18 11:43:14 +03:00
|
|
|
{
|
2006-12-29 22:21:50 +03:00
|
|
|
return io_read(arg->argc, arg->argv, arg->io);
|
2001-01-18 11:43:14 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2005-01-25 07:03:02 +03:00
|
|
|
* IO.read(name, [length [, offset]] ) => string
|
2008-08-24 14:32:59 +04:00
|
|
|
* IO.read(name, [length [, offset]], open_args) => string
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Opens the file, optionally seeks to the given offset, then returns
|
|
|
|
* <i>length</i> bytes (defaulting to the rest of the file).
|
|
|
|
* <code>read</code> ensures the file is closed before returning.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2007-12-23 19:02:46 +03:00
|
|
|
* If the last argument is a hash, it specifies option for internal
|
2008-02-15 10:35:11 +03:00
|
|
|
* open(). The key would be the following. open_args: is exclusive
|
|
|
|
* to others.
|
|
|
|
*
|
2007-12-23 19:02:46 +03:00
|
|
|
* encoding: string or encoding
|
|
|
|
*
|
|
|
|
* specifies encoding of the read string. encoding will be ignored
|
|
|
|
* if length is specified.
|
|
|
|
*
|
|
|
|
* mode: string
|
|
|
|
*
|
|
|
|
* specifies mode argument for open(). it should start with "r"
|
|
|
|
* otherwise it would cause error.
|
|
|
|
*
|
|
|
|
* open_args: array of strings
|
|
|
|
*
|
|
|
|
* specifies arguments for open() as an array.
|
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* IO.read("testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
|
|
|
|
* IO.read("testfile", 20) #=> "This is line one\nThi"
|
|
|
|
* IO.read("testfile", 20, 10) #=> "ne one\nThis is line "
|
|
|
|
*/
|
|
|
|
|
2001-01-18 11:43:14 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_io_s_read(int argc, VALUE *argv, VALUE io)
|
2001-01-18 11:43:14 +03:00
|
|
|
{
|
2007-12-23 19:02:46 +03:00
|
|
|
VALUE offset;
|
2001-01-18 11:43:14 +03:00
|
|
|
struct foreach_arg arg;
|
|
|
|
|
2007-12-23 19:02:46 +03:00
|
|
|
rb_scan_args(argc, argv, "13", NULL, NULL, &offset, NULL);
|
|
|
|
open_key_args(argc, argv, &arg);
|
2001-01-18 11:43:14 +03:00
|
|
|
if (NIL_P(arg.io)) return Qnil;
|
2007-12-23 18:56:41 +03:00
|
|
|
if (!NIL_P(offset)) {
|
2007-12-21 10:02:55 +03:00
|
|
|
rb_io_binmode(arg.io);
|
2001-03-13 08:45:13 +03:00
|
|
|
rb_io_seek(arg.io, offset, SEEK_SET);
|
2007-12-23 19:02:46 +03:00
|
|
|
if (arg.argc == 2) arg.argc = 1;
|
2001-01-18 11:43:14 +03:00
|
|
|
}
|
|
|
|
return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-09-23 14:48:17 +04:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.binread(name, [length [, offset]] ) => string
|
|
|
|
*
|
|
|
|
* Opens the file, optionally seeks to the given offset, then returns
|
|
|
|
* <i>length</i> bytes (defaulting to the rest of the file).
|
|
|
|
* <code>read</code> ensures the file is closed before returning.
|
|
|
|
* The open mode would be "rb:ASCII-8BIT".
|
|
|
|
*
|
|
|
|
* IO.binread("testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
|
|
|
|
* IO.binread("testfile", 20) #=> "This is line one\nThi"
|
|
|
|
* IO.binread("testfile", 20, 10) #=> "ne one\nThis is line "
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_s_binread(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
VALUE offset;
|
|
|
|
struct foreach_arg arg;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "12", NULL, NULL, &offset);
|
2009-02-08 12:34:46 +03:00
|
|
|
FilePathValue(argv[0]);
|
2008-09-23 14:48:17 +04:00
|
|
|
arg.io = rb_io_open(argv[0], rb_str_new_cstr("rb:ASCII-8BIT"), Qnil, Qnil);
|
|
|
|
if (NIL_P(arg.io)) return Qnil;
|
|
|
|
arg.argv = argv+1;
|
2008-09-24 06:31:12 +04:00
|
|
|
arg.argc = (argc > 1) ? 1 : 0;
|
2008-09-23 14:48:17 +04:00
|
|
|
if (!NIL_P(offset)) {
|
|
|
|
rb_io_seek(arg.io, offset, SEEK_SET);
|
|
|
|
}
|
|
|
|
return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
|
|
|
|
}
|
|
|
|
|
2008-03-30 10:38:05 +04:00
|
|
|
struct copy_stream_struct {
|
|
|
|
VALUE src;
|
|
|
|
VALUE dst;
|
2008-04-19 23:47:16 +04:00
|
|
|
off_t copy_length; /* (off_t)-1 if not specified */
|
|
|
|
off_t src_offset; /* (off_t)-1 if not specified */
|
|
|
|
|
2008-03-30 10:38:05 +04:00
|
|
|
int src_fd;
|
|
|
|
int dst_fd;
|
|
|
|
int close_src;
|
|
|
|
int close_dst;
|
|
|
|
off_t total;
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *syserr;
|
2008-03-30 10:38:05 +04:00
|
|
|
int error_no;
|
2008-05-31 13:28:20 +04:00
|
|
|
const char *notimp;
|
2008-03-30 10:38:05 +04:00
|
|
|
rb_fdset_t fds;
|
2008-09-23 12:17:17 +04:00
|
|
|
VALUE th;
|
2008-03-30 10:38:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2009-01-03 21:34:06 +03:00
|
|
|
maygvl_copy_stream_wait_read(struct copy_stream_struct *stp)
|
2008-03-30 10:38:05 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
rb_fd_zero(&stp->fds);
|
|
|
|
rb_fd_set(stp->src_fd, &stp->fds);
|
|
|
|
ret = rb_fd_select(rb_fd_max(&stp->fds), &stp->fds, NULL, NULL, NULL);
|
|
|
|
if (ret == -1) {
|
|
|
|
stp->syserr = "select";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-01-03 21:34:06 +03:00
|
|
|
nogvl_copy_stream_wait_write(struct copy_stream_struct *stp)
|
2008-03-30 10:38:05 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
rb_fd_zero(&stp->fds);
|
|
|
|
rb_fd_set(stp->dst_fd, &stp->fds);
|
|
|
|
ret = rb_fd_select(rb_fd_max(&stp->fds), NULL, &stp->fds, NULL, NULL);
|
|
|
|
if (ret == -1) {
|
|
|
|
stp->syserr = "select";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_SENDFILE
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#define USE_SENDFILE
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SENDFILE_H
|
|
|
|
#include <sys/sendfile.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
simple_sendfile(int out_fd, int in_fd, off_t *offset, size_t count)
|
|
|
|
{
|
|
|
|
return sendfile(out_fd, in_fd, offset, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SENDFILE
|
|
|
|
static int
|
2009-01-03 21:34:06 +03:00
|
|
|
nogvl_copy_stream_sendfile(struct copy_stream_struct *stp)
|
2008-03-30 10:38:05 +04:00
|
|
|
{
|
|
|
|
struct stat src_stat, dst_stat;
|
|
|
|
ssize_t ss;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
off_t copy_length;
|
|
|
|
off_t src_offset;
|
|
|
|
int use_pread;
|
|
|
|
|
|
|
|
ret = fstat(stp->src_fd, &src_stat);
|
|
|
|
if (ret == -1) {
|
|
|
|
stp->syserr = "fstat";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!S_ISREG(src_stat.st_mode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = fstat(stp->dst_fd, &dst_stat);
|
|
|
|
if (ret == -1) {
|
|
|
|
stp->syserr = "fstat";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((dst_stat.st_mode & S_IFMT) != S_IFSOCK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
src_offset = stp->src_offset;
|
|
|
|
use_pread = src_offset != (off_t)-1;
|
|
|
|
|
|
|
|
copy_length = stp->copy_length;
|
|
|
|
if (copy_length == (off_t)-1) {
|
|
|
|
if (use_pread)
|
|
|
|
copy_length = src_stat.st_size - src_offset;
|
|
|
|
else {
|
|
|
|
off_t cur = lseek(stp->src_fd, 0, SEEK_CUR);
|
|
|
|
if (cur == (off_t)-1) {
|
|
|
|
stp->syserr = "lseek";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
copy_length = src_stat.st_size - cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:09:29 +04:00
|
|
|
retry_sendfile:
|
2008-03-30 10:38:05 +04:00
|
|
|
if (use_pread) {
|
|
|
|
ss = simple_sendfile(stp->dst_fd, stp->src_fd, &src_offset, copy_length);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ss = simple_sendfile(stp->dst_fd, stp->src_fd, NULL, copy_length);
|
|
|
|
}
|
|
|
|
if (0 < ss) {
|
|
|
|
stp->total += ss;
|
|
|
|
copy_length -= ss;
|
|
|
|
if (0 < copy_length) {
|
|
|
|
ss = -1;
|
|
|
|
errno = EAGAIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ss == -1) {
|
2008-08-05 07:44:09 +04:00
|
|
|
switch (errno) {
|
|
|
|
case EINVAL:
|
|
|
|
#ifdef ENOSYS
|
|
|
|
case ENOSYS:
|
|
|
|
#endif
|
2008-03-30 10:38:05 +04:00
|
|
|
return 0;
|
2008-08-05 07:44:09 +04:00
|
|
|
case EAGAIN:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
#endif
|
2009-01-03 21:34:06 +03:00
|
|
|
if (nogvl_copy_stream_wait_write(stp) == -1)
|
2008-03-30 10:38:05 +04:00
|
|
|
return -1;
|
2008-09-23 12:17:17 +04:00
|
|
|
if (rb_thread_interrupted(stp->th))
|
2008-03-30 11:35:09 +04:00
|
|
|
return -1;
|
2008-03-30 10:38:05 +04:00
|
|
|
goto retry_sendfile;
|
|
|
|
}
|
|
|
|
stp->syserr = "sendfile";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static ssize_t
|
2009-04-26 13:46:41 +04:00
|
|
|
maygvl_copy_stream_read(struct copy_stream_struct *stp, char *buf, size_t len, off_t offset)
|
2008-03-30 10:38:05 +04:00
|
|
|
{
|
|
|
|
ssize_t ss;
|
2008-08-26 20:09:29 +04:00
|
|
|
retry_read:
|
2008-03-30 10:38:05 +04:00
|
|
|
if (offset == (off_t)-1)
|
|
|
|
ss = read(stp->src_fd, buf, len);
|
|
|
|
else {
|
|
|
|
#ifdef HAVE_PREAD
|
|
|
|
ss = pread(stp->src_fd, buf, len, offset);
|
|
|
|
#else
|
|
|
|
stp->notimp = "pread";
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (ss == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ss == -1) {
|
2008-08-05 07:44:09 +04:00
|
|
|
switch (errno) {
|
|
|
|
case EAGAIN:
|
|
|
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
|
|
|
case EWOULDBLOCK:
|
|
|
|
#endif
|
2009-01-03 21:34:06 +03:00
|
|
|
if (maygvl_copy_stream_wait_read(stp) == -1)
|
2008-03-30 10:38:05 +04:00
|
|
|
return -1;
|
|
|
|
goto retry_read;
|
2008-08-05 07:44:09 +04:00
|
|
|
#ifdef ENOSYS
|
|
|
|
case ENOSYS:
|
|
|
|
#endif
|
2008-03-30 10:38:05 +04:00
|
|
|
stp->notimp = "pread";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
stp->syserr = offset == (off_t)-1 ? "read" : "pread";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-04-26 13:46:41 +04:00
|
|
|
nogvl_copy_stream_write(struct copy_stream_struct *stp, char *buf, size_t len)
|
2008-03-30 10:38:05 +04:00
|
|
|
{
|
|
|
|
ssize_t ss;
|
|
|
|
int off = 0;
|
|
|
|
while (len) {
|
|
|
|
ss = write(stp->dst_fd, buf+off, len);
|
|
|
|
if (ss == -1) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
2009-01-03 21:34:06 +03:00
|
|
|
if (nogvl_copy_stream_wait_write(stp) == -1)
|
2008-03-30 10:38:05 +04:00
|
|
|
return -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stp->syserr = "write";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
2009-04-26 13:46:41 +04:00
|
|
|
off += (int)ss;
|
|
|
|
len -= (int)ss;
|
2008-03-30 10:38:05 +04:00
|
|
|
stp->total += ss;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-01-03 21:34:06 +03:00
|
|
|
nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
|
2008-03-30 10:38:05 +04:00
|
|
|
{
|
|
|
|
char buf[1024*16];
|
2009-03-12 13:40:33 +03:00
|
|
|
size_t len;
|
2008-03-30 10:38:05 +04:00
|
|
|
ssize_t ss;
|
|
|
|
int ret;
|
|
|
|
off_t copy_length;
|
|
|
|
int use_eof;
|
|
|
|
off_t src_offset;
|
|
|
|
int use_pread;
|
|
|
|
|
|
|
|
copy_length = stp->copy_length;
|
|
|
|
use_eof = copy_length == (off_t)-1;
|
|
|
|
src_offset = stp->src_offset;
|
|
|
|
use_pread = src_offset != (off_t)-1;
|
|
|
|
|
|
|
|
if (use_pread && stp->close_src) {
|
|
|
|
off_t r;
|
|
|
|
r = lseek(stp->src_fd, src_offset, SEEK_SET);
|
|
|
|
if (r == (off_t)-1) {
|
|
|
|
stp->syserr = "lseek";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
src_offset = (off_t)-1;
|
|
|
|
use_pread = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (use_eof || 0 < copy_length) {
|
2009-04-26 13:46:41 +04:00
|
|
|
if (!use_eof && copy_length < (off_t)sizeof(buf)) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 12:16:15 +03:00
|
|
|
len = (size_t)copy_length;
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = sizeof(buf);
|
|
|
|
}
|
|
|
|
if (use_pread) {
|
2009-01-03 21:34:06 +03:00
|
|
|
ss = maygvl_copy_stream_read(stp, buf, len, src_offset);
|
2008-03-30 10:38:05 +04:00
|
|
|
if (0 < ss)
|
|
|
|
src_offset += ss;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-03 21:34:06 +03:00
|
|
|
ss = maygvl_copy_stream_read(stp, buf, len, (off_t)-1);
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
if (ss <= 0) /* EOF or error */
|
|
|
|
return;
|
|
|
|
|
2009-01-03 21:34:06 +03:00
|
|
|
ret = nogvl_copy_stream_write(stp, buf, ss);
|
2008-03-30 10:38:05 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!use_eof)
|
|
|
|
copy_length -= ss;
|
|
|
|
|
2008-09-23 12:17:17 +04:00
|
|
|
if (rb_thread_interrupted(stp->th))
|
2008-03-30 10:38:05 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2009-01-03 21:34:06 +03:00
|
|
|
nogvl_copy_stream_func(void *arg)
|
2008-03-30 10:38:05 +04:00
|
|
|
{
|
|
|
|
struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
|
2008-04-20 10:14:49 +04:00
|
|
|
#ifdef USE_SENDFILE
|
2008-03-30 10:38:05 +04:00
|
|
|
int ret;
|
2008-04-20 10:14:49 +04:00
|
|
|
#endif
|
2008-03-30 10:38:05 +04:00
|
|
|
|
|
|
|
#ifdef USE_SENDFILE
|
2009-01-03 21:34:06 +03:00
|
|
|
ret = nogvl_copy_stream_sendfile(stp);
|
2008-03-30 10:38:05 +04:00
|
|
|
if (ret != 0)
|
|
|
|
goto finish; /* error or success */
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 21:34:06 +03:00
|
|
|
nogvl_copy_stream_read_write(stp);
|
2008-03-30 10:38:05 +04:00
|
|
|
|
2008-04-20 10:14:49 +04:00
|
|
|
#ifdef USE_SENDFILE
|
2008-08-26 20:09:29 +04:00
|
|
|
finish:
|
2008-04-20 10:14:49 +04:00
|
|
|
#endif
|
2008-03-30 10:38:05 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2008-04-19 23:47:16 +04:00
|
|
|
static VALUE
|
|
|
|
copy_stream_fallback_body(VALUE arg)
|
|
|
|
{
|
|
|
|
struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
|
|
|
|
const int buflen = 16*1024;
|
|
|
|
VALUE n;
|
|
|
|
VALUE buf = rb_str_buf_new(buflen);
|
2009-03-11 23:22:52 +03:00
|
|
|
off_t rest = stp->copy_length;
|
2008-04-20 07:51:57 +04:00
|
|
|
off_t off = stp->src_offset;
|
2008-09-05 13:37:55 +04:00
|
|
|
ID read_method = id_readpartial;
|
|
|
|
|
|
|
|
if (stp->src_fd == -1) {
|
|
|
|
if (!rb_respond_to(stp->src, read_method)) {
|
|
|
|
read_method = id_read;
|
|
|
|
}
|
|
|
|
}
|
2008-04-20 07:51:57 +04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
long numwrote;
|
2008-04-20 08:59:04 +04:00
|
|
|
long l;
|
2008-04-20 07:51:57 +04:00
|
|
|
if (stp->copy_length == (off_t)-1) {
|
|
|
|
l = buflen;
|
2008-04-19 23:47:16 +04:00
|
|
|
}
|
2008-04-20 07:51:57 +04:00
|
|
|
else {
|
|
|
|
if (rest == 0)
|
|
|
|
break;
|
2009-03-11 23:22:52 +03:00
|
|
|
l = buflen < rest ? buflen : (long)rest;
|
2008-04-20 07:51:57 +04:00
|
|
|
}
|
|
|
|
if (stp->src_fd == -1) {
|
2008-09-05 13:37:55 +04:00
|
|
|
rb_funcall(stp->src, read_method, 2, INT2FIX(l), buf);
|
2008-04-19 23:47:16 +04:00
|
|
|
}
|
2008-04-20 07:51:57 +04:00
|
|
|
else {
|
|
|
|
ssize_t ss;
|
2008-04-20 10:13:17 +04:00
|
|
|
rb_thread_wait_fd(stp->src_fd);
|
2008-04-20 07:51:57 +04:00
|
|
|
rb_str_resize(buf, buflen);
|
2009-01-03 21:34:06 +03:00
|
|
|
ss = maygvl_copy_stream_read(stp, RSTRING_PTR(buf), l, off);
|
2008-04-20 07:51:57 +04:00
|
|
|
if (ss == -1)
|
|
|
|
return Qnil;
|
|
|
|
if (ss == 0)
|
|
|
|
rb_eof_error();
|
|
|
|
rb_str_resize(buf, ss);
|
|
|
|
if (off != (off_t)-1)
|
|
|
|
off += ss;
|
|
|
|
}
|
2008-04-20 10:13:17 +04:00
|
|
|
n = rb_io_write(stp->dst, buf);
|
|
|
|
numwrote = NUM2LONG(n);
|
|
|
|
stp->total += numwrote;
|
2008-04-20 07:51:57 +04:00
|
|
|
rest -= numwrote;
|
2008-09-05 13:37:55 +04:00
|
|
|
if (read_method == id_read && RSTRING_LEN(buf) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2008-04-19 23:47:16 +04:00
|
|
|
}
|
2008-04-20 07:51:57 +04:00
|
|
|
|
2008-04-19 23:47:16 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
copy_stream_fallback(struct copy_stream_struct *stp)
|
|
|
|
{
|
2008-04-20 07:51:57 +04:00
|
|
|
if (stp->src_fd == -1 && stp->src_offset != (off_t)-1) {
|
2008-04-20 10:13:17 +04:00
|
|
|
rb_raise(rb_eArgError, "cannot specify src_offset for non-IO");
|
2008-04-19 23:47:16 +04:00
|
|
|
}
|
|
|
|
rb_rescue2(copy_stream_fallback_body, (VALUE)stp,
|
|
|
|
(VALUE (*) (ANYARGS))0, (VALUE)0,
|
|
|
|
rb_eEOFError, (VALUE)0);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2008-03-30 10:38:05 +04:00
|
|
|
static VALUE
|
|
|
|
copy_stream_body(VALUE arg)
|
|
|
|
{
|
|
|
|
struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
|
|
|
|
VALUE src_io, dst_io;
|
2008-04-20 08:12:32 +04:00
|
|
|
rb_io_t *src_fptr = 0, *dst_fptr = 0;
|
2008-03-30 10:38:05 +04:00
|
|
|
int src_fd, dst_fd;
|
|
|
|
|
2008-09-23 12:17:17 +04:00
|
|
|
stp->th = rb_thread_current();
|
2008-03-30 10:38:05 +04:00
|
|
|
|
2008-04-19 23:47:16 +04:00
|
|
|
stp->total = 0;
|
|
|
|
|
|
|
|
if (stp->src == argf ||
|
|
|
|
!(TYPE(stp->src) == T_FILE ||
|
|
|
|
TYPE(stp->src) == T_STRING ||
|
2008-04-20 07:51:57 +04:00
|
|
|
rb_respond_to(stp->src, rb_intern("to_path")))) {
|
|
|
|
src_fd = -1;
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-12-31 10:19:24 +03:00
|
|
|
src_io = TYPE(stp->src) == T_FILE ? stp->src : Qnil;
|
2008-04-20 10:13:17 +04:00
|
|
|
if (NIL_P(src_io)) {
|
|
|
|
VALUE args[2];
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags = O_RDONLY;
|
2008-03-31 13:58:41 +04:00
|
|
|
#ifdef O_NOCTTY
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags |= O_NOCTTY;
|
2008-03-31 13:58:41 +04:00
|
|
|
#endif
|
2008-04-20 10:13:17 +04:00
|
|
|
FilePathValue(stp->src);
|
|
|
|
args[0] = stp->src;
|
2008-09-05 15:30:35 +04:00
|
|
|
args[1] = INT2NUM(oflags);
|
2008-04-20 10:13:17 +04:00
|
|
|
src_io = rb_class_new_instance(2, args, rb_cFile);
|
|
|
|
stp->src = src_io;
|
2008-04-20 07:51:57 +04:00
|
|
|
stp->close_src = 1;
|
|
|
|
}
|
2008-04-20 10:13:17 +04:00
|
|
|
GetOpenFile(src_io, src_fptr);
|
2008-04-21 14:09:33 +04:00
|
|
|
rb_io_check_readable(src_fptr);
|
2008-04-20 10:13:17 +04:00
|
|
|
src_fd = src_fptr->fd;
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
stp->src_fd = src_fd;
|
|
|
|
|
2008-04-20 07:51:57 +04:00
|
|
|
if (stp->dst == argf ||
|
|
|
|
!(TYPE(stp->dst) == T_FILE ||
|
|
|
|
TYPE(stp->dst) == T_STRING ||
|
|
|
|
rb_respond_to(stp->dst, rb_intern("to_path")))) {
|
|
|
|
dst_fd = -1;
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-12-31 10:19:24 +03:00
|
|
|
dst_io = TYPE(stp->dst) == T_FILE ? stp->dst : Qnil;
|
2008-04-20 10:13:17 +04:00
|
|
|
if (NIL_P(dst_io)) {
|
|
|
|
VALUE args[3];
|
2008-09-05 15:30:35 +04:00
|
|
|
int oflags = O_WRONLY|O_CREAT|O_TRUNC;
|
2008-03-31 13:58:41 +04:00
|
|
|
#ifdef O_NOCTTY
|
2008-09-05 15:30:35 +04:00
|
|
|
oflags |= O_NOCTTY;
|
2008-03-31 13:58:41 +04:00
|
|
|
#endif
|
2008-04-20 10:13:17 +04:00
|
|
|
FilePathValue(stp->dst);
|
|
|
|
args[0] = stp->dst;
|
2008-09-05 15:30:35 +04:00
|
|
|
args[1] = INT2NUM(oflags);
|
2008-04-20 10:13:17 +04:00
|
|
|
args[2] = INT2FIX(0600);
|
|
|
|
dst_io = rb_class_new_instance(3, args, rb_cFile);
|
|
|
|
stp->dst = dst_io;
|
2008-04-20 07:51:57 +04:00
|
|
|
stp->close_dst = 1;
|
|
|
|
}
|
2008-04-20 10:13:17 +04:00
|
|
|
else {
|
|
|
|
dst_io = GetWriteIO(dst_io);
|
|
|
|
stp->dst = dst_io;
|
|
|
|
}
|
|
|
|
GetOpenFile(dst_io, dst_fptr);
|
2008-04-21 14:09:33 +04:00
|
|
|
rb_io_check_writable(dst_fptr);
|
2008-04-20 10:13:17 +04:00
|
|
|
dst_fd = dst_fptr->fd;
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
stp->dst_fd = dst_fd;
|
|
|
|
|
2008-04-20 10:13:17 +04:00
|
|
|
if (stp->src_offset == (off_t)-1 && src_fptr && src_fptr->rbuf_len) {
|
2009-03-12 13:40:33 +03:00
|
|
|
size_t len = src_fptr->rbuf_len;
|
2008-03-30 10:38:05 +04:00
|
|
|
VALUE str;
|
2009-04-26 13:46:41 +04:00
|
|
|
if (stp->copy_length != (off_t)-1 && stp->copy_length < (off_t)len) {
|
* array.c, bignum.c, dln.c, error.c, gc.c, io.c, marshal.c,
numeric.c, pack.c, strftime.c, string.c, thread.c, transcode.c,
transcode_data.h, util.c, variable.c, vm_dump.c,
include/ruby/encoding.h, missing/crypt.c, missing/vsnprintf.c:
suppress VC type warnings. [ruby-core:22726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-03-12 12:16:15 +03:00
|
|
|
len = (size_t)stp->copy_length;
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
str = rb_str_buf_new(len);
|
|
|
|
rb_str_resize(str,len);
|
|
|
|
read_buffered_data(RSTRING_PTR(str), len, src_fptr);
|
2008-12-25 10:25:06 +03:00
|
|
|
if (dst_fptr) { /* IO or filename */
|
|
|
|
if (io_binwrite(str, dst_fptr, 0) < 0)
|
|
|
|
rb_sys_fail(0);
|
|
|
|
}
|
2008-04-20 10:13:17 +04:00
|
|
|
else /* others such as StringIO */
|
|
|
|
rb_io_write(stp->dst, str);
|
2008-03-30 10:38:05 +04:00
|
|
|
stp->total += len;
|
|
|
|
if (stp->copy_length != (off_t)-1)
|
|
|
|
stp->copy_length -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst_fptr && io_fflush(dst_fptr) < 0) {
|
|
|
|
rb_raise(rb_eIOError, "flush failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stp->copy_length == 0)
|
|
|
|
return Qnil;
|
|
|
|
|
2008-04-20 10:13:17 +04:00
|
|
|
if (src_fd == -1 || dst_fd == -1) {
|
|
|
|
return copy_stream_fallback(stp);
|
|
|
|
}
|
|
|
|
|
2008-03-30 10:38:05 +04:00
|
|
|
rb_fd_init(&stp->fds);
|
|
|
|
rb_fd_set(src_fd, &stp->fds);
|
|
|
|
rb_fd_set(dst_fd, &stp->fds);
|
|
|
|
|
2009-01-03 21:34:06 +03:00
|
|
|
return rb_thread_blocking_region(nogvl_copy_stream_func, (void*)stp, RUBY_UBF_IO, 0);
|
2008-03-30 10:38:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
copy_stream_finalize(VALUE arg)
|
|
|
|
{
|
|
|
|
struct copy_stream_struct *stp = (struct copy_stream_struct *)arg;
|
2008-04-20 10:13:17 +04:00
|
|
|
if (stp->close_src) {
|
|
|
|
rb_io_close_m(stp->src);
|
|
|
|
}
|
|
|
|
if (stp->close_dst) {
|
|
|
|
rb_io_close_m(stp->dst);
|
|
|
|
}
|
2008-03-30 10:38:05 +04:00
|
|
|
rb_fd_term(&stp->fds);
|
|
|
|
if (stp->syserr) {
|
|
|
|
errno = stp->error_no;
|
|
|
|
rb_sys_fail(stp->syserr);
|
|
|
|
}
|
|
|
|
if (stp->notimp) {
|
|
|
|
rb_raise(rb_eNotImpError, "%s() not implemented", stp->notimp);
|
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.copy_stream(src, dst)
|
|
|
|
* IO.copy_stream(src, dst, copy_length)
|
|
|
|
* IO.copy_stream(src, dst, copy_length, src_offset)
|
|
|
|
*
|
|
|
|
* IO.copy_stream copies <i>src</i> to <i>dst</i>.
|
|
|
|
* <i>src</i> and <i>dst</i> is either a filename or an IO.
|
|
|
|
*
|
|
|
|
* This method returns the number of bytes copied.
|
|
|
|
*
|
|
|
|
* If optional arguments are not given,
|
|
|
|
* the start position of the copy is
|
|
|
|
* the beginning of the filename or
|
|
|
|
* the current file offset of the IO.
|
|
|
|
* The end position of the copy is the end of file.
|
|
|
|
*
|
|
|
|
* If <i>copy_length</i> is given,
|
|
|
|
* No more than <i>copy_length</i> bytes are copied.
|
|
|
|
*
|
|
|
|
* If <i>src_offset</i> is given,
|
|
|
|
* it specifies the start position of the copy.
|
|
|
|
*
|
|
|
|
* When <i>src_offset</i> is specified and
|
|
|
|
* <i>src</i> is an IO,
|
|
|
|
* IO.copy_stream doesn't move the current file offset.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static VALUE
|
|
|
|
rb_io_s_copy_stream(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
VALUE src, dst, length, src_offset;
|
|
|
|
struct copy_stream_struct st;
|
|
|
|
|
|
|
|
MEMZERO(&st, struct copy_stream_struct, 1);
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "22", &src, &dst, &length, &src_offset);
|
|
|
|
|
2008-04-19 23:47:16 +04:00
|
|
|
st.src = src;
|
|
|
|
st.dst = dst;
|
|
|
|
|
2008-03-30 10:38:05 +04:00
|
|
|
if (NIL_P(length))
|
|
|
|
st.copy_length = (off_t)-1;
|
|
|
|
else
|
|
|
|
st.copy_length = NUM2OFFT(length);
|
|
|
|
|
|
|
|
if (NIL_P(src_offset))
|
|
|
|
st.src_offset = (off_t)-1;
|
|
|
|
else
|
|
|
|
st.src_offset = NUM2OFFT(src_offset);
|
|
|
|
|
|
|
|
rb_ensure(copy_stream_body, (VALUE)&st, copy_stream_finalize, (VALUE)&st);
|
|
|
|
|
|
|
|
return OFFT2NUM(st.total);
|
|
|
|
}
|
2007-12-21 07:26:38 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2007-12-22 00:10:55 +03:00
|
|
|
* io.external_encoding => encoding
|
2007-12-21 07:26:38 +03:00
|
|
|
*
|
|
|
|
* Returns the Encoding object that represents the encoding of the file.
|
2007-12-25 09:44:58 +03:00
|
|
|
* If io is write mode and no encoding is specified, returns <code>nil</code>.
|
2007-12-21 07:26:38 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_external_encoding(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
2008-08-24 11:49:13 +04:00
|
|
|
if (fptr->encs.enc2) {
|
|
|
|
return rb_enc_from_encoding(fptr->encs.enc2);
|
2007-12-23 20:38:32 +03:00
|
|
|
}
|
2007-12-25 09:44:58 +03:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
2008-08-24 11:49:13 +04:00
|
|
|
if (fptr->encs.enc)
|
|
|
|
return rb_enc_from_encoding(fptr->encs.enc);
|
2007-12-25 09:44:58 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
2007-12-23 21:01:16 +03:00
|
|
|
return rb_enc_from_encoding(io_read_encoding(fptr));
|
2007-12-21 07:26:38 +03:00
|
|
|
}
|
|
|
|
|
2007-12-23 18:56:41 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* io.internal_encoding => encoding
|
|
|
|
*
|
|
|
|
* Returns the Encoding of the internal string if conversion is
|
|
|
|
* specified. Otherwise returns nil.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_internal_encoding(VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
2008-08-24 11:49:13 +04:00
|
|
|
if (!fptr->encs.enc2) return Qnil;
|
2007-12-23 21:01:16 +03:00
|
|
|
return rb_enc_from_encoding(io_read_encoding(fptr));
|
2007-12-23 18:56:41 +03:00
|
|
|
}
|
|
|
|
|
2007-12-24 21:17:35 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-08-24 14:32:59 +04:00
|
|
|
* io.set_encoding(ext_enc) => io
|
|
|
|
* io.set_encoding("ext_enc:int_enc") => io
|
|
|
|
* io.set_encoding(ext_enc, int_enc) => io
|
|
|
|
* io.set_encoding("ext_enc:int_enc", opt) => io
|
|
|
|
* io.set_encoding(ext_enc, int_enc, opt) => io
|
2007-12-24 21:17:35 +03:00
|
|
|
*
|
2008-01-05 06:35:13 +03:00
|
|
|
* If single argument is specified, read string from io is tagged
|
|
|
|
* with the encoding specified. If encoding is a colon separated two
|
2007-12-24 21:17:35 +03:00
|
|
|
* encoding names "A:B", the read string is converted from encoding A
|
|
|
|
* (external encoding) to encoding B (internal encoding), then tagged
|
|
|
|
* with B. If two arguments are specified, those must be encoding
|
2008-01-05 06:35:13 +03:00
|
|
|
* objects or encoding names, and the first one is the external encoding, and the
|
2007-12-24 21:17:35 +03:00
|
|
|
* second one is the internal encoding.
|
2008-08-24 14:32:59 +04:00
|
|
|
* If the external encoding and the internal encoding is specified,
|
|
|
|
* optional hash argument specify the conversion option.
|
2007-12-24 21:17:35 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_set_encoding(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
2008-08-24 13:40:31 +04:00
|
|
|
VALUE v1, v2, opt;
|
2007-12-24 21:17:35 +03:00
|
|
|
|
2008-10-21 17:57:16 +04:00
|
|
|
opt = pop_last_hash(&argc, argv);
|
2007-12-24 21:17:35 +03:00
|
|
|
rb_scan_args(argc, argv, "11", &v1, &v2);
|
|
|
|
GetOpenFile(io, fptr);
|
2008-09-13 14:28:06 +04:00
|
|
|
io_encoding_set(fptr, v1, v2, opt);
|
2007-12-24 21:17:35 +03:00
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2007-12-22 19:21:09 +03:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_external_encoding(VALUE argf)
|
2007-12-22 19:21:09 +03:00
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
if (!RTEST(ARGF.current_file)) {
|
2008-05-29 17:30:09 +04:00
|
|
|
return rb_enc_from_encoding(rb_default_external_encoding());
|
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_external_encoding(rb_io_check_io(ARGF.current_file));
|
2007-12-23 18:56:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_internal_encoding(VALUE argf)
|
2007-12-23 18:56:41 +03:00
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
if (!RTEST(ARGF.current_file)) {
|
2008-05-29 17:30:09 +04:00
|
|
|
return rb_enc_from_encoding(rb_default_external_encoding());
|
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_internal_encoding(rb_io_check_io(ARGF.current_file));
|
2007-12-22 19:21:09 +03:00
|
|
|
}
|
2007-12-21 07:26:38 +03:00
|
|
|
|
2007-12-24 21:17:35 +03:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_set_encoding(int argc, VALUE *argv, VALUE argf)
|
2007-12-24 21:17:35 +03:00
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
|
2008-02-21 08:49:42 +03:00
|
|
|
if (!next_argv()) {
|
2008-02-21 08:47:12 +03:00
|
|
|
rb_raise(rb_eArgError, "no stream to set encoding");
|
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
rb_io_set_encoding(argc, argv, ARGF.current_file);
|
|
|
|
GetOpenFile(ARGF.current_file, fptr);
|
2008-09-04 05:33:47 +04:00
|
|
|
ARGF.encs = fptr->encs;
|
2008-03-01 11:59:04 +03:00
|
|
|
return argf;
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_tell(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
if (!next_argv()) {
|
|
|
|
rb_raise(rb_eArgError, "no stream to tell");
|
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(0, 0);
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_tell(ARGF.current_file);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_seek_m(int argc, VALUE *argv, VALUE argf)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
if (!next_argv()) {
|
|
|
|
rb_raise(rb_eArgError, "no stream to seek");
|
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(argc, argv);
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_seek_m(argc, argv, ARGF.current_file);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_set_pos(VALUE argf, VALUE offset)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
if (!next_argv()) {
|
2001-01-18 11:43:14 +03:00
|
|
|
rb_raise(rb_eArgError, "no stream to set position");
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(1, &offset);
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_set_pos(ARGF.current_file, offset);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_rewind(VALUE argf)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
if (!next_argv()) {
|
|
|
|
rb_raise(rb_eArgError, "no stream to rewind");
|
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(0, 0);
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_rewind(ARGF.current_file);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_fileno(VALUE argf)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
if (!next_argv()) {
|
|
|
|
rb_raise(rb_eArgError, "no stream");
|
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(0, 0);
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_fileno(ARGF.current_file);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_to_io(VALUE argf)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2003-02-18 17:30:17 +03:00
|
|
|
next_argv();
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(0, 0);
|
2008-09-04 07:33:27 +04:00
|
|
|
return ARGF.current_file;
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2003-12-23 22:53:45 +03:00
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_eof(VALUE argf)
|
2003-12-23 22:53:45 +03:00
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.current_file) {
|
|
|
|
if (ARGF.init_p == 0) return Qtrue;
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(0, 0);
|
2008-09-04 07:33:27 +04:00
|
|
|
if (rb_io_eof(ARGF.current_file)) {
|
2003-12-23 22:53:45 +03:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_read(int argc, VALUE *argv, VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-12-30 22:29:56 +03:00
|
|
|
VALUE tmp, str, length;
|
2002-08-21 19:47:54 +04:00
|
|
|
long len = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-01-06 05:53:34 +03:00
|
|
|
rb_scan_args(argc, argv, "02", &length, &str);
|
2003-12-30 22:29:56 +03:00
|
|
|
if (!NIL_P(length)) {
|
2003-12-26 20:05:20 +03:00
|
|
|
len = NUM2LONG(argv[0]);
|
2003-12-30 22:29:56 +03:00
|
|
|
}
|
|
|
|
if (!NIL_P(str)) {
|
|
|
|
StringValue(str);
|
|
|
|
rb_str_resize(str,0);
|
|
|
|
argv[1] = Qnil;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
retry:
|
2003-12-26 20:05:20 +03:00
|
|
|
if (!next_argv()) {
|
|
|
|
return str;
|
|
|
|
}
|
2008-03-01 11:59:04 +03:00
|
|
|
if (ARGF_GENERIC_INPUT_P()) {
|
|
|
|
tmp = argf_forward(argc, argv, argf);
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
tmp = io_read(argc, argv, ARGF.current_file);
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
}
|
2003-12-23 22:53:45 +03:00
|
|
|
if (NIL_P(str)) str = tmp;
|
2004-01-15 07:03:15 +03:00
|
|
|
else if (!NIL_P(tmp)) rb_str_append(str, tmp);
|
2004-01-02 19:21:26 +03:00
|
|
|
if (NIL_P(tmp) || NIL_P(length)) {
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.next_p != -1) {
|
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
2003-12-03 20:30:09 +03:00
|
|
|
goto retry;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2003-12-30 22:29:56 +03:00
|
|
|
else if (argc >= 1) {
|
2006-08-31 14:47:44 +04:00
|
|
|
if (RSTRING_LEN(str) < len) {
|
|
|
|
len -= RSTRING_LEN(str);
|
2003-12-03 20:30:09 +03:00
|
|
|
argv[0] = INT2NUM(len);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2007-08-16 01:29:10 +04:00
|
|
|
struct argf_call_arg {
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
2008-03-01 11:59:04 +03:00
|
|
|
VALUE argf;
|
2007-08-16 01:29:10 +04:00
|
|
|
};
|
|
|
|
|
2005-01-01 14:25:43 +03:00
|
|
|
static VALUE
|
2007-08-16 01:29:10 +04:00
|
|
|
argf_forward_call(VALUE arg)
|
2005-01-01 14:25:43 +03:00
|
|
|
{
|
2007-08-16 01:29:10 +04:00
|
|
|
struct argf_call_arg *p = (struct argf_call_arg *)arg;
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_forward(p->argc, p->argv, p->argf);
|
2005-01-01 14:25:43 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_readpartial(int argc, VALUE *argv, VALUE argf)
|
2005-01-01 14:25:43 +03:00
|
|
|
{
|
|
|
|
VALUE tmp, str, length;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &length, &str);
|
|
|
|
if (!NIL_P(str)) {
|
|
|
|
StringValue(str);
|
|
|
|
argv[1] = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!next_argv()) {
|
|
|
|
rb_str_resize(str, 0);
|
|
|
|
rb_eof_error();
|
|
|
|
}
|
2008-03-01 11:59:04 +03:00
|
|
|
if (ARGF_GENERIC_INPUT_P()) {
|
2007-08-16 01:29:10 +04:00
|
|
|
struct argf_call_arg arg;
|
|
|
|
arg.argc = argc;
|
|
|
|
arg.argv = argv;
|
2008-03-01 11:59:04 +03:00
|
|
|
arg.argf = argf;
|
2007-08-16 01:29:10 +04:00
|
|
|
tmp = rb_rescue2(argf_forward_call, (VALUE)&arg,
|
|
|
|
RUBY_METHOD_FUNC(0), Qnil, rb_eEOFError, (VALUE)0);
|
2005-01-01 14:25:43 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
tmp = io_getpartial(argc, argv, ARGF.current_file, 0);
|
2005-01-01 14:25:43 +03:00
|
|
|
}
|
|
|
|
if (NIL_P(tmp)) {
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.next_p == -1) {
|
2005-01-01 14:25:43 +03:00
|
|
|
rb_eof_error();
|
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
|
|
|
if (RARRAY_LEN(ARGF.argv) == 0)
|
2005-01-01 14:25:43 +03:00
|
|
|
rb_eof_error();
|
|
|
|
if (NIL_P(str))
|
|
|
|
str = rb_str_new(NULL, 0);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_getc(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
VALUE ch;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
retry:
|
|
|
|
if (!next_argv()) return Qnil;
|
2008-03-01 11:59:04 +03:00
|
|
|
if (ARGF_GENERIC_INPUT_P()) {
|
2008-09-04 07:33:27 +04:00
|
|
|
ch = rb_funcall3(ARGF.current_file, rb_intern("getc"), 0, 0);
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
ch = rb_io_getc(ARGF.current_file);
|
* 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-25 07:29:39 +04:00
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
if (NIL_P(ch) && ARGF.next_p != -1) {
|
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
* 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-25 07:29:39 +04:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_getbyte(VALUE argf)
|
* 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-25 07:29:39 +04:00
|
|
|
{
|
|
|
|
VALUE ch;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
if (!next_argv()) return Qnil;
|
2008-09-04 07:33:27 +04:00
|
|
|
if (TYPE(ARGF.current_file) != T_FILE) {
|
|
|
|
ch = rb_funcall3(ARGF.current_file, rb_intern("getbyte"), 0, 0);
|
* 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-25 07:29:39 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
ch = rb_io_getbyte(ARGF.current_file);
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
if (NIL_P(ch) && ARGF.next_p != -1) {
|
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
* sprintf.c (rb_str_format): allow %c to print one character
string (e.g. ?x).
* lib/tempfile.rb (Tempfile::make_tmpname): put dot between
basename and pid. [ruby-talk:196272]
* parse.y (do_block): remove -> style block.
* parse.y (parser_yylex): remove tLAMBDA_ARG.
* eval.c (rb_call0): binding for the return event hook should have
consistent scope. [ruby-core:07928]
* eval.c (proc_invoke): return behavior should depend whether it
is surrounded by a lambda or a mere block.
* eval.c (formal_assign): handles post splat arguments.
* eval.c (rb_call0): ditto.
* st.c (strhash): use FNV-1a hash.
* parse.y (parser_yylex): removed experimental ';;' terminator.
* eval.c (rb_node_arity): should be aware of post splat arguments.
* eval.c (rb_proc_arity): ditto.
* parse.y (f_args): syntax rule enhanced to support arguments
after the splat.
* parse.y (block_param): ditto for block parameters.
* parse.y (f_post_arg): mandatory formal arguments after the splat
argument.
* parse.y (new_args_gen): generate nodes for mandatory formal
arguments after the splat argument.
* eval.c (rb_eval): dispatch mandatory formal arguments after the
splat argument.
* parse.y (args): allow more than one splat in the argument list.
* parse.y (method_call): allow aref [] to accept all kind of
method argument, including assocs, splat, and block argument.
* eval.c (SETUP_ARGS0): prepare block argument as well.
* lib/mathn.rb (Integer): remove Integer#gcd2. [ruby-core:07931]
* eval.c (error_line): print receivers true/false/nil specially.
* eval.c (rb_proc_yield): handles parameters in yield semantics.
* eval.c (nil_yield): gives LocalJumpError to denote no block
error.
* io.c (rb_io_getc): now takes one-character string.
* string.c (rb_str_hash): use FNV-1a hash from Fowler/Noll/Vo
hashing algorithm.
* string.c (rb_str_aref): str[0] now returns 1 character string,
instead of a fixnum. [Ruby2]
* parse.y (parser_yylex): ?c now returns 1 character string,
instead of a fixnum. [Ruby2]
* string.c (rb_str_aset): no longer support fixnum insertion.
* eval.c (umethod_bind): should not update original class.
[ruby-dev:28636]
* eval.c (ev_const_get): should support constant access from
within instance_eval(). [ruby-dev:28327]
* time.c (time_timeval): should round for usec floating
number. [ruby-core:07896]
* time.c (time_add): ditto.
* dir.c (sys_warning): should not call a vararg function
rb_sys_warning() indirectly. [ruby-core:07886]
* numeric.c (flo_divmod): the first element of Float#divmod should
be an integer. [ruby-dev:28589]
* test/ruby/test_float.rb: add tests for divmod, div, modulo and remainder.
* re.c (rb_reg_initialize): should not allow modifying literal
regexps. frozen check moved from rb_reg_initialize_m as well.
* re.c (rb_reg_initialize): should not modify untainted objects in
safe levels higher than 3.
* re.c (rb_memcmp): type change from char* to const void*.
* dir.c (dir_close): should not close untainted dir stream.
* dir.c (GetDIR): add tainted/frozen check for each dir operation.
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser::parse_symbol_arg):
typo fixed. a patch from Florian Gross <florg at florg.net>.
* eval.c (EXEC_EVENT_HOOK): trace_func may remove itself from
event_hooks. no guarantee for arbitrary hook deletion.
[ruby-dev:28632]
* util.c (ruby_strtod): differ addition to minimize error.
[ruby-dev:28619]
* util.c (ruby_strtod): should not raise ERANGE when the input
string does not have any digits. [ruby-dev:28629]
* eval.c (proc_invoke): should restore old ruby_frame->block.
thanks to ts <decoux at moulon.inra.fr>. [ruby-core:07833]
also fix [ruby-dev:28614] as well.
* signal.c (trap): sig should be less then NSIG. Coverity found
this bug. a patch from Kevin Tew <tewk at tewk.com>.
[ruby-core:07823]
* math.c (math_log2): add new method inspired by
[ruby-talk:191237].
* math.c (math_log): add optional base argument to Math::log().
[ruby-talk:191308]
* ext/syck/emitter.c (syck_scan_scalar): avoid accessing
uninitialized array element. a patch from Pat Eyler
<rubypate at gmail.com>. [ruby-core:07809]
* array.c (rb_ary_fill): initialize local variables first. a
patch from Pat Eyler <rubypate at gmail.com>. [ruby-core:07810]
* ext/syck/yaml2byte.c (syck_yaml2byte_handler): need to free
type_tag. a patch from Pat Eyler <rubypate at gmail.com>.
[ruby-core:07808]
* ext/socket/socket.c (make_hostent_internal): accept ai_family
check from Sam Roberts <sroberts at uniserve.com>.
[ruby-core:07691]
* util.c (ruby_strtod): should not cut off 18 digits for no
reason. [ruby-core:07796]
* array.c (rb_ary_fill): internalize local variable "beg" to
pacify Coverity. [ruby-core:07770]
* pack.c (pack_unpack): now supports CRLF newlines. a patch from
<tommy at tmtm.org>. [ruby-dev:28601]
* applied code clean-up patch from Stefan Huehner
<stefan at huehner.org>. [ruby-core:07764]
* lib/jcode.rb (String::tr_s): should have translated non
squeezing character sequence (i.e. a character) as well. thanks
to Hiroshi Ichikawa <gimite at gimite.ddo.jp> [ruby-list:42090]
* ext/socket/socket.c: document update patch from Sam Roberts
<sroberts at uniserve.com>. [ruby-core:07701]
* lib/mathn.rb (Integer): need not to remove gcd2. a patch from
NARUSE, Yui <naruse at airemix.com>. [ruby-dev:28570]
* parse.y (arg): too much NEW_LIST()
* eval.c (SETUP_ARGS0): remove unnecessary access to nd_alen.
* eval.c (rb_eval): use ARGSCAT for NODE_OP_ASGN1.
[ruby-dev:28585]
* parse.y (arg): use NODE_ARGSCAT for placeholder.
* lib/getoptlong.rb (GetoptLong::get): RDoc update patch from
mathew <meta at pobox.com>. [ruby-core:07738]
* variable.c (rb_const_set): raise error when no target klass is
supplied. [ruby-dev:28582]
* prec.c (prec_prec_f): documentation patch from
<gerardo.santana at gmail.com>. [ruby-core:07689]
* bignum.c (rb_big_pow): second operand may be too big even if
it's a Fixnum. [ruby-talk:187984]
* README.EXT: update symbol description. [ruby-talk:188104]
* COPYING: explicitly note GPLv2. [ruby-talk:187922]
* parse.y: remove some obsolete syntax rules (unparenthesized
method calls in argument list).
* eval.c (rb_call0): insecure calling should be checked for non
NODE_SCOPE method invocations too.
* eval.c (rb_alias): should preserve the current safe level as
well as method definition.
* process.c (rb_f_sleep): remove RDoc description about SIGALRM
which is not valid on the current implementation. [ruby-dev:28464]
Thu Mar 23 21:40:47 2006 K.Kosako <sndgk393 AT ybb.ne.jp>
* eval.c (method_missing): should support argument splat in
super. a bug in combination of super, splat and
method_missing. [ruby-talk:185438]
* configure.in: Solaris SunPro compiler -rapth patch from
<kuwa at labs.fujitsu.com>. [ruby-dev:28443]
* configure.in: remove enable_rpath=no for Solaris.
[ruby-dev:28440]
* ext/win32ole/win32ole.c (ole_val2olevariantdata): change behavior
of converting OLE Variant object with VT_ARRAY|VT_UI1 and Ruby
String object.
* ruby.1: a clarification patch from David Lutterkort
<dlutter at redhat.com>. [ruby-core:7508]
* lib/rdoc/ri/ri_paths.rb (RI::Paths): adding paths from rubygems
directories. a patch from Eric Hodel <drbrain at segment7.net>.
[ruby-core:07423]
* eval.c (rb_clear_cache_by_class): clearing wrong cache.
* ext/extmk.rb: use :remove_destination to install extension libraries
to avoid SEGV. [ruby-dev:28417]
* eval.c (rb_thread_fd_writable): should not re-schedule output
from KILLED thread (must be error printing).
* array.c (rb_ary_flatten_bang): allow specifying recursion
level. [ruby-talk:182170]
* array.c (rb_ary_flatten): ditto.
* gc.c (add_heap): a heap_slots may overflow. a patch from Stefan
Weil <weil at mail.berlios.de>.
* eval.c (rb_call): use separate cache for fcall/vcall
invocation.
* eval.c (rb_eval): NODE_FCALL, NODE_VCALL can call local
functions.
* eval.c (rb_mod_local): a new method to specify newly added
visibility "local".
* eval.c (search_method): search for local methods which are
visible only from the current class.
* class.c (rb_class_local_methods): a method to list local methods.
* object.c (Init_Object): add BasicObject class as a top level
BlankSlate class.
* ruby.h (SYM2ID): should not cast to signed long.
[ruby-core:07414]
* class.c (rb_include_module): allow module duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-06-10 01:20:17 +04:00
|
|
|
return ch;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_readchar(VALUE argf)
|
* 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-25 07:29:39 +04:00
|
|
|
{
|
|
|
|
VALUE ch;
|
|
|
|
|
|
|
|
retry:
|
2008-05-29 17:44:29 +04:00
|
|
|
if (!next_argv()) rb_eof_error();
|
2008-09-04 07:33:27 +04:00
|
|
|
if (TYPE(ARGF.current_file) != T_FILE) {
|
|
|
|
ch = rb_funcall3(ARGF.current_file, rb_intern("getc"), 0, 0);
|
* 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-25 07:29:39 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-04 07:33:27 +04:00
|
|
|
ch = rb_io_getc(ARGF.current_file);
|
* 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-25 07:29:39 +04:00
|
|
|
}
|
2008-09-04 07:33:27 +04:00
|
|
|
if (NIL_P(ch) && ARGF.next_p != -1) {
|
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
* 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-25 07:29:39 +04:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_readbyte(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
VALUE c;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
NEXT_ARGF_FORWARD(0, 0);
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
c = argf_getbyte(argf);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (NIL_P(c)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_eof_error();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
argf_each_line(int argc, VALUE *argv, VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* io.c (argf_tell, argf_seek_m, argf_set_pos, argf_rewind,
argf_fileno, argf_to_io, argf_eofl, argf_getc, argf_getbyte,
argf_readchar, argf_readbyte, argf_each_line): use receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-19 18:14:01 +03:00
|
|
|
RETURN_ENUMERATOR(argf, argc, argv);
|
2007-08-14 15:03:29 +04:00
|
|
|
for (;;) {
|
2009-06-15 13:54:36 +04:00
|
|
|
if (!next_argv()) return argf;
|
2008-09-04 07:33:27 +04:00
|
|
|
rb_block_call(ARGF.current_file, rb_intern("each_line"), argc, argv, rb_yield, 0);
|
|
|
|
ARGF.next_p = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_each_byte(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-03-01 11:59:04 +03:00
|
|
|
RETURN_ENUMERATOR(argf, 0, 0);
|
2007-08-14 15:03:29 +04:00
|
|
|
for (;;) {
|
2009-06-15 13:54:36 +04:00
|
|
|
if (!next_argv()) return argf;
|
2008-09-04 07:33:27 +04:00
|
|
|
rb_block_call(ARGF.current_file, rb_intern("each_byte"), 0, 0, rb_yield, 0);
|
|
|
|
ARGF.next_p = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-30 19:00:12 +04:00
|
|
|
static VALUE
|
|
|
|
argf_each_char(VALUE argf)
|
|
|
|
{
|
|
|
|
RETURN_ENUMERATOR(argf, 0, 0);
|
|
|
|
for (;;) {
|
2009-06-15 13:54:36 +04:00
|
|
|
if (!next_argv()) return argf;
|
2008-09-04 07:33:27 +04:00
|
|
|
rb_block_call(ARGF.current_file, rb_intern("each_char"), 0, 0, rb_yield, 0);
|
|
|
|
ARGF.next_p = 1;
|
2008-03-30 19:00:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_filename(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-03-28 12:17:54 +03:00
|
|
|
next_argv();
|
2008-09-04 07:33:27 +04:00
|
|
|
return ARGF.filename;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_filename_getter(ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
return argf_filename(*var);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_file(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-03-28 12:17:54 +03:00
|
|
|
next_argv();
|
2008-09-04 07:33:27 +04:00
|
|
|
return ARGF.current_file;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-03-28 12:17:54 +03:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_binmode_m(VALUE argf)
|
2002-03-28 12:17:54 +03:00
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.binmode = 1;
|
2002-03-28 12:17:54 +03:00
|
|
|
next_argv();
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(0, 0);
|
2009-06-25 13:01:45 +04:00
|
|
|
rb_io_ascii8bit_binmode(ARGF.current_file);
|
|
|
|
|
2002-03-28 12:17:54 +03:00
|
|
|
return argf;
|
|
|
|
}
|
|
|
|
|
2008-06-21 19:08:57 +04:00
|
|
|
static VALUE
|
|
|
|
argf_binmode_p(VALUE argf)
|
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
return ARGF.binmode ? Qtrue : Qfalse;
|
2008-06-21 19:08:57 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_skip(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2009-06-16 05:14:28 +04:00
|
|
|
if (ARGF.init_p && ARGF.next_p == 0) {
|
2008-09-04 07:33:27 +04:00
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
ARGF.next_p = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
return argf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_close_m(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
next_argv();
|
2008-09-04 07:33:27 +04:00
|
|
|
argf_close(ARGF.current_file);
|
|
|
|
if (ARGF.next_p != -1) {
|
|
|
|
ARGF.next_p = 1;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2009-06-26 22:10:12 +04:00
|
|
|
ARGF.lineno = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
return argf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_closed(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
next_argv();
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
ARGF_FORWARD(0, 0);
|
2008-09-04 07:33:27 +04:00
|
|
|
return rb_io_closed(ARGF.current_file);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_to_s(VALUE argf)
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
{
|
|
|
|
return rb_str_new2("ARGF");
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static VALUE
|
2008-03-01 11:59:04 +03:00
|
|
|
argf_inplace_mode_get(VALUE argf)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
if (!ARGF.inplace) return Qnil;
|
|
|
|
return rb_str_new2(ARGF.inplace);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
static VALUE
|
|
|
|
opt_i_get(ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
return argf_inplace_mode_get(*var);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_inplace_mode_set(VALUE argf, VALUE val)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2001-06-22 13:12:24 +04:00
|
|
|
if (!RTEST(val)) {
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.inplace) free(ARGF.inplace);
|
|
|
|
ARGF.inplace = 0;
|
2001-06-22 13:12:24 +04:00
|
|
|
}
|
2008-03-01 11:59:04 +03:00
|
|
|
else {
|
|
|
|
StringValue(val);
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.inplace) free(ARGF.inplace);
|
|
|
|
ARGF.inplace = 0;
|
|
|
|
ARGF.inplace = strdup(RSTRING_PTR(val));
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
return argf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
opt_i_set(VALUE val, ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
argf_inplace_mode_set(*var, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ruby_get_inplace_mode(void)
|
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
return ARGF.inplace;
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_set_inplace_mode(const char *suffix)
|
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
if (ARGF.inplace) free(ARGF.inplace);
|
|
|
|
ARGF.inplace = 0;
|
|
|
|
if (suffix) ARGF.inplace = strdup(suffix);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
static VALUE
|
|
|
|
argf_argv(VALUE argf)
|
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
return ARGF.argv;
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_argv_getter(ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
return argf_argv(*var);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_get_argv(void)
|
|
|
|
{
|
2008-09-04 07:33:27 +04:00
|
|
|
return ARGF.argv;
|
2008-03-01 11:59:04 +03:00
|
|
|
}
|
|
|
|
|
2003-12-24 07:24:29 +03:00
|
|
|
/*
|
|
|
|
* Class <code>IO</code> is the basis for all input and output in Ruby.
|
|
|
|
* An I/O stream may be <em>duplexed</em> (that is, bidirectional), and
|
|
|
|
* so may use more than one native operating system stream.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* Many of the examples in this section use class <code>File</code>,
|
|
|
|
* the only standard subclass of <code>IO</code>. The two classes are
|
|
|
|
* closely associated.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* As used in this section, <em>portname</em> may take any of the
|
|
|
|
* following forms.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* * A plain string represents a filename suitable for the underlying
|
|
|
|
* operating system.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* * A string starting with ``<code>|</code>'' indicates a subprocess.
|
|
|
|
* The remainder of the string following the ``<code>|</code>'' is
|
|
|
|
* invoked as a process with appropriate input/output channels
|
|
|
|
* connected to it.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* * A string equal to ``<code>|-</code>'' will create another Ruby
|
|
|
|
* instance as a subprocess.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* Ruby will convert pathnames between different operating system
|
|
|
|
* conventions if possible. For instance, on a Windows system the
|
|
|
|
* filename ``<code>/gumby/ruby/test.rb</code>'' will be opened as
|
|
|
|
* ``<code>\gumby\ruby\test.rb</code>''. When specifying a
|
|
|
|
* Windows-style filename in a Ruby string, remember to escape the
|
|
|
|
* backslashes:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* "c:\\gumby\\ruby\\test.rb"
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* Our examples here will use the Unix-style forward slashes;
|
|
|
|
* <code>File::SEPARATOR</code> can be used to get the
|
|
|
|
* platform-specific separator character.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* I/O ports may be opened in any one of several different modes, which
|
2003-12-27 03:44:05 +03:00
|
|
|
* are shown in this section as <em>mode</em>. The mode may
|
|
|
|
* either be a Fixnum or a String. If numeric, it should be
|
|
|
|
* one of the operating system specific constants (O_RDONLY,
|
|
|
|
* O_WRONLY, O_RDWR, O_APPEND and so on). See man open(2) for
|
|
|
|
* more information.
|
|
|
|
*
|
|
|
|
* If the mode is given as a String, it must be one of the
|
|
|
|
* values listed in the following table.
|
2003-12-24 07:24:29 +03:00
|
|
|
*
|
|
|
|
* Mode | Meaning
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "r" | Read-only, starts at beginning of file (default mode).
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "r+" | Read-write, starts at beginning of file.
|
|
|
|
* -----+--------------------------------------------------------
|
2004-06-29 05:17:39 +04:00
|
|
|
* "w" | Write-only, truncates existing file
|
2003-12-24 07:24:29 +03:00
|
|
|
* | to zero length or creates a new file for writing.
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "w+" | Read-write, truncates existing file to zero length
|
|
|
|
* | or creates a new file for reading and writing.
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "a" | Write-only, starts at end of file if file exists,
|
|
|
|
* | otherwise creates a new file for writing.
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "a+" | Read-write, starts at end of file if file exists,
|
2004-06-29 05:17:39 +04:00
|
|
|
* | otherwise creates a new file for reading and
|
2003-12-24 07:24:29 +03:00
|
|
|
* | writing.
|
|
|
|
* -----+--------------------------------------------------------
|
2008-12-23 14:30:44 +03:00
|
|
|
* "b" | Binary file mode (may appear with
|
2003-12-24 07:24:29 +03:00
|
|
|
* | any of the key letters listed above).
|
2008-12-23 14:30:44 +03:00
|
|
|
* | Suppresses EOL <-> CRLF conversion on Windows. And
|
|
|
|
* | sets external encoding to ASCII-8BIT unless explicitly
|
|
|
|
* | specified.
|
2008-08-24 14:32:59 +04:00
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "t" | Text file mode (may appear with
|
|
|
|
* | any of the key letters listed above except "b").
|
2003-12-24 07:24:29 +03:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
*
|
|
|
|
* The global constant ARGF (also accessible as $<) provides an
|
|
|
|
* IO-like stream which allows access to all files mentioned on the
|
|
|
|
* command line (or STDIN if no files are mentioned). ARGF provides
|
|
|
|
* the methods <code>#path</code> and <code>#filename</code> to access
|
|
|
|
* the name of the file currently being read.
|
2003-12-24 07:24:29 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
Init_IO(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2008-06-09 13:25:32 +04:00
|
|
|
#undef rb_intern
|
2008-08-16 04:20:31 +04:00
|
|
|
#define rb_intern(str) rb_intern_const(str)
|
2008-06-09 13:25:32 +04:00
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
VALUE rb_cARGF;
|
2004-06-29 05:17:39 +04:00
|
|
|
#ifdef __CYGWIN__
|
2003-02-15 21:16:52 +03:00
|
|
|
#include <sys/cygwin.h>
|
|
|
|
static struct __cygwin_perfile pf[] =
|
|
|
|
{
|
|
|
|
{"", O_RDONLY | O_BINARY},
|
|
|
|
{"", O_WRONLY | O_BINARY},
|
|
|
|
{"", O_RDWR | O_BINARY},
|
|
|
|
{"", O_APPEND | O_BINARY},
|
|
|
|
{NULL, 0}
|
|
|
|
};
|
|
|
|
cygwin_internal(CW_PERFILE, pf);
|
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_eIOError = rb_define_class("IOError", rb_eStandardError);
|
|
|
|
rb_eEOFError = rb_define_class("EOFError", rb_eIOError);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
id_write = rb_intern("write");
|
2003-04-10 21:41:40 +04:00
|
|
|
id_read = rb_intern("read");
|
|
|
|
id_getc = rb_intern("getc");
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
id_flush = rb_intern("flush");
|
2008-04-19 23:47:16 +04:00
|
|
|
id_readpartial = rb_intern("readpartial");
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_global_function("syscall", rb_f_syscall, -1);
|
|
|
|
|
|
|
|
rb_define_global_function("open", rb_f_open, -1);
|
1999-08-24 12:21:56 +04:00
|
|
|
rb_define_global_function("printf", rb_f_printf, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_global_function("print", rb_f_print, -1);
|
|
|
|
rb_define_global_function("putc", rb_f_putc, 1);
|
|
|
|
rb_define_global_function("puts", rb_f_puts, -1);
|
|
|
|
rb_define_global_function("gets", rb_f_gets, -1);
|
|
|
|
rb_define_global_function("readline", rb_f_readline, -1);
|
|
|
|
rb_define_global_function("select", rb_f_select, -1);
|
|
|
|
|
|
|
|
rb_define_global_function("readlines", rb_f_readlines, -1);
|
|
|
|
|
|
|
|
rb_define_global_function("`", rb_f_backquote, 1);
|
|
|
|
|
|
|
|
rb_define_global_function("p", rb_f_p, -1);
|
|
|
|
rb_define_method(rb_mKernel, "display", rb_obj_display, -1);
|
|
|
|
|
|
|
|
rb_cIO = rb_define_class("IO", rb_cObject);
|
|
|
|
rb_include_module(rb_cIO, rb_mEnumerable);
|
|
|
|
|
2009-03-19 14:40:38 +03:00
|
|
|
rb_mWaitReadable = rb_define_module_under(rb_cIO, "WaitReadable");
|
|
|
|
rb_mWaitWritable = rb_define_module_under(rb_cIO, "WaitWritable");
|
|
|
|
|
2008-12-23 14:30:44 +03:00
|
|
|
#if 0
|
|
|
|
/* This is necessary only for forcing rdoc handle File::open */
|
|
|
|
rb_define_singleton_method(rb_cFile, "open", rb_io_s_open, -1);
|
|
|
|
#endif
|
|
|
|
|
2002-12-20 11:33:17 +03:00
|
|
|
rb_define_alloc_func(rb_cIO, io_alloc);
|
2002-01-18 17:24:01 +03:00
|
|
|
rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1);
|
|
|
|
rb_define_singleton_method(rb_cIO, "open", rb_io_s_open, -1);
|
2002-05-23 09:35:32 +04:00
|
|
|
rb_define_singleton_method(rb_cIO, "sysopen", rb_io_s_sysopen, -1);
|
2003-04-03 09:25:00 +04:00
|
|
|
rb_define_singleton_method(rb_cIO, "for_fd", rb_io_s_for_fd, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1);
|
|
|
|
rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1);
|
|
|
|
rb_define_singleton_method(rb_cIO, "readlines", rb_io_s_readlines, -1);
|
2001-01-18 11:43:14 +03:00
|
|
|
rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
|
2008-09-23 14:48:17 +04:00
|
|
|
rb_define_singleton_method(rb_cIO, "binread", rb_io_s_binread, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_singleton_method(rb_cIO, "select", rb_f_select, -1);
|
2007-12-23 19:48:28 +03:00
|
|
|
rb_define_singleton_method(rb_cIO, "pipe", rb_io_s_pipe, -1);
|
2007-08-24 21:47:09 +04:00
|
|
|
rb_define_singleton_method(rb_cIO, "try_convert", rb_io_s_try_convert, 1);
|
2008-03-30 10:38:05 +04:00
|
|
|
rb_define_singleton_method(rb_cIO, "copy_stream", rb_io_s_copy_stream, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2002-01-18 17:24:01 +03:00
|
|
|
rb_define_method(rb_cIO, "initialize", rb_io_initialize, -1);
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
rb_output_fs = Qnil;
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_str_setter);
|
|
|
|
|
2001-10-29 08:07:26 +03:00
|
|
|
rb_rs = rb_default_rs = rb_str_new2("\n");
|
* gc.c, include/ruby/ruby.h: rename rb_register_mark_object()
to rb_gc_register_mark_object().
* eval.c, vm.c: initialize vm->mark_object_ary at
Init_top_self().
* bignum.c, complex.c, encoding.c, ext/win32ole/win32ole.c,
io.c, load.c, marshal.c, rational.c, ruby.c, vm.c:
use rb_gc_register_mark_object() instead of
rb_global_variable() or rb_gc_register_address().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-15 18:59:14 +04:00
|
|
|
rb_gc_register_mark_object(rb_default_rs);
|
2001-10-29 08:07:26 +03:00
|
|
|
rb_output_rs = Qnil;
|
2000-02-01 06:12:21 +03:00
|
|
|
OBJ_FREEZE(rb_default_rs); /* avoid modifying RS_default */
|
2003-04-14 13:04:43 +04:00
|
|
|
rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter);
|
|
|
|
rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
|
|
|
|
rb_define_hooked_variable("$\\", &rb_output_rs, 0, rb_str_setter);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
|
|
|
|
|
2003-05-19 09:41:08 +04:00
|
|
|
rb_define_method(rb_cIO, "initialize_copy", rb_io_init_copy, 1);
|
2000-02-29 11:05:32 +03:00
|
|
|
rb_define_method(rb_cIO, "reopen", rb_io_reopen, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "print", rb_io_print, -1);
|
|
|
|
rb_define_method(rb_cIO, "putc", rb_io_putc, 1);
|
|
|
|
rb_define_method(rb_cIO, "puts", rb_io_puts, -1);
|
|
|
|
rb_define_method(rb_cIO, "printf", rb_io_printf, -1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "each", rb_io_each_line, -1);
|
|
|
|
rb_define_method(rb_cIO, "each_line", rb_io_each_line, -1);
|
|
|
|
rb_define_method(rb_cIO, "each_byte", rb_io_each_byte, 0);
|
2008-03-30 19:00:12 +04:00
|
|
|
rb_define_method(rb_cIO, "each_char", rb_io_each_char, 0);
|
2009-06-22 12:23:30 +04:00
|
|
|
rb_define_method(rb_cIO, "each_codepoint", rb_io_each_codepoint, 0);
|
2006-10-17 03:07:07 +04:00
|
|
|
rb_define_method(rb_cIO, "lines", rb_io_lines, -1);
|
|
|
|
rb_define_method(rb_cIO, "bytes", rb_io_bytes, 0);
|
2008-03-30 19:00:12 +04:00
|
|
|
rb_define_method(rb_cIO, "chars", rb_io_chars, 0);
|
2009-06-22 12:23:30 +04:00
|
|
|
rb_define_method(rb_cIO, "codepoints", rb_io_codepoints, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "syswrite", rb_io_syswrite, 1);
|
2002-12-11 12:32:41 +03:00
|
|
|
rb_define_method(rb_cIO, "sysread", rb_io_sysread, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "fileno", rb_io_fileno, 0);
|
|
|
|
rb_define_alias(rb_cIO, "to_i", "fileno");
|
|
|
|
rb_define_method(rb_cIO, "to_io", rb_io_to_io, 0);
|
|
|
|
|
2002-01-23 10:30:43 +03:00
|
|
|
rb_define_method(rb_cIO, "fsync", rb_io_fsync, 0);
|
2009-06-22 08:50:29 +04:00
|
|
|
rb_define_method(rb_cIO, "fdatasync", rb_io_fdatasync, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cIO, "sync", rb_io_sync, 0);
|
|
|
|
rb_define_method(rb_cIO, "sync=", rb_io_set_sync, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "lineno", rb_io_lineno, 0);
|
|
|
|
rb_define_method(rb_cIO, "lineno=", rb_io_set_lineno, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "readlines", rb_io_readlines, -1);
|
|
|
|
|
2006-05-22 11:38:42 +04:00
|
|
|
rb_define_method(rb_cIO, "read_nonblock", io_read_nonblock, -1);
|
|
|
|
rb_define_method(rb_cIO, "write_nonblock", rb_io_write_nonblock, 1);
|
2004-08-11 20:57:14 +04:00
|
|
|
rb_define_method(rb_cIO, "readpartial", io_readpartial, -1);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_method(rb_cIO, "read", io_read, -1);
|
2008-09-23 15:55:48 +04:00
|
|
|
rb_define_method(rb_cIO, "write", io_write_m, 1);
|
2000-01-05 07:41:21 +03:00
|
|
|
rb_define_method(rb_cIO, "gets", rb_io_gets_m, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cIO, "readline", rb_io_readline, -1);
|
* 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-25 07:29:39 +04:00
|
|
|
rb_define_method(rb_cIO, "getc", rb_io_getc, 0);
|
|
|
|
rb_define_method(rb_cIO, "getbyte", rb_io_getbyte, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cIO, "readchar", rb_io_readchar, 0);
|
* 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-25 07:29:39 +04:00
|
|
|
rb_define_method(rb_cIO, "readbyte", rb_io_readbyte, 0);
|
2008-08-18 18:28:45 +04:00
|
|
|
rb_define_method(rb_cIO, "ungetbyte",rb_io_ungetbyte, 1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cIO, "ungetc",rb_io_ungetc, 1);
|
|
|
|
rb_define_method(rb_cIO, "<<", rb_io_addstr, 1);
|
|
|
|
rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
|
|
|
|
rb_define_method(rb_cIO, "tell", rb_io_tell, 0);
|
2001-03-13 08:45:13 +03:00
|
|
|
rb_define_method(rb_cIO, "seek", rb_io_seek_m, -1);
|
1999-11-04 11:39:57 +03:00
|
|
|
rb_define_const(rb_cIO, "SEEK_SET", INT2FIX(SEEK_SET));
|
|
|
|
rb_define_const(rb_cIO, "SEEK_CUR", INT2FIX(SEEK_CUR));
|
|
|
|
rb_define_const(rb_cIO, "SEEK_END", INT2FIX(SEEK_END));
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0);
|
|
|
|
rb_define_method(rb_cIO, "pos", rb_io_tell, 0);
|
|
|
|
rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);
|
|
|
|
rb_define_method(rb_cIO, "eof", rb_io_eof, 0);
|
|
|
|
rb_define_method(rb_cIO, "eof?", rb_io_eof, 0);
|
|
|
|
|
2007-11-20 11:12:34 +03:00
|
|
|
rb_define_method(rb_cIO, "close_on_exec?", rb_io_close_on_exec_p, 0);
|
|
|
|
rb_define_method(rb_cIO, "close_on_exec=", rb_io_set_close_on_exec, 1);
|
|
|
|
|
2000-01-05 07:41:21 +03:00
|
|
|
rb_define_method(rb_cIO, "close", rb_io_close_m, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_method(rb_cIO, "closed?", rb_io_closed, 0);
|
|
|
|
rb_define_method(rb_cIO, "close_read", rb_io_close_read, 0);
|
|
|
|
rb_define_method(rb_cIO, "close_write", rb_io_close_write, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "isatty", rb_io_isatty, 0);
|
|
|
|
rb_define_method(rb_cIO, "tty?", rb_io_isatty, 0);
|
2007-11-20 06:16:53 +03:00
|
|
|
rb_define_method(rb_cIO, "binmode", rb_io_binmode_m, 0);
|
2008-06-21 19:08:57 +04:00
|
|
|
rb_define_method(rb_cIO, "binmode?", rb_io_binmode_p, 0);
|
2002-03-27 08:28:00 +03:00
|
|
|
rb_define_method(rb_cIO, "sysseek", rb_io_sysseek, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
|
|
|
|
rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
|
2000-05-24 08:34:26 +04:00
|
|
|
rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
|
2002-02-22 13:28:47 +03:00
|
|
|
rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2007-12-21 07:26:38 +03:00
|
|
|
rb_define_method(rb_cIO, "external_encoding", rb_io_external_encoding, 0);
|
2007-12-23 18:56:41 +03:00
|
|
|
rb_define_method(rb_cIO, "internal_encoding", rb_io_internal_encoding, 0);
|
2007-12-24 21:17:35 +03:00
|
|
|
rb_define_method(rb_cIO, "set_encoding", rb_io_set_encoding, -1);
|
2007-12-21 07:26:38 +03:00
|
|
|
|
2003-07-29 22:26:55 +04:00
|
|
|
rb_define_variable("$stdin", &rb_stdin);
|
2005-12-12 06:04:53 +03:00
|
|
|
rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
|
2003-07-29 22:26:55 +04:00
|
|
|
rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);
|
2005-12-12 06:04:53 +03:00
|
|
|
rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO, "<STDOUT>");
|
2003-07-29 22:26:55 +04:00
|
|
|
rb_define_hooked_variable("$stderr", &rb_stderr, 0, stdout_setter);
|
2005-12-12 06:04:53 +03:00
|
|
|
rb_stderr = prep_stdio(stderr, FMODE_WRITABLE|FMODE_SYNC, rb_cIO, "<STDERR>");
|
2003-07-29 22:26:55 +04:00
|
|
|
rb_define_hooked_variable("$>", &rb_stdout, 0, stdout_setter);
|
|
|
|
orig_stdout = rb_stdout;
|
2003-07-31 12:42:44 +04:00
|
|
|
rb_deferr = orig_stderr = rb_stderr;
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
|
|
|
|
/* constants to hold original stdin/stdout/stderr */
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_define_global_const("STDIN", rb_stdin);
|
|
|
|
rb_define_global_const("STDOUT", rb_stdout);
|
|
|
|
rb_define_global_const("STDERR", rb_stderr);
|
|
|
|
|
2008-03-19 18:21:15 +03:00
|
|
|
rb_cARGF = rb_class_new(rb_cObject);
|
2008-03-20 15:46:35 +03:00
|
|
|
rb_set_class_path(rb_cARGF, rb_cObject, "ARGF.class");
|
2008-03-19 18:21:15 +03:00
|
|
|
rb_define_alloc_func(rb_cARGF, argf_alloc);
|
2008-03-01 11:59:04 +03:00
|
|
|
|
|
|
|
rb_include_module(rb_cARGF, rb_mEnumerable);
|
|
|
|
|
2008-03-19 18:21:15 +03:00
|
|
|
rb_define_method(rb_cARGF, "initialize", argf_initialize, -2);
|
|
|
|
rb_define_method(rb_cARGF, "initialize_copy", argf_initialize_copy, 1);
|
2008-03-01 11:59:04 +03:00
|
|
|
rb_define_method(rb_cARGF, "to_s", argf_to_s, 0);
|
|
|
|
rb_define_method(rb_cARGF, "argv", argf_argv, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cARGF, "fileno", argf_fileno, 0);
|
|
|
|
rb_define_method(rb_cARGF, "to_i", argf_fileno, 0);
|
|
|
|
rb_define_method(rb_cARGF, "to_io", argf_to_io, 0);
|
|
|
|
rb_define_method(rb_cARGF, "each", argf_each_line, -1);
|
|
|
|
rb_define_method(rb_cARGF, "each_line", argf_each_line, -1);
|
|
|
|
rb_define_method(rb_cARGF, "each_byte", argf_each_byte, 0);
|
2008-03-30 19:00:12 +04:00
|
|
|
rb_define_method(rb_cARGF, "each_char", argf_each_char, 0);
|
2008-05-27 08:13:58 +04:00
|
|
|
rb_define_method(rb_cARGF, "lines", argf_each_line, -1);
|
|
|
|
rb_define_method(rb_cARGF, "bytes", argf_each_byte, 0);
|
|
|
|
rb_define_method(rb_cARGF, "chars", argf_each_char, 0);
|
2008-03-01 11:59:04 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cARGF, "read", argf_read, -1);
|
|
|
|
rb_define_method(rb_cARGF, "readpartial", argf_readpartial, -1);
|
2008-03-21 15:32:33 +03:00
|
|
|
rb_define_method(rb_cARGF, "readlines", argf_readlines, -1);
|
|
|
|
rb_define_method(rb_cARGF, "to_a", argf_readlines, -1);
|
|
|
|
rb_define_method(rb_cARGF, "gets", argf_gets, -1);
|
|
|
|
rb_define_method(rb_cARGF, "readline", argf_readline, -1);
|
2008-03-01 11:59:04 +03:00
|
|
|
rb_define_method(rb_cARGF, "getc", argf_getc, 0);
|
|
|
|
rb_define_method(rb_cARGF, "getbyte", argf_getbyte, 0);
|
|
|
|
rb_define_method(rb_cARGF, "readchar", argf_readchar, 0);
|
|
|
|
rb_define_method(rb_cARGF, "readbyte", argf_readbyte, 0);
|
|
|
|
rb_define_method(rb_cARGF, "tell", argf_tell, 0);
|
|
|
|
rb_define_method(rb_cARGF, "seek", argf_seek_m, -1);
|
|
|
|
rb_define_method(rb_cARGF, "rewind", argf_rewind, 0);
|
|
|
|
rb_define_method(rb_cARGF, "pos", argf_tell, 0);
|
|
|
|
rb_define_method(rb_cARGF, "pos=", argf_set_pos, 1);
|
|
|
|
rb_define_method(rb_cARGF, "eof", argf_eof, 0);
|
|
|
|
rb_define_method(rb_cARGF, "eof?", argf_eof, 0);
|
|
|
|
rb_define_method(rb_cARGF, "binmode", argf_binmode_m, 0);
|
2008-06-21 19:08:57 +04:00
|
|
|
rb_define_method(rb_cARGF, "binmode?", argf_binmode_p, 0);
|
2008-03-01 11:59:04 +03:00
|
|
|
|
|
|
|
rb_define_method(rb_cARGF, "filename", argf_filename, 0);
|
|
|
|
rb_define_method(rb_cARGF, "path", argf_filename, 0);
|
|
|
|
rb_define_method(rb_cARGF, "file", argf_file, 0);
|
|
|
|
rb_define_method(rb_cARGF, "skip", argf_skip, 0);
|
|
|
|
rb_define_method(rb_cARGF, "close", argf_close_m, 0);
|
|
|
|
rb_define_method(rb_cARGF, "closed?", argf_closed, 0);
|
|
|
|
|
|
|
|
rb_define_method(rb_cARGF, "lineno", argf_lineno, 0);
|
|
|
|
rb_define_method(rb_cARGF, "lineno=", argf_set_lineno, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cARGF, "inplace_mode", argf_inplace_mode_get, 0);
|
|
|
|
rb_define_method(rb_cARGF, "inplace_mode=", argf_inplace_mode_set, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cARGF, "external_encoding", argf_external_encoding, 0);
|
|
|
|
rb_define_method(rb_cARGF, "internal_encoding", argf_internal_encoding, 0);
|
|
|
|
rb_define_method(rb_cARGF, "set_encoding", argf_set_encoding, -1);
|
|
|
|
|
2008-03-19 18:21:15 +03:00
|
|
|
argf = rb_class_new_instance(0, 0, rb_cARGF);
|
|
|
|
|
2005-12-12 06:04:53 +03:00
|
|
|
rb_define_readonly_variable("$<", &argf);
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_define_global_const("ARGF", argf);
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
rb_define_hooked_variable("$.", &argf, argf_lineno_getter, argf_lineno_setter);
|
2008-10-14 15:45:32 +04:00
|
|
|
rb_define_hooked_variable("$FILENAME", &argf, argf_filename_getter, rb_gvar_readonly_setter);
|
2008-09-04 07:33:27 +04:00
|
|
|
ARGF.filename = rb_str_new2("-");
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
rb_define_hooked_variable("$-i", &argf, opt_i_get, opt_i_set);
|
2008-10-14 15:45:32 +04:00
|
|
|
rb_define_hooked_variable("$*", &argf, argf_argv_getter, rb_gvar_readonly_setter);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2008-10-04 17:25:12 +04:00
|
|
|
#if defined (_WIN32) || defined(__CYGWIN__)
|
1998-01-16 15:13:05 +03:00
|
|
|
atexit(pipe_atexit);
|
|
|
|
#endif
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
Init_File();
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2000-03-23 11:37:35 +03:00
|
|
|
rb_define_method(rb_cFile, "initialize", rb_file_initialize, -1);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
rb_file_const("RDONLY", INT2FIX(O_RDONLY));
|
|
|
|
rb_file_const("WRONLY", INT2FIX(O_WRONLY));
|
|
|
|
rb_file_const("RDWR", INT2FIX(O_RDWR));
|
|
|
|
rb_file_const("APPEND", INT2FIX(O_APPEND));
|
|
|
|
rb_file_const("CREAT", INT2FIX(O_CREAT));
|
|
|
|
rb_file_const("EXCL", INT2FIX(O_EXCL));
|
|
|
|
#if defined(O_NDELAY) || defined(O_NONBLOCK)
|
|
|
|
# ifdef O_NONBLOCK
|
|
|
|
rb_file_const("NONBLOCK", INT2FIX(O_NONBLOCK));
|
|
|
|
# else
|
|
|
|
rb_file_const("NONBLOCK", INT2FIX(O_NDELAY));
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
rb_file_const("TRUNC", INT2FIX(O_TRUNC));
|
|
|
|
#ifdef O_NOCTTY
|
|
|
|
rb_file_const("NOCTTY", INT2FIX(O_NOCTTY));
|
|
|
|
#endif
|
|
|
|
#ifdef O_BINARY
|
|
|
|
rb_file_const("BINARY", INT2FIX(O_BINARY));
|
2007-12-21 08:47:15 +03:00
|
|
|
#else
|
|
|
|
rb_file_const("BINARY", INT2FIX(0));
|
1999-08-13 09:45:20 +04:00
|
|
|
#endif
|
2000-02-17 10:11:22 +03:00
|
|
|
#ifdef O_SYNC
|
2000-02-18 09:59:36 +03:00
|
|
|
rb_file_const("SYNC", INT2FIX(O_SYNC));
|
2000-02-17 10:11:22 +03:00
|
|
|
#endif
|
2008-08-20 14:16:20 +04:00
|
|
|
#ifdef O_DSYNC
|
|
|
|
rb_file_const("DSYNC", INT2FIX(O_DSYNC));
|
|
|
|
#endif
|
|
|
|
#ifdef O_RSYNC
|
|
|
|
rb_file_const("RSYNC", INT2FIX(O_RSYNC));
|
|
|
|
#endif
|
|
|
|
#ifdef O_NOFOLLOW
|
|
|
|
rb_file_const("NOFOLLOW", INT2FIX(O_NOFOLLOW)); /* FreeBSD, Linux */
|
|
|
|
#endif
|
2009-05-11 15:11:11 +04:00
|
|
|
#ifdef O_NOATIME
|
|
|
|
rb_file_const("NOATIME", INT2FIX(O_NOATIME)); /* Linux */
|
|
|
|
#endif
|
2008-06-17 01:31:56 +04:00
|
|
|
|
|
|
|
sym_mode = ID2SYM(rb_intern("mode"));
|
|
|
|
sym_perm = ID2SYM(rb_intern("perm"));
|
|
|
|
sym_extenc = ID2SYM(rb_intern("external_encoding"));
|
|
|
|
sym_intenc = ID2SYM(rb_intern("internal_encoding"));
|
|
|
|
sym_encoding = ID2SYM(rb_intern("encoding"));
|
|
|
|
sym_open_args = ID2SYM(rb_intern("open_args"));
|
2008-08-23 06:23:42 +04:00
|
|
|
sym_textmode = ID2SYM(rb_intern("textmode"));
|
|
|
|
sym_binmode = ID2SYM(rb_intern("binmode"));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|