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"
|
|
|
|
#include "ruby/signal.h"
|
2008-03-30 10:38:05 +04:00
|
|
|
#include "vm_core.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
|
|
|
|
* 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(MSDOS) || defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__human68k__) || defined(__EMX__) || defined(__BEOS__)
|
2000-08-25 12:26:06 +04:00
|
|
|
# define NO_SAFE_RENAME
|
|
|
|
#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(MSDOS) || 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>
|
2005-07-27 11:27:19 +04:00
|
|
|
#if defined(HAVE_SYS_IOCTL_H) && !defined(DJGPP) && !defined(_WIN32) && !defined(__human68k__)
|
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
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE rb_cIO;
|
|
|
|
VALUE rb_eEOFError;
|
|
|
|
VALUE rb_eIOError;
|
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;
|
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;
|
|
|
|
int gets_lineno;
|
|
|
|
int init_p, next_p;
|
|
|
|
VALUE lineno;
|
|
|
|
VALUE argv;
|
|
|
|
char *inplace;
|
|
|
|
int binmode;
|
|
|
|
rb_encoding *enc, *enc2;
|
|
|
|
};
|
|
|
|
|
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)
|
|
|
|
#elif defined(__VMS)
|
2005-09-12 19:23:54 +04:00
|
|
|
# define STDIO_READ_DATA_PENDING(fp) (((unsigned int)(*(fp))->_cnt) > 0)
|
2004-12-30 16:49:56 +03:00
|
|
|
#else
|
|
|
|
# define STDIO_READ_DATA_PENDING(fp) (!feof(fp))
|
|
|
|
#endif
|
|
|
|
|
2003-12-26 04:47:12 +03:00
|
|
|
#if defined(__VMS)
|
|
|
|
#define open(file_spec, flags, mode) open(file_spec, flags, mode, "rfm=stmlf")
|
|
|
|
#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
|
|
|
|
|
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
|
2005-11-11 14:08:17 +03:00
|
|
|
is_socket(int fd, const char *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)
|
|
|
|
rb_sys_fail(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
|
|
|
|
*/
|
|
|
|
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 20:20:24 +03:00
|
|
|
#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
|
|
|
|
if (!(fptr->mode & FMODE_BINMODE)) {
|
|
|
|
int len = fptr->rbuf_len;
|
|
|
|
while (fptr->rbuf_len-- > 0) {
|
|
|
|
if (fptr->rbuf[fptr->rbuf_len] == '\n')
|
|
|
|
++len;
|
|
|
|
}
|
|
|
|
r = lseek(fptr->fd, -len, SEEK_CUR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
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
|
|
|
{
|
* 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 len = RSTRING_LEN(str);
|
|
|
|
|
* 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;
|
* 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)
|
|
|
|
fptr->rbuf_capa = len;
|
|
|
|
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;
|
|
|
|
}
|
* 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
|
|
|
fptr->rbuf_off-=len;
|
|
|
|
fptr->rbuf_len+=len;
|
|
|
|
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
|
|
|
{
|
* 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_fflush(fptr);
|
|
|
|
io_unread(fptr);
|
2007-10-25 09:19:33 +04:00
|
|
|
errno = 0;
|
2002-10-02 18:59:25 +04:00
|
|
|
return 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
|
|
|
#define io_seek(fptr, ofs, whence) lseek(flush_before_seek(fptr)->fd, ofs, whence)
|
|
|
|
#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) {
|
|
|
|
io_fflush(fptr);
|
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);
|
|
|
|
io_fflush(wfptr);
|
|
|
|
}
|
2007-12-23 21:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static rb_encoding*
|
|
|
|
io_read_encoding(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
if (fptr->enc) {
|
|
|
|
return fptr->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)
|
|
|
|
{
|
|
|
|
if (fptr->enc2) {
|
|
|
|
return fptr->enc2;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-01-17 11:37:53 +03: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_read_pending(FILE *fp)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2004-12-30 16:49:56 +03:00
|
|
|
return STDIO_READ_DATA_PENDING(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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rb_read_internal(int fd, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct io_internal_struct iis;
|
|
|
|
iis.fd = fd;
|
|
|
|
iis.buf = buf;
|
|
|
|
iis.capa = count;
|
|
|
|
|
2008-05-02 18:59:28 +04:00
|
|
|
return rb_thread_blocking_region(internal_read_func, &iis, RB_UBF_DFL, 0);
|
2007-12-21 12:43:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rb_write_internal(int fd, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct io_internal_struct iis;
|
|
|
|
iis.fd = fd;
|
|
|
|
iis.buf = buf;
|
|
|
|
iis.capa = count;
|
|
|
|
|
2008-05-02 18:59:28 +04:00
|
|
|
return rb_thread_blocking_region(internal_write_func, &iis, RB_UBF_DFL, 0);
|
2007-12-21 12:43:49 +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
|
|
|
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
|
|
|
{
|
2005-07-18 05:00:23 +04:00
|
|
|
int r, 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
|
|
|
int wbuf_off, wbuf_len;
|
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;
|
|
|
|
wbuf_off = fptr->wbuf_off;
|
|
|
|
wbuf_len = fptr->wbuf_len;
|
2007-12-27 08:36:02 +03:00
|
|
|
l = wbuf_len;
|
2005-07-18 05:00:23 +04:00
|
|
|
if (PIPE_BUF < l &&
|
|
|
|
!rb_thread_critical &&
|
|
|
|
!rb_thread_alone() &&
|
|
|
|
wsplit_p(fptr)) {
|
|
|
|
l = PIPE_BUF;
|
|
|
|
}
|
2007-12-27 08:36:02 +03:00
|
|
|
r = rb_write_internal(fptr->fd, fptr->wbuf+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) {
|
2008-05-05 15:12:17 +04:00
|
|
|
fptr->wbuf_off += r;
|
|
|
|
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
|
|
|
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
|
2002-10-02 18:13:58 +04:00
|
|
|
rb_thread_select(f + 1, &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
|
2002-10-02 18:13:58 +04:00
|
|
|
rb_thread_select(f + 1, NULL, &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-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;
|
|
|
|
|
|
|
|
enc = fptr->enc2 ? fptr->enc2 : fptr->enc;
|
|
|
|
senc = rb_econv_stateless_encoding(enc->name);
|
|
|
|
if (senc) {
|
|
|
|
denc = enc->name;
|
|
|
|
fptr->writeconv_stateless = rb_str_new2(senc);
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-08-18 17:35:55 +04:00
|
|
|
denc = NULL;
|
|
|
|
fptr->writeconv_stateless = Qnil;
|
2008-08-18 16:06:42 +04:00
|
|
|
}
|
|
|
|
if (senc) {
|
|
|
|
fptr->writeconv = rb_econv_open(senc, denc, 0);
|
|
|
|
if (!fptr->writeconv)
|
|
|
|
rb_raise(rb_eIOError, "code converter open failed (%s to %s)", senc, denc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fptr->writeconv = NULL;
|
|
|
|
}
|
|
|
|
fptr->writeconv_initialized = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/* writing functions */
|
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_fwrite(VALUE str, rb_io_t *fptr)
|
2002-12-20 12:29:41 +03:00
|
|
|
{
|
2005-07-18 05:00:23 +04:00
|
|
|
long len, n, r, l, offset = 0;
|
2002-12-20 12:29:41 +03:00
|
|
|
|
2007-12-22 19:21:09 +03:00
|
|
|
/*
|
|
|
|
* If an external encoding was specified and it differs from
|
|
|
|
* the strings encoding then we must transcode before writing.
|
|
|
|
*/
|
2007-12-22 20:28:20 +03:00
|
|
|
if (fptr->enc) {
|
2008-08-18 16:06:42 +04:00
|
|
|
make_writeconv(fptr);
|
2008-08-18 17:35:55 +04:00
|
|
|
if (fptr->writeconv) {
|
|
|
|
str = rb_str_transcode(str, fptr->writeconv_stateless);
|
2008-08-18 16:06:42 +04:00
|
|
|
str = rb_econv_string(fptr->writeconv, str, 0, RSTRING_LEN(str), Qnil, ECONV_PARTIAL_INPUT);
|
2008-08-18 17:35:55 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fptr->enc2)
|
|
|
|
str = rb_str_transcode(str, rb_enc_from_encoding(fptr->enc2));
|
|
|
|
else
|
2008-08-18 16:06:42 +04:00
|
|
|
str = rb_str_transcode(str, rb_enc_from_encoding(fptr->enc));
|
2008-08-18 17:35:55 +04:00
|
|
|
}
|
2007-12-22 19:21:09 +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;
|
* 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 == NULL && !(fptr->mode & FMODE_SYNC)) {
|
|
|
|
fptr->wbuf_off = 0;
|
|
|
|
fptr->wbuf_len = 0;
|
|
|
|
fptr->wbuf_capa = 8192;
|
|
|
|
fptr->wbuf = ALLOC_N(char, fptr->wbuf_capa);
|
|
|
|
}
|
2008-03-01 11:59:04 +03:00
|
|
|
if ((fptr->mode & (FMODE_SYNC|FMODE_TTY)) ||
|
|
|
|
(fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + 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
|
|
|
/* 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);
|
* 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_len += len;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
retry:
|
2005-07-18 05:00:23 +04:00
|
|
|
l = n;
|
|
|
|
if (PIPE_BUF < l &&
|
|
|
|
!rb_thread_critical &&
|
|
|
|
!rb_thread_alone() &&
|
|
|
|
wsplit_p(fptr)) {
|
|
|
|
l = PIPE_BUF;
|
|
|
|
}
|
2007-12-21 12:43:49 +03:00
|
|
|
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);
|
* 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_len += len;
|
|
|
|
return len;
|
2002-12-20 12:29:41 +03:00
|
|
|
}
|
|
|
|
|
2004-11-27 16:05:46 +03:00
|
|
|
long
|
* 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_fwrite(const char *ptr, long len, FILE *f)
|
2004-11-27 16:05:46 +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 of;
|
2004-11-27 16:05:46 +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
|
|
|
of.fd = fileno(f);
|
2004-12-08 16:26:27 +03:00
|
|
|
of.stdio_file = f;
|
2004-11-27 16:05:46 +03:00
|
|
|
of.mode = FMODE_WRITABLE;
|
2004-11-27 17:08:45 +03:00
|
|
|
of.path = NULL;
|
2004-12-06 18:31:26 +03:00
|
|
|
return io_fwrite(rb_str_new(ptr, len), &of);
|
2004-11-27 16:05:46 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.write(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>. 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.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* count = $stdout.write( "This is a test\n" )
|
|
|
|
* puts "That was #{count} bytes of data"
|
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
|
|
|
|
* That was 15 bytes of data
|
|
|
|
*/
|
|
|
|
|
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_write(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-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
|
|
|
|
2004-12-06 18:31:26 +03:00
|
|
|
n = io_fwrite(str, fptr);
|
2002-12-20 12:29:41 +03:00
|
|
|
if (n == -1L) rb_sys_fail(fptr->path);
|
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
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
io_fflush(fptr);
|
|
|
|
}
|
|
|
|
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);
|
2007-10-25 09:19:33 +04:00
|
|
|
if (pos < 0 && errno) rb_sys_fail(fptr->path);
|
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);
|
2007-10-25 09:19:33 +04:00
|
|
|
if (pos < 0 && errno) rb_sys_fail(fptr->path);
|
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);
|
2004-06-25 03:10:55 +04:00
|
|
|
if (pos < 0) rb_sys_fail(fptr->path);
|
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
|
|
|
}
|
|
|
|
|
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);
|
2004-06-25 03:10:55 +04:00
|
|
|
if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail(fptr->path);
|
2008-03-01 11:59:04 +03:00
|
|
|
if (io == ARGF.current_file) {
|
|
|
|
ARGF.gets_lineno -= fptr->lineno;
|
2000-06-19 12:38:11 +04:00
|
|
|
}
|
|
|
|
fptr->lineno = 0;
|
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
|
|
|
{
|
|
|
|
int 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
|
|
|
|
* 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;
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
fptr->rbuf_off = 0;
|
|
|
|
fptr->rbuf_len = r;
|
|
|
|
if (r == 0)
|
|
|
|
return -1; /* EOF */
|
|
|
|
}
|
* 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
|
* 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_sync(VALUE io, VALUE mode)
|
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);
|
|
|
|
if (RTEST(mode)) {
|
|
|
|
fptr->mode |= FMODE_SYNC;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fptr->mode &= ~FMODE_SYNC;
|
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* Returns <code>nil</code> if the underlying operating system does not
|
|
|
|
* support <em>fsync(2)</em>. Note that <code>fsync</code> differs from
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
|
|
|
#ifdef HAVE_FSYNC
|
* 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
|
|
|
|
* 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_fflush(fptr);
|
|
|
|
if (fsync(fptr->fd) < 0)
|
2002-01-23 10:30:43 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
return INT2FIX(0);
|
|
|
|
#else
|
|
|
|
rb_notimplement();
|
|
|
|
return Qnil; /* not reached */
|
|
|
|
#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
|
|
|
|
* <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;
|
|
|
|
return INT2FIX(fptr->pid);
|
|
|
|
}
|
|
|
|
|
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;
|
* 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;
|
2003-11-06 12:05:11 +03:00
|
|
|
if (!fptr || !fptr->path) return rb_any_to_s(obj);
|
2003-01-31 07:00:17 +03:00
|
|
|
cname = rb_obj_classname(obj);
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->fd < 0) {
|
2003-11-06 12:05:11 +03:00
|
|
|
st = " (closed)";
|
|
|
|
}
|
2005-07-23 05:02:18 +04:00
|
|
|
return rb_sprintf("#<%s:%s%s>", cname, fptr->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
|
|
|
{
|
|
|
|
long n;
|
|
|
|
|
* 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;
|
|
|
|
if (n > len) n = 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;
|
2000-07-14 11:18:58 +04:00
|
|
|
int c;
|
|
|
|
|
2008-06-11 18:54:23 +04:00
|
|
|
if (READ_DATA_PENDING(fptr) == 0) {
|
|
|
|
while (n > 0) {
|
|
|
|
c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n);
|
|
|
|
if (c == 0) break;
|
|
|
|
if (c < 0) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-11-27 05:21:53 +03:00
|
|
|
long
|
* 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_fread(char *ptr, long len, FILE *f)
|
2004-11-27 05:21:53 +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 of;
|
2004-12-06 18:31:26 +03:00
|
|
|
VALUE str;
|
|
|
|
long n;
|
2004-11-27 05:21: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
|
|
|
of.fd = fileno(f);
|
2004-12-08 16:26:27 +03:00
|
|
|
of.stdio_file = f;
|
2004-11-29 09:09:40 +03:00
|
|
|
of.mode = FMODE_READABLE;
|
2004-12-06 18:31:26 +03:00
|
|
|
str = rb_str_new(ptr, len);
|
|
|
|
n = io_fread(str, 0, &of);
|
2006-08-31 14:47:44 +04:00
|
|
|
MEMCPY(ptr, RSTRING_PTR(str), char, n);
|
2004-12-06 18:31:26 +03:00
|
|
|
return n;
|
2004-11-27 05:21:53 +03: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
|
|
|
|
)
|
|
|
|
{
|
2005-01-11 14:59:00 +03:00
|
|
|
io_fflush(fptr);
|
|
|
|
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
|
|
|
|
make_readconv(rb_io_t *fptr)
|
|
|
|
{
|
|
|
|
if (!fptr->readconv) {
|
|
|
|
fptr->readconv = rb_econv_open(fptr->enc2->name, fptr->enc->name, 0);
|
|
|
|
if (!fptr->readconv)
|
2008-08-18 16:06:42 +04:00
|
|
|
rb_raise(rb_eIOError, "code converter open failed (%s to %s)", fptr->enc2->name, fptr->enc->name);
|
2008-08-18 07:13:53 +04:00
|
|
|
fptr->crbuf_off = 0;
|
|
|
|
fptr->crbuf_len = 0;
|
|
|
|
fptr->crbuf_capa = 1024;
|
|
|
|
fptr->crbuf = ALLOC_N(char, fptr->crbuf_capa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
int crbuf_len0;
|
|
|
|
|
|
|
|
if (fptr->crbuf_len == fptr->crbuf_capa)
|
|
|
|
return 0; /* crbuf full */
|
|
|
|
if (fptr->crbuf_len == 0)
|
|
|
|
fptr->crbuf_off = 0;
|
|
|
|
else if (fptr->crbuf_off + fptr->crbuf_len == fptr->crbuf_capa) {
|
|
|
|
memmove(fptr->crbuf, fptr->crbuf+fptr->crbuf_off, fptr->crbuf_len);
|
|
|
|
fptr->crbuf_off = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
crbuf_len0 = fptr->crbuf_len;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ss = sp = (const unsigned char *)fptr->rbuf + fptr->rbuf_off;
|
|
|
|
se = sp + fptr->rbuf_len;
|
|
|
|
ds = dp = (unsigned char *)fptr->crbuf + fptr->crbuf_off + fptr->crbuf_len;
|
|
|
|
de = (unsigned char *)fptr->crbuf + fptr->crbuf_capa;
|
|
|
|
res = rb_econv_convert(fptr->readconv, &sp, se, &dp, de, ECONV_PARTIAL_INPUT|ECONV_OUTPUT_FOLLOWED_BY_INPUT);
|
|
|
|
fptr->rbuf_off += sp - ss;
|
|
|
|
fptr->rbuf_len -= sp - ss;
|
|
|
|
fptr->crbuf_len += dp - ds;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (crbuf_len0 != fptr->crbuf_len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (res == econv_finished)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ds = dp = (unsigned char *)fptr->crbuf + fptr->crbuf_off + fptr->crbuf_len;
|
|
|
|
de = (unsigned char *)fptr->crbuf + fptr->crbuf_capa;
|
|
|
|
res = rb_econv_convert(fptr->readconv, NULL, NULL, &dp, de, 0);
|
|
|
|
fptr->crbuf_len += dp - ds;
|
|
|
|
rb_econv_check_error(fptr->readconv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
io_shift_crbuf(rb_io_t *fptr, int len, VALUE *strp)
|
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
if (NIL_P(*strp)) {
|
|
|
|
*strp = str = rb_str_new(fptr->crbuf+fptr->crbuf_off, len);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
size_t slen;
|
|
|
|
str = *strp;
|
|
|
|
slen = RSTRING_LEN(str);
|
|
|
|
rb_str_resize(str, RSTRING_LEN(str) + len);
|
|
|
|
memcpy(RSTRING_PTR(str)+slen, fptr->crbuf+fptr->crbuf_off, len);
|
|
|
|
}
|
|
|
|
fptr->crbuf_off += len;
|
|
|
|
fptr->crbuf_len -= len;
|
|
|
|
OBJ_TAINT(str);
|
|
|
|
rb_enc_associate(str, fptr->enc);
|
|
|
|
/* xxx: set coderange */
|
|
|
|
if (fptr->crbuf_len == 0)
|
|
|
|
fptr->crbuf_off = 0;
|
|
|
|
if (fptr->crbuf_off < fptr->crbuf_capa/2) {
|
|
|
|
memmove(fptr->crbuf, fptr->crbuf+fptr->crbuf_off, fptr->crbuf_len);
|
|
|
|
fptr->crbuf_off = 0;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (fptr->enc2) {
|
|
|
|
VALUE str = rb_str_new(NULL, 0);
|
|
|
|
make_readconv(fptr);
|
|
|
|
while (1) {
|
|
|
|
if (fptr->crbuf_len) {
|
|
|
|
io_shift_crbuf(fptr, fptr->crbuf_len, &str);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
cr = fptr->enc2 ? ENC_CODERANGE_BROKEN : 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-02-27 23:56:03 +03:00
|
|
|
if (!fptr->enc2) {
|
2008-02-27 18:19:22 +03:00
|
|
|
ENC_CODERANGE_SET(str, cr);
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
#ifdef F_GETFL
|
|
|
|
flags = fcntl(fptr->fd, F_GETFL);
|
|
|
|
if (flags == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
flags = 0;
|
|
|
|
#endif
|
2006-05-23 02:12:57 +04:00
|
|
|
if ((flags & O_NONBLOCK) == 0) {
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
if (fcntl(fptr->fd, F_SETFL, flags) == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
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;
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)".
|
|
|
|
* * It doesn't cause Errno::EAGAIN and Errno::EINTR. When readpartial meets EAGAIN 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.
|
|
|
|
* It blocks on the situation IO#sysread causes Errno::EAGAIN 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
|
|
|
|
* read(2) system call after O_NONBLOCK is set for
|
|
|
|
* the underlying file descriptor.
|
|
|
|
*
|
|
|
|
* If the optional <i>outbuf</i> argument is present,
|
|
|
|
* it must reference a String, which will receive the data.
|
|
|
|
*
|
|
|
|
* read_nonblock just calls read(2).
|
|
|
|
* It causes all errors read(2) causes: EAGAIN, EINTR, etc.
|
|
|
|
* The caller should care such errors.
|
|
|
|
*
|
|
|
|
* read_nonblock causes EOFError on EOF.
|
|
|
|
*
|
|
|
|
* If the read buffer is not empty,
|
|
|
|
* read_nonblock reads from the buffer like readpartial.
|
|
|
|
* In this case, read(2) is not called.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
* write(2) system call after O_NONBLOCK is set for
|
|
|
|
* the underlying file descriptor.
|
|
|
|
*
|
|
|
|
* write_nonblock just calls write(2).
|
|
|
|
* It causes all errors write(2) causes: EAGAIN, EINTR, etc.
|
|
|
|
* The result may also be smaller than string.length (partial write).
|
|
|
|
* The caller should care such errors and partial write.
|
|
|
|
*
|
|
|
|
* If the write buffer is not empty, it is flushed at first.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
io_fflush(fptr);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if (n == -1) rb_sys_fail(fptr->path);
|
|
|
|
|
|
|
|
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
|
|
|
*
|
2005-01-24 14:43:12 +03:00
|
|
|
* Reads at most <i>length</i> bytes from the I/O stream, or to the
|
|
|
|
* end of file if <i>length</i> is omitted or is <code>nil</code>.
|
|
|
|
* <i>length</i> must be a non-negative integer or nil.
|
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.
|
|
|
|
*
|
|
|
|
* <code><i>ios</i>.read(0)</code> returns <code>""</code>.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* f = File.new("testfile")
|
|
|
|
* f.read(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
|
|
|
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-18 05:40:01 +04:00
|
|
|
if (fptr->enc2) {
|
|
|
|
make_readconv(fptr);
|
|
|
|
while (1) {
|
|
|
|
const char *p, *e;
|
|
|
|
int searchlen;
|
|
|
|
if (fptr->crbuf_len) {
|
|
|
|
p = fptr->crbuf+fptr->crbuf_off;
|
|
|
|
searchlen = fptr->crbuf_len;
|
|
|
|
if (0 < limit && limit < searchlen)
|
|
|
|
searchlen = limit;
|
|
|
|
e = memchr(p, delim, searchlen);
|
|
|
|
if (e) {
|
|
|
|
if (NIL_P(str))
|
|
|
|
*strp = str = rb_str_new(p, e-p+1);
|
|
|
|
else
|
|
|
|
rb_str_buf_cat(str, p, e-p+1);
|
|
|
|
fptr->crbuf_off += e-p+1;
|
|
|
|
fptr->crbuf_len -= e-p+1;
|
|
|
|
limit -= e-p+1;
|
|
|
|
*lp = limit;
|
|
|
|
return delim;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NIL_P(str))
|
|
|
|
*strp = str = rb_str_new(p, searchlen);
|
|
|
|
else
|
|
|
|
rb_str_buf_cat(str, p, searchlen);
|
|
|
|
fptr->crbuf_off += searchlen;
|
|
|
|
fptr->crbuf_len -= searchlen;
|
|
|
|
limit -= searchlen;
|
|
|
|
|
|
|
|
if (limit == 0) {
|
|
|
|
*lp = limit;
|
|
|
|
return (unsigned char)RSTRING_PTR(str)[RSTRING_LEN(str)-1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (more_char(fptr) == -1) {
|
|
|
|
*lp = limit;
|
|
|
|
return EOF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-17 23:41:39 +04:00
|
|
|
while (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
|
|
|
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)
|
|
|
|
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);
|
* 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) {
|
2006-12-29 22:21:50 +03:00
|
|
|
*lp = limit;
|
2008-08-17 23:41:39 +04:00
|
|
|
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
|
|
|
}
|
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 {
|
2002-08-28 12:05:23 +04:00
|
|
|
long 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;
|
|
|
|
i = cnt;
|
|
|
|
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 */
|
2002-03-25 17:50:40 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
* 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-03-01 04:33:17 +03:00
|
|
|
int cr = fptr->enc2 ? ENC_CODERANGE_BROKEN : 0;
|
2002-03-25 17:50:40 +03:00
|
|
|
|
2006-12-29 22:21:50 +03:00
|
|
|
for (;;) {
|
2008-01-23 21:43:51 +03:00
|
|
|
long pending = READ_DATA_PENDING_COUNT(fptr);
|
|
|
|
|
|
|
|
if (pending > 0) {
|
|
|
|
const char *p = READ_DATA_PENDING_PTR(fptr);
|
|
|
|
const char *e;
|
|
|
|
|
|
|
|
e = memchr(p, '\n', pending);
|
|
|
|
if (e) {
|
2008-01-25 18:57:32 +03:00
|
|
|
pending = 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-03-01 04:33:17 +03:00
|
|
|
if (!fptr->enc2) ENC_CODERANGE_SET(str, cr);
|
2008-01-23 21:43:51 +03:00
|
|
|
fptr->lineno++;
|
2008-03-01 11:59:04 +03:00
|
|
|
ARGF.lineno = INT2FIX(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);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (NIL_P(rs)) {
|
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-18 05:40:01 +04:00
|
|
|
else if (rs == rb_default_rs && limit < 0 && !fptr->enc2 &&
|
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 {
|
2002-03-25 17:50:40 +03:00
|
|
|
int c, newline;
|
2006-06-20 22:02:17 +04:00
|
|
|
const char *rsptr;
|
2002-08-21 19:47:54 +04:00
|
|
|
long rslen;
|
|
|
|
int rspara = 0;
|
2008-08-17 23:41:39 +04:00
|
|
|
int extra_limit = 16;
|
2002-03-25 17:50:40 +03:00
|
|
|
|
2006-08-31 14:47:44 +04:00
|
|
|
rslen = RSTRING_LEN(rs);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (rslen == 0) {
|
|
|
|
rsptr = "\n\n";
|
|
|
|
rslen = 2;
|
|
|
|
rspara = 1;
|
2002-03-25 17:50:40 +03:00
|
|
|
swallow(fptr, '\n');
|
2007-12-24 19:36:14 +03:00
|
|
|
rs = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2006-08-31 14:47:44 +04:00
|
|
|
rsptr = RSTRING_PTR(rs);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2008-08-17 23:41:39 +04:00
|
|
|
newline = (unsigned char)rsptr[rslen - 1];
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2008-08-18 05:40:01 +04:00
|
|
|
if (fptr->enc2)
|
|
|
|
enc = fptr->enc;
|
|
|
|
else
|
|
|
|
enc = io_input_encoding(fptr);
|
2008-01-23 21:43:51 +03:00
|
|
|
while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
|
2008-08-17 23:41:39 +04:00
|
|
|
const char *s, *p, *pp;
|
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-08-17 23:41:39 +04:00
|
|
|
p = s + RSTRING_LEN(str) - rslen;
|
2007-12-25 12:52:52 +03:00
|
|
|
pp = rb_enc_left_char_head(s, p, enc);
|
|
|
|
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);
|
|
|
|
pp = rb_enc_left_char_head(s, p-1, enc);
|
|
|
|
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++;
|
2008-03-01 11:59:04 +03:00
|
|
|
ARGF.lineno = INT2FIX(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
|
|
|
{
|
* 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);
|
2008-06-12 03:52:20 +04:00
|
|
|
return rb_io_getline_fast(fptr, io_read_encoding(fptr));
|
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
|
|
|
|
* given value.
|
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
|
|
|
|
* longer than the given value. 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++;
|
2008-01-03 05:29:04 +03: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-16 21:06:35 +04:00
|
|
|
if (fptr->enc2) {
|
2008-08-18 07:13:53 +04:00
|
|
|
VALUE str = Qnil;
|
|
|
|
|
2008-08-16 21:06:35 +04:00
|
|
|
if (!fptr->readconv) {
|
2008-08-18 05:40:01 +04:00
|
|
|
make_readconv(fptr);
|
2008-08-16 21:06:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (fptr->crbuf_len) {
|
2008-08-18 05:40:01 +04:00
|
|
|
r = rb_enc_precise_mbclen(fptr->crbuf+fptr->crbuf_off,
|
|
|
|
fptr->crbuf+fptr->crbuf_off+fptr->crbuf_len,
|
|
|
|
fptr->enc);
|
2008-08-16 21:06:35 +04:00
|
|
|
if (!MBCLEN_NEEDMORE_P(r))
|
|
|
|
break;
|
|
|
|
if (fptr->crbuf_len == fptr->crbuf_capa) {
|
|
|
|
rb_raise(rb_eIOError, "too long character");
|
|
|
|
}
|
|
|
|
}
|
2008-08-18 05:40:01 +04:00
|
|
|
|
|
|
|
if (more_char(fptr) == -1) {
|
|
|
|
if (fptr->crbuf_len == 0)
|
|
|
|
return Qnil;
|
|
|
|
/* return an incomplete character just before EOF */
|
2008-08-18 07:13:53 +04:00
|
|
|
return io_shift_crbuf(fptr, fptr->crbuf_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-18 05:40:01 +04:00
|
|
|
r = rb_enc_mbclen(fptr->crbuf+fptr->crbuf_off,
|
|
|
|
fptr->crbuf+fptr->crbuf_off+fptr->crbuf_len,
|
|
|
|
fptr->enc);
|
2008-08-18 07:13:53 +04:00
|
|
|
return io_shift_crbuf(fptr, r, &str);
|
2008-08-16 21:06:35 +04:00
|
|
|
}
|
2008-08-18 07:13:53 +04:00
|
|
|
return io_shift_crbuf(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);
|
|
|
|
if (!fptr->enc2) {
|
|
|
|
ENC_CODERANGE_SET(str, cr);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
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
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
* 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
|
|
|
* ios.getc => fixnum 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")
|
* 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"
|
|
|
|
* f.getc #=> "1"
|
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
|
|
|
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_getc(FILE *f)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2008-05-28 10:32:10 +04:00
|
|
|
rb_read_check(f);
|
1999-08-13 09:45:20 +04:00
|
|
|
TRAP_BEG;
|
|
|
|
c = getc(f);
|
|
|
|
TRAP_END;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
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")
|
|
|
|
* f.readchar #=> "8"
|
|
|
|
* f.readchar #=> "1"
|
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
|
|
|
|
*
|
|
|
|
* Reads a character as with <code>IO#getc</code>, but raises an
|
|
|
|
* <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);
|
|
|
|
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);
|
* 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-18 18:28:45 +04:00
|
|
|
if (fptr->enc2) {
|
|
|
|
make_readconv(fptr);
|
|
|
|
len = RSTRING_LEN(c);
|
|
|
|
if (fptr->crbuf_capa - fptr->crbuf_len < len)
|
|
|
|
rb_raise(rb_eIOError, "ungetc failed");
|
|
|
|
if (fptr->crbuf_off < len) {
|
|
|
|
MEMMOVE(fptr->crbuf+fptr->crbuf_capa-fptr->crbuf_len,
|
|
|
|
fptr->crbuf+fptr->crbuf_off,
|
|
|
|
char, fptr->crbuf_len);
|
|
|
|
fptr->crbuf_off = fptr->crbuf_capa-fptr->crbuf_len;
|
|
|
|
}
|
|
|
|
fptr->crbuf_off -= len;
|
|
|
|
fptr->crbuf_len += len;
|
|
|
|
MEMMOVE(fptr->crbuf+fptr->crbuf_off, RSTRING_PTR(c), char, len);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
|
|
|
|
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)) {
|
|
|
|
if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
|
|
|
|
if (!(ret & FD_CLOEXEC)) return Qfalse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
if (fptr && 0 <= (fd = fptr->fd)) {
|
|
|
|
if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
|
|
|
|
if (!(ret & FD_CLOEXEC)) return Qfalse;
|
|
|
|
}
|
|
|
|
return Qtrue;
|
|
|
|
#else
|
|
|
|
rb_notimplement();
|
|
|
|
return Qnil; /* not reached */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(F_SETFD) && defined(FD_CLOEXEC)
|
|
|
|
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)) {
|
|
|
|
if ((ret = fcntl(fptr->fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
|
|
|
|
if ((ret & FD_CLOEXEC) != flag) {
|
|
|
|
ret = (ret & ~FD_CLOEXEC) | flag;
|
|
|
|
ret = fcntl(fd, F_SETFD, ret);
|
|
|
|
if (ret == -1) rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
if (fptr && 0 <= (fd = fptr->fd)) {
|
|
|
|
if ((ret = fcntl(fd, F_GETFD)) == -1) rb_sys_fail(fptr->path);
|
|
|
|
if ((ret & FD_CLOEXEC) != flag) {
|
|
|
|
ret = (ret & ~FD_CLOEXEC) | flag;
|
|
|
|
ret = fcntl(fd, F_SETFD, ret);
|
|
|
|
if (ret == -1) rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
rb_notimplement();
|
|
|
|
#endif
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2004-12-23 20:53:58 +03:00
|
|
|
#define FMODE_PREP (1<<16)
|
|
|
|
#define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
|
|
|
|
#define PREP_STDIO_NAME(f) ((f)->path)
|
|
|
|
|
2008-08-18 16:06:42 +04:00
|
|
|
static void
|
|
|
|
finish_writeconv(rb_io_t *fptr, int noraise)
|
|
|
|
{
|
|
|
|
unsigned char *ds, *dp, *de;
|
|
|
|
rb_econv_result_t res;
|
|
|
|
|
|
|
|
if (!fptr->wbuf) {
|
|
|
|
unsigned char buf[1024];
|
|
|
|
int r;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
retry:
|
|
|
|
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)) {
|
|
|
|
if (!noraise)
|
|
|
|
rb_io_check_closed(fptr);
|
|
|
|
else if (fptr->fd < 0)
|
|
|
|
return;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!noraise) {
|
|
|
|
rb_econv_check_error(fptr->writeconv);
|
|
|
|
}
|
|
|
|
if (res == econv_invalid_byte_sequence ||
|
|
|
|
res == econv_undefined_conversion) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = econv_destination_buffer_full;
|
|
|
|
while (res == econv_destination_buffer_full) {
|
|
|
|
if (fptr->wbuf_len == fptr->wbuf_capa) {
|
|
|
|
io_fflush(fptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
fptr->wbuf_len += dp - ds;
|
|
|
|
if (!noraise) {
|
|
|
|
rb_econv_check_error(fptr->writeconv);
|
|
|
|
}
|
|
|
|
if (res == econv_invalid_byte_sequence ||
|
|
|
|
res == econv_undefined_conversion) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-06-09 12:48:41 +04:00
|
|
|
int ebadf = 0;
|
2008-08-18 16:06:42 +04:00
|
|
|
if (fptr->writeconv) {
|
|
|
|
finish_writeconv(fptr, noraise);
|
|
|
|
}
|
* 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) {
|
|
|
|
io_fflush(fptr);
|
2002-02-05 20:10:54 +03:00
|
|
|
}
|
2004-12-23 20:53:58 +03:00
|
|
|
if (IS_PREP_STDIO(fptr) ||
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->fd <= 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
|
|
|
return;
|
2002-02-05 10:56:31 +03:00
|
|
|
}
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->stdio_file) {
|
2004-12-30 16:49:56 +03:00
|
|
|
if (fclose(fptr->stdio_file) < 0 && !noraise) {
|
|
|
|
/* fptr->stdio_file is deallocated anyway */
|
2004-12-08 16:26:27 +03:00
|
|
|
fptr->stdio_file = 0;
|
|
|
|
fptr->fd = -1;
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (0 <= fptr->fd) {
|
2004-12-30 16:49:56 +03:00
|
|
|
if (close(fptr->fd) < 0 && !noraise) {
|
2008-06-09 12:48:41 +04:00
|
|
|
if (errno != EBADF) {
|
|
|
|
/* fptr->fd is still not closed */
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* fptr->fd is already closed. */
|
|
|
|
ebadf = 1;
|
|
|
|
}
|
2004-12-08 16:26:27 +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
|
|
|
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-06-09 12:48:41 +04:00
|
|
|
if (ebadf) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
if (fptr->crbuf) {
|
|
|
|
free(fptr->crbuf);
|
|
|
|
fptr->crbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (fptr->refcnt <= 0 || --fptr->refcnt) return 0;
|
2003-10-30 12:36:41 +03:00
|
|
|
if (fptr->path) {
|
|
|
|
free(fptr->path);
|
2004-04-07 06:51:05 +04:00
|
|
|
fptr->path = 0;
|
2003-10-30 12:36:41 +03:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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);
|
2004-12-06 15:20:29 +03:00
|
|
|
if (is_socket(fptr->fd, fptr->path)) {
|
2004-12-08 16:26:27 +03:00
|
|
|
#ifndef SHUT_RD
|
|
|
|
# define SHUT_RD 0
|
|
|
|
#endif
|
|
|
|
if (shutdown(fptr->fd, SHUT_RD) < 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(fptr->path);
|
|
|
|
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;
|
2007-11-20 06:16:53 +03:00
|
|
|
fptr_finalize(fptr, Qfalse);
|
2008-01-31 00:24:24 +03:00
|
|
|
GetOpenFile(write_io, wfptr);
|
|
|
|
if (fptr->refcnt < LONG_MAX) {
|
|
|
|
wfptr->refcnt++;
|
|
|
|
RFILE(io)->fptr = wfptr;
|
|
|
|
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);
|
2004-12-06 15:20:29 +03:00
|
|
|
if (is_socket(fptr->fd, fptr->path)) {
|
2004-12-08 16:26:27 +03:00
|
|
|
#ifndef SHUT_WR
|
|
|
|
# define SHUT_WR 1
|
|
|
|
#endif
|
|
|
|
if (shutdown(fptr->fd, SHUT_WR) < 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(fptr->path);
|
|
|
|
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);
|
2002-03-27 08:28:00 +03:00
|
|
|
if (pos == -1) rb_sys_fail(fptr->path);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2005-09-18 22:29:19 +04:00
|
|
|
TRAP_BEG;
|
2006-08-31 14:47:44 +04:00
|
|
|
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
|
2005-09-18 22:29:19 +04:00
|
|
|
TRAP_END;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (n == -1) rb_sys_fail(fptr->path);
|
|
|
|
|
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) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
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-01-09 20:44:13 +03:00
|
|
|
#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
|
* 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_BINMODE) && READ_DATA_BUFFERED(fptr)) {
|
2004-03-31 06:59:57 +04:00
|
|
|
rb_raise(rb_eIOError, "buffer already filled with text-mode content");
|
|
|
|
}
|
2004-12-08 16:26:27 +03:00
|
|
|
if (0 <= fptr->fd && setmode(fptr->fd, O_BINARY) == -1)
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
#endif
|
2007-12-21 10:02:55 +03:00
|
|
|
fptr->mode |= FMODE_BINMODE;
|
1998-01-16 15:13:05 +03:00
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2007-11-20 06:16:53 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.binmode => ios
|
|
|
|
*
|
|
|
|
* Puts <em>ios</em> into binary mode. This is useful only in
|
|
|
|
* MS-DOS/Windows environments. Once a stream is in binary mode, it
|
|
|
|
* cannot be reset to nonbinary mode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_binmode_m(VALUE io)
|
|
|
|
{
|
|
|
|
#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
|
|
|
|
VALUE write_io;
|
2007-12-23 05:01:34 +03:00
|
|
|
#endif
|
2007-11-20 06:16:53 +03:00
|
|
|
|
2007-12-23 05:01:34 +03:00
|
|
|
rb_io_binmode(io);
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__) || defined(__EMX__)
|
2007-11-20 06:16:53 +03:00
|
|
|
write_io = GetWriteIO(io);
|
|
|
|
if (write_io != io)
|
|
|
|
rb_io_binmode(write_io);
|
|
|
|
#endif
|
|
|
|
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*
|
* 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_flags_mode(int flags)
|
2003-05-09 12:12:52 +04:00
|
|
|
{
|
2004-10-05 05:37:46 +04:00
|
|
|
#ifdef O_BINARY
|
2004-10-12 10:07:01 +04:00
|
|
|
# define MODE_BINMODE(a,b) ((flags & FMODE_BINMODE) ? (b) : (a))
|
2004-10-05 05:37:46 +04:00
|
|
|
#else
|
|
|
|
# define MODE_BINMODE(a,b) (a)
|
|
|
|
#endif
|
2004-10-06 11:40:06 +04:00
|
|
|
if (flags & FMODE_APPEND) {
|
|
|
|
if ((flags & FMODE_READWRITE) == FMODE_READWRITE) {
|
|
|
|
return MODE_BINMODE("a+", "ab+");
|
|
|
|
}
|
|
|
|
return MODE_BINMODE("a", "ab");
|
|
|
|
}
|
2003-05-09 12:12:52 +04:00
|
|
|
switch (flags & FMODE_READWRITE) {
|
|
|
|
case FMODE_READABLE:
|
2004-10-05 05:37:46 +04:00
|
|
|
return MODE_BINMODE("r", "rb");
|
2003-05-09 12:12:52 +04:00
|
|
|
case FMODE_WRITABLE:
|
2004-10-05 05:37:46 +04:00
|
|
|
return MODE_BINMODE("w", "wb");
|
2003-05-09 12:12:52 +04:00
|
|
|
case FMODE_READWRITE:
|
2004-10-18 06:29:43 +04:00
|
|
|
if (flags & FMODE_CREATE) {
|
|
|
|
return MODE_BINMODE("w+", "wb+");
|
|
|
|
}
|
2004-10-05 05:37:46 +04:00
|
|
|
return MODE_BINMODE("r+", "rb+");
|
2003-05-09 12:12:52 +04:00
|
|
|
}
|
2008-08-19 16:14:02 +04:00
|
|
|
rb_raise(rb_eArgError, "invalid access modenum 0x%x", flags);
|
2004-10-05 05:37:46 +04:00
|
|
|
return NULL; /* not reached */
|
2003-05-09 12:12:52 +04:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03: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_mode_flags(const char *mode)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
int flags = 0;
|
2001-06-05 11:19:39 +04:00
|
|
|
const char *m = mode;
|
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':
|
|
|
|
flags |= FMODE_READABLE;
|
|
|
|
break;
|
|
|
|
case 'w':
|
2008-08-19 22:38:32 +04:00
|
|
|
flags |= FMODE_WRITABLE | FMODE_TRUNC | FMODE_CREATE;
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
case 'a':
|
2004-10-18 06:29:43 +04:00
|
|
|
flags |= 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:
|
* regerror.c, string.c, io.c, lib/getoptlong.rb, lib/net/imap.rb,
compile.c, sprintf.c, parse.y, ext/win32ole/win32ole.c,
ext/tk/sample/demos-en/entry3.rb, ext/tk/lib/tcltk.rb,
ext/openssl/ossl_bn.c, numeric.c, vm.c,
benchmark/bm_so_meteor_contest.rb, bignum.c, ruby.c: don't "illegal"
for non law violation context.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-21 05:31:11 +03:00
|
|
|
rb_raise(rb_eArgError, "invalid access mode %s", mode);
|
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':
|
2002-04-24 08:54:16 +04:00
|
|
|
flags |= FMODE_BINMODE;
|
|
|
|
break;
|
2007-12-12 16:23:07 +03:00
|
|
|
case '+':
|
2002-04-24 08:54:16 +04:00
|
|
|
flags |= FMODE_READWRITE;
|
|
|
|
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 ':':
|
|
|
|
return flags;
|
2002-04-24 08:54:16 +04:00
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2004-11-18 04:11:01 +03: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_modenum_flags(int mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2002-04-24 08:54:16 +04:00
|
|
|
int flags = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) {
|
2002-03-29 17:50:09 +03:00
|
|
|
case O_RDONLY:
|
1999-08-13 09:45:20 +04:00
|
|
|
flags = FMODE_READABLE;
|
|
|
|
break;
|
|
|
|
case O_WRONLY:
|
|
|
|
flags = FMODE_WRITABLE;
|
|
|
|
break;
|
|
|
|
case O_RDWR:
|
2004-10-06 11:40:06 +04:00
|
|
|
flags = FMODE_READWRITE;
|
1999-08-13 09:45:20 +04:00
|
|
|
break;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2004-10-06 11:40:06 +04:00
|
|
|
if (mode & O_APPEND) {
|
|
|
|
flags |= FMODE_APPEND;
|
|
|
|
}
|
2008-08-19 22:38:32 +04:00
|
|
|
if (mode & O_TRUNC) {
|
|
|
|
flags |= FMODE_TRUNC;
|
|
|
|
}
|
2004-10-19 14:25:23 +04:00
|
|
|
if (mode & O_CREAT) {
|
|
|
|
flags |= FMODE_CREATE;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
#ifdef O_BINARY
|
|
|
|
if (mode & O_BINARY) {
|
|
|
|
flags |= FMODE_BINMODE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2008-08-19 23:17:46 +04:00
|
|
|
static int
|
2008-08-19 22:38:32 +04:00
|
|
|
rb_io_flags_modenum(int flags)
|
2001-06-05 11:19:39 +04:00
|
|
|
{
|
2008-08-19 22:38:32 +04:00
|
|
|
int mode = 0;
|
2001-06-05 11:19:39 +04:00
|
|
|
|
2008-08-19 22:38:32 +04:00
|
|
|
switch (flags & FMODE_READWRITE) {
|
|
|
|
case FMODE_READABLE:
|
|
|
|
mode |= O_RDONLY;
|
|
|
|
break;
|
|
|
|
case FMODE_WRITABLE:
|
|
|
|
mode |= O_WRONLY;
|
|
|
|
break;
|
|
|
|
case FMODE_READWRITE:
|
|
|
|
mode |= O_RDWR;
|
|
|
|
break;
|
2001-06-05 11:19:39 +04:00
|
|
|
}
|
|
|
|
|
2008-08-19 22:38:32 +04:00
|
|
|
if (flags & FMODE_APPEND) {
|
|
|
|
mode |= O_APPEND;
|
|
|
|
}
|
|
|
|
if (flags & FMODE_TRUNC) {
|
|
|
|
mode |= O_TRUNC;
|
|
|
|
}
|
|
|
|
if (flags & FMODE_CREATE) {
|
|
|
|
mode |= O_CREAT;
|
|
|
|
}
|
2001-06-05 11:19:39 +04:00
|
|
|
#ifdef O_BINARY
|
2008-08-19 22:38:32 +04:00
|
|
|
if (flags & FMODE_BINMODE) {
|
|
|
|
mode |= 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-08-19 22:38:32 +04:00
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_io_mode_modenum(const char *mode)
|
|
|
|
{
|
|
|
|
return rb_io_flags_modenum(rb_io_mode_flags(mode));
|
2001-06-05 11:19:39 +04:00
|
|
|
}
|
|
|
|
|
2004-10-04 09:04:22 +04:00
|
|
|
#define MODENUM_MAX 4
|
|
|
|
|
2006-06-20 22:02:17 +04:00
|
|
|
static const char*
|
* 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_modenum_mode(int flags)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2004-10-06 11:40:06 +04:00
|
|
|
#ifdef O_BINARY
|
2004-10-12 10:07:01 +04:00
|
|
|
# define MODE_BINARY(a,b) ((flags & O_BINARY) ? (b) : (a))
|
2004-10-06 11:40:06 +04:00
|
|
|
#else
|
|
|
|
# define MODE_BINARY(a,b) (a)
|
|
|
|
#endif
|
|
|
|
if (flags & O_APPEND) {
|
|
|
|
if ((flags & O_RDWR) == O_RDWR) {
|
|
|
|
return MODE_BINARY("a+", "ab+");
|
|
|
|
}
|
|
|
|
return MODE_BINARY("a", "ab");
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
switch (flags & (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-08-19 16:14:02 +04:00
|
|
|
rb_raise(rb_eArgError, "invalid access modenum 0x%x", flags);
|
2004-10-06 11:40:06 +04:00
|
|
|
return NULL; /* not reached */
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
const char *p0, *p1;
|
2007-12-22 19:21:09 +03:00
|
|
|
char *enc2name;
|
|
|
|
int idx, idx2;
|
2008-03-19 18:29:09 +03:00
|
|
|
|
2008-08-16 21:06:35 +04:00
|
|
|
/* parse estr as "enc" or "enc2:enc" */
|
|
|
|
|
2008-08-20 00:20:31 +04:00
|
|
|
*enc_p = 0;
|
|
|
|
*enc2_p = 0;
|
2008-08-18 11:55:04 +04:00
|
|
|
|
2007-12-23 18:56:41 +03:00
|
|
|
p0 = strrchr(estr, ':');
|
|
|
|
if (!p0) p1 = estr;
|
|
|
|
else p1 = p0 + 1;
|
|
|
|
idx = rb_enc_find_index(p1);
|
|
|
|
if (idx >= 0) {
|
2008-08-20 00:20:31 +04:00
|
|
|
*enc_p = rb_enc_from_index(idx);
|
2007-12-23 18:56:41 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_warn("Unsupported encoding %s ignored", p1);
|
|
|
|
}
|
|
|
|
|
2008-08-20 00:20:31 +04:00
|
|
|
if (*enc_p && p0) {
|
2008-01-16 08:55:22 +03:00
|
|
|
int n = p0 - estr;
|
|
|
|
if (n > ENCODING_MAXNAMELEN) {
|
|
|
|
idx2 = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
enc2name = ALLOCA_N(char, n+1);
|
|
|
|
memcpy(enc2name, estr, n);
|
|
|
|
enc2name[n] = '\0';
|
2008-01-16 09:26:33 +03:00
|
|
|
estr = enc2name;
|
2008-01-16 08:55:22 +03:00
|
|
|
idx2 = rb_enc_find_index(enc2name);
|
|
|
|
}
|
|
|
|
if (idx2 < 0) {
|
2008-01-16 09:26:33 +03:00
|
|
|
rb_warn("Unsupported encoding %.*s ignored", n, estr);
|
2008-01-16 08:55:22 +03:00
|
|
|
}
|
|
|
|
else if (idx2 == idx) {
|
2008-01-16 09:26:33 +03:00
|
|
|
rb_warn("Ignoring internal encoding %.*s: it is identical to external encoding %s",
|
|
|
|
n, estr, p1);
|
2007-12-12 16:23:07 +03:00
|
|
|
}
|
2007-12-23 18:56:41 +03:00
|
|
|
else {
|
2008-08-20 00:20:31 +04:00
|
|
|
*enc2_p = rb_enc_from_index(idx2);
|
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);
|
|
|
|
|
|
|
|
parse_mode_enc(estr, &fptr->enc, &fptr->enc2);
|
|
|
|
}
|
|
|
|
|
2007-12-23 18:56:41 +03:00
|
|
|
void
|
|
|
|
rb_io_mode_enc(rb_io_t *fptr, const char *mode)
|
|
|
|
{
|
|
|
|
const char *p = strchr(mode, ':');
|
|
|
|
if (p) {
|
|
|
|
mode_enc(fptr, p+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-20 00:20:31 +04:00
|
|
|
static int
|
|
|
|
io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p)
|
|
|
|
{
|
|
|
|
VALUE encoding=Qnil, extenc=Qnil, intenc=Qnil;
|
|
|
|
int extracted = 0;
|
|
|
|
if (!NIL_P(opt)) {
|
|
|
|
VALUE v;
|
|
|
|
v = rb_hash_aref(opt, sym_encoding);
|
|
|
|
if (!NIL_P(v)) encoding = v;
|
|
|
|
v = rb_hash_aref(opt, sym_extenc);
|
|
|
|
if (!NIL_P(v)) extenc = v;
|
|
|
|
v = rb_hash_aref(opt, sym_intenc);
|
|
|
|
if (!NIL_P(v)) intenc = v;
|
|
|
|
}
|
|
|
|
if (!NIL_P(extenc)) {
|
|
|
|
rb_encoding *extencoding = rb_to_encoding(extenc);
|
|
|
|
extracted = 1;
|
|
|
|
*enc_p = 0;
|
|
|
|
*enc2_p = 0;
|
|
|
|
if (!NIL_P(encoding)) {
|
|
|
|
rb_warn("Ignoring encoding parameter '%s': external_encoding is used",
|
|
|
|
RSTRING_PTR(encoding));
|
|
|
|
}
|
|
|
|
if (!NIL_P(intenc)) {
|
|
|
|
rb_encoding *intencoding = rb_to_encoding(intenc);
|
|
|
|
if (extencoding == intencoding) {
|
|
|
|
rb_warn("Ignoring internal encoding '%s': it is identical to external encoding '%s'",
|
|
|
|
RSTRING_PTR(rb_inspect(intenc)),
|
|
|
|
RSTRING_PTR(rb_inspect(extenc)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*enc2_p = intencoding;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*enc_p = extencoding;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!NIL_P(intenc)) {
|
|
|
|
rb_raise(rb_eArgError, "External encoding must be specified when internal encoding is given");
|
|
|
|
}
|
|
|
|
if (!NIL_P(encoding)) {
|
|
|
|
extracted = 1;
|
|
|
|
parse_mode_enc(StringValueCStr(encoding), enc_p, enc2_p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return extracted;
|
|
|
|
}
|
|
|
|
|
2008-08-20 14:24:37 +04:00
|
|
|
typedef struct convconfig_t {
|
|
|
|
rb_encoding *enc;
|
|
|
|
rb_encoding *enc2;
|
|
|
|
} convconfig_t;
|
|
|
|
|
|
|
|
static void
|
|
|
|
rb_io_extract_modeenc(VALUE mode, VALUE opthash,
|
|
|
|
int *modenum_p, int *flags_p, convconfig_t *convconfig_p)
|
|
|
|
{
|
|
|
|
int modenum, flags;
|
|
|
|
rb_encoding *enc, *enc2;
|
|
|
|
int has_enc = 0;
|
|
|
|
|
|
|
|
enc = NULL;
|
|
|
|
enc2 = NULL;
|
|
|
|
|
|
|
|
if (NIL_P(mode)) {
|
|
|
|
flags = FMODE_READABLE;
|
|
|
|
modenum = O_RDONLY;
|
|
|
|
}
|
|
|
|
else if (FIXNUM_P(mode)) {
|
|
|
|
modenum = FIX2INT(mode);
|
|
|
|
flags = rb_io_modenum_flags(modenum);
|
|
|
|
}
|
|
|
|
else { /* xxx: Bignum, to_int */
|
|
|
|
const char *p;
|
|
|
|
SafeStringValue(mode);
|
|
|
|
p = StringValueCStr(mode);
|
|
|
|
flags = rb_io_mode_flags(p);
|
|
|
|
modenum = rb_io_flags_modenum(flags);
|
|
|
|
p = strchr(p, ':');
|
|
|
|
if (p) {
|
|
|
|
has_enc = 1;
|
|
|
|
parse_mode_enc(p+1, &enc, &enc2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NIL_P(opthash)) {
|
|
|
|
if (io_extract_encoding_option(opthash, &enc, &enc2)) {
|
|
|
|
if (has_enc) {
|
|
|
|
rb_raise(rb_eArgError, "encoding sepecified twice");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*modenum_p = modenum;
|
|
|
|
*flags_p = flags;
|
|
|
|
convconfig_p->enc = enc;
|
|
|
|
convconfig_p->enc2 = enc2;
|
|
|
|
}
|
|
|
|
|
2007-11-20 13:47:53 +03:00
|
|
|
struct sysopen_struct {
|
|
|
|
char *fname;
|
|
|
|
int flag;
|
2008-08-20 20:10:36 +04:00
|
|
|
mode_t mode;
|
2007-11-20 13:47:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
sysopen_func(void *ptr)
|
|
|
|
{
|
|
|
|
struct sysopen_struct *data = ptr;
|
|
|
|
return (VALUE)open(data->fname, data->flag, data->mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_sysopen_internal(char *fname, int flags, mode_t mode)
|
2007-11-20 13:47:53 +03:00
|
|
|
{
|
2007-11-26 04:44:23 +03:00
|
|
|
struct sysopen_struct data;
|
|
|
|
data.fname = fname;
|
|
|
|
data.flag = flags;
|
|
|
|
data.mode = mode;
|
2007-11-20 13:47:53 +03:00
|
|
|
return (int)rb_thread_blocking_region(sysopen_func, &data, RB_UBF_DFL, 0);
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static int
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_sysopen(char *fname, int flags, mode_t mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2007-11-20 13:47:53 +03:00
|
|
|
fd = rb_sysopen_internal(fname, flags, mode);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (fd < 0) {
|
|
|
|
if (errno == EMFILE || errno == ENFILE) {
|
|
|
|
rb_gc();
|
2007-11-20 13:47:53 +03:00
|
|
|
fd = rb_sysopen_internal(fname, flags, mode);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
if (fd < 0) {
|
|
|
|
rb_sys_fail(fname);
|
|
|
|
}
|
|
|
|
}
|
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 *
|
* 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_fdopen(int fd, const char *mode)
|
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
|
1999-08-13 09:45:20 +04:00
|
|
|
file = fdopen(fd, mode);
|
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
|
1999-08-13 09:45:20 +04:00
|
|
|
file = fdopen(fd, mode);
|
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
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_file_open_generic(VALUE io, const char *fname, int modenum, int flags, 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;
|
2000-03-23 11:37:35 +03:00
|
|
|
|
|
|
|
MakeOpenFile(io, fptr);
|
2008-08-20 14:24:37 +04:00
|
|
|
fptr->mode = flags;
|
|
|
|
if (convconfig) {
|
|
|
|
fptr->enc = convconfig->enc;
|
|
|
|
fptr->enc2 = convconfig->enc2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fptr->enc = NULL;
|
|
|
|
fptr->enc2 = NULL;
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
fptr->path = strdup(fname);
|
2008-08-20 14:24:37 +04:00
|
|
|
fptr->fd = rb_sysopen(fptr->path, modenum, perm);
|
2004-12-23 13:12:35 +03:00
|
|
|
io_check_tty(fptr);
|
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
|
|
|
|
rb_file_open_internal(VALUE io, const char *fname, const char *mode)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
const char *p = strchr(mode, ':');
|
|
|
|
convconfig_t convconfig;
|
|
|
|
if (p) {
|
|
|
|
parse_mode_enc(p+1, &convconfig.enc, &convconfig.enc2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
convconfig.enc = NULL;
|
|
|
|
convconfig.enc2 = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = rb_io_mode_flags(mode);
|
|
|
|
return rb_file_open_generic(io, fname,
|
2008-08-20 17:32:08 +04:00
|
|
|
rb_io_flags_modenum(flags),
|
2008-08-20 14:24:37 +04:00
|
|
|
flags,
|
|
|
|
&convconfig,
|
|
|
|
0666);
|
|
|
|
}
|
|
|
|
|
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_file_open(const char *fname, const char *mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2002-12-20 11:33:17 +03:00
|
|
|
return rb_file_open_internal(io_alloc(rb_cFile), fname, mode);
|
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;
|
2000-11-13 13:11:31 +03:00
|
|
|
#if defined DJGPP
|
2000-07-10 10:47:04 +04:00
|
|
|
status <<= 8;
|
|
|
|
#endif
|
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
|
|
|
|
close(fd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
static int
|
* 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
|
|
|
popen_exec(void *pp)
|
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();
|
2008-04-28 04:11:46 +04:00
|
|
|
return rb_exec(p->execp);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
2008-04-28 04:11:46 +04:00
|
|
|
pipe_open(struct rb_exec_arg *eargp, VALUE prog, const char *mode)
|
2004-02-16 09:45:32 +03:00
|
|
|
{
|
|
|
|
int modef = rb_io_mode_flags(mode);
|
|
|
|
int 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;
|
|
|
|
#elif defined(_WIN32)
|
|
|
|
int openmode = rb_io_mode_modenum(mode);
|
2007-08-07 07:31:54 +04:00
|
|
|
const char *exename = NULL;
|
2008-01-16 08:55:22 +03:00
|
|
|
volatile VALUE cmdbuf;
|
2008-05-12 18:15:32 +04: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;
|
* 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.modef = modef;
|
|
|
|
arg.pair[0] = arg.pair[1] = -1;
|
2007-11-20 06:16:53 +03:00
|
|
|
arg.write_pair[0] = arg.write_pair[1] = -1;
|
2007-04-04 12:08:46 +04:00
|
|
|
switch (modef & (FMODE_READABLE|FMODE_WRITABLE)) {
|
|
|
|
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);
|
2008-04-28 04:11:46 +04:00
|
|
|
pid = rb_fork(&status, popen_exec, &arg, arg.execp->redirect_fds);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
else {
|
2007-08-04 23:56:27 +04:00
|
|
|
fflush(stdin); /* is it really needed? */
|
|
|
|
rb_io_flush(rb_stdout);
|
|
|
|
rb_io_flush(rb_stderr);
|
2008-04-24 18:46:39 +04: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]);
|
2007-11-20 06:16:53 +03:00
|
|
|
if ((modef & (FMODE_READABLE|FMODE_WRITABLE)) == (FMODE_READABLE|FMODE_WRITABLE)) {
|
|
|
|
close(arg.write_pair[0]);
|
|
|
|
close(arg.write_pair[1]);
|
|
|
|
}
|
2004-11-30 17:49:18 +03:00
|
|
|
errno = e;
|
2004-11-02 08:33:11 +03:00
|
|
|
rb_sys_fail(cmd);
|
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 ((modef & FMODE_READABLE) && (modef & FMODE_WRITABLE)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
else if (modef & FMODE_READABLE) {
|
|
|
|
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) {
|
2008-01-16 08:55:22 +03:00
|
|
|
volatile VALUE argbuf;
|
|
|
|
char **args;
|
2004-02-16 09:45:32 +03:00
|
|
|
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;
|
2007-08-07 07:31:54 +04:00
|
|
|
exename = cmd;
|
2008-01-16 08:55:22 +03:00
|
|
|
cmdbuf = rb_str_tmp_new(rb_w32_argv_size(args));
|
|
|
|
cmd = rb_w32_join_argv(RSTRING_PTR(cmdbuf), args);
|
2008-01-16 12:03:12 +03:00
|
|
|
rb_str_resize(argbuf, 0);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
2008-05-12 18:15:32 +04:00
|
|
|
if (eargp) {
|
|
|
|
rb_exec_arg_fixup(eargp);
|
|
|
|
rb_run_exec_options(eargp, &sarg);
|
|
|
|
}
|
2007-11-20 07:04:51 +03:00
|
|
|
while ((pid = rb_w32_pipe_exec(cmd, exename, openmode, &fd, &write_fd)) == -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)
|
|
|
|
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)
|
|
|
|
rb_run_exec_options(&sarg, NULL);
|
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);
|
|
|
|
rb_run_exec_options(eargp, &sarg);
|
|
|
|
}
|
2007-04-04 05:17:34 +04:00
|
|
|
fp = popen(cmd, mode);
|
2008-05-12 18:15:32 +04:00
|
|
|
if (eargp)
|
|
|
|
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;
|
2004-12-23 13:12:35 +03:00
|
|
|
fptr->mode = modef | FMODE_SYNC|FMODE_DUPLEX;
|
2007-12-21 06:29:54 +03:00
|
|
|
rb_io_mode_enc(fptr, mode);
|
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;
|
|
|
|
write_fptr->mode = (modef & ~FMODE_READABLE)| FMODE_SYNC|FMODE_DUPLEX;
|
|
|
|
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
|
|
|
|
pipe_open_v(int argc, VALUE *argv, const char *mode)
|
|
|
|
{
|
2008-04-28 04:11:46 +04:00
|
|
|
VALUE prog;
|
|
|
|
struct rb_exec_arg earg;
|
|
|
|
prog = rb_exec_arg_init(argc, argv, Qfalse, &earg);
|
|
|
|
return pipe_open(&earg, prog, mode);
|
2007-08-04 23:56:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
pipe_open_s(VALUE prog, const char *mode)
|
|
|
|
{
|
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-04-28 04:11:46 +04:00
|
|
|
return pipe_open(0, 0, mode);
|
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);
|
|
|
|
return pipe_open(&earg, prog, mode);
|
2007-08-04 23:56:27 +04:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-06-29 05:17:39 +04:00
|
|
|
* IO.popen(cmd, mode="r") => io
|
|
|
|
* IO.popen(cmd, mode="r") {|io| block } => obj
|
|
|
|
*
|
|
|
|
* 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
|
2004-06-29 05:17:39 +04:00
|
|
|
* <code>IO</code> object. If _cmd_ is a +String+
|
2003-12-27 03:44:05 +03:00
|
|
|
* ``<code>-</code>'', then a new instance of Ruby is started as the
|
2004-06-29 05:17:39 +04:00
|
|
|
* subprocess. If <i>cmd</i> is an +Array+ of +String+, then it will
|
2008-04-24 18:46:39 +04:00
|
|
|
* be used as the subprocess's +argv+ bypassing a shell.
|
|
|
|
* The array can contains a hash at first for environments and
|
|
|
|
* a hash at last for options similar to <code>spawn</code>. The default
|
2004-06-29 05:17:39 +04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Raises exceptions which <code>IO::pipe</code> and
|
|
|
|
* <code>Kernel::system</code> raise.
|
|
|
|
*
|
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>.
|
|
|
|
* 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
|
|
|
|
* puts "Parent is #{Process.pid}"
|
2004-06-29 05:17:39 +04:00
|
|
|
* IO.popen("date") { |f| puts f.gets }
|
2003-12-27 03:44:05 +03:00
|
|
|
* IO.popen("-") {|f| $stderr.puts "#{Process.pid} is here, f is #{f}"}
|
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"]
|
|
|
|
* Parent is 26166
|
|
|
|
* Wed Apr 9 08:53:52 CDT 2003
|
|
|
|
* 26169 is here, f is
|
|
|
|
* 26166 is here, f is #<IO:0x401b3d44>
|
2006-03-28 05:50:11 +04:00
|
|
|
* #<Process::Status: pid=26166,exited(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
|
|
|
{
|
2006-06-20 22:02:17 +04:00
|
|
|
const char *mode;
|
2004-02-16 09:45:32 +03:00
|
|
|
VALUE pname, pmode, port, tmp;
|
2000-03-23 11:37:35 +03:00
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
if (rb_scan_args(argc, argv, "11", &pname, &pmode) == 1) {
|
|
|
|
mode = "r";
|
|
|
|
}
|
|
|
|
else if (FIXNUM_P(pmode)) {
|
2004-10-06 11:40:06 +04:00
|
|
|
mode = rb_io_modenum_mode(FIX2INT(pmode));
|
2000-03-23 11:37:35 +03:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
else {
|
2008-01-28 06:32:27 +03:00
|
|
|
mode = StringValueCStr(pmode);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
tmp = rb_check_array_type(pname);
|
|
|
|
if (!NIL_P(tmp)) {
|
2008-01-16 08:55:22 +03:00
|
|
|
tmp = rb_ary_dup(tmp);
|
|
|
|
RBASIC(tmp)->klass = 0;
|
|
|
|
port = pipe_open_v(RARRAY_LEN(tmp), RARRAY_PTR(tmp), mode);
|
2008-01-16 12:03:12 +03:00
|
|
|
rb_ary_clear(tmp);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(pname);
|
2007-08-04 23:56:27 +04:00
|
|
|
port = pipe_open_s(pname, mode);
|
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,
|
|
|
|
VALUE *fname_p, int *modenum_p, int *flags_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-08-20 14:24:37 +04:00
|
|
|
int modenum, flags;
|
2008-08-20 20:10:36 +04:00
|
|
|
mode_t perm;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2008-08-18 20:04:09 +04:00
|
|
|
if (0 < argc) {
|
|
|
|
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
|
|
|
|
if (!NIL_P(opt)) {
|
|
|
|
argc -= 1;
|
|
|
|
}
|
2008-06-17 01:31:56 +04:00
|
|
|
}
|
|
|
|
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_scan_args(argc, argv, "12", &fname, &vmode, &vperm);
|
2008-06-17 01:31:56 +04:00
|
|
|
#if defined _WIN32 || defined __APPLE__
|
|
|
|
{
|
2008-06-18 10:07:38 +04:00
|
|
|
static rb_encoding *fs_encoding;
|
|
|
|
rb_encoding *fname_encoding = rb_enc_get(fname);
|
2008-06-17 01:31:56 +04:00
|
|
|
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_transcode(fname, fs_enc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2004-04-07 10:30:15 +04:00
|
|
|
FilePathValue(fname);
|
2008-08-20 14:24:37 +04:00
|
|
|
|
2008-08-20 15:16:59 +04:00
|
|
|
rb_io_extract_modeenc(vmode, opt, &modenum, &flags, 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;
|
|
|
|
*modenum_p = modenum;
|
|
|
|
*flags_p = flags;
|
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;
|
|
|
|
int modenum, flags;
|
|
|
|
convconfig_t convconfig;
|
2008-08-20 20:10:36 +04:00
|
|
|
mode_t perm;
|
2008-08-20 15:16:59 +04:00
|
|
|
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_scan_open_args(argc, argv, &fname, &modenum, &flags, &convconfig, &perm);
|
|
|
|
rb_file_open_generic(io, RSTRING_PTR(fname), modenum, flags, &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
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.open(fd, mode_string="r" ) => io
|
|
|
|
* IO.open(fd, mode_string="r" ) {|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
|
|
|
|
* <code>IO::new</code>. If the optional code block is given, it will
|
|
|
|
* be passed <i>io</i> as an argument, and the IO object will
|
|
|
|
* automatically be closed when the block terminates. In this instance,
|
|
|
|
* <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-06-06 20:26:05 +04:00
|
|
|
int flags, fd;
|
2008-08-20 20:10:36 +04:00
|
|
|
mode_t perm;
|
2004-10-06 19:10:43 +04:00
|
|
|
char *path;
|
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
|
|
|
|
|
|
|
if (NIL_P(vmode)) flags = O_RDONLY;
|
2004-03-15 05:27:29 +03:00
|
|
|
else if (FIXNUM_P(vmode)) flags = FIX2INT(vmode);
|
2002-05-23 09:35:32 +04:00
|
|
|
else {
|
2003-06-23 10:52:39 +04:00
|
|
|
SafeStringValue(vmode);
|
2008-01-28 06:32:27 +03:00
|
|
|
flags = rb_io_mode_modenum(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);
|
|
|
|
path = RSTRING_PTR(fname);
|
2008-08-20 20:10:36 +04:00
|
|
|
fd = rb_sysopen(path, flags, perm);
|
2002-05-23 09:35:32 +04:00
|
|
|
return INT2NUM(fd);
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-01-05 06:35:13 +03:00
|
|
|
* open(path [, mode_enc [, perm]] ) => io or nil
|
|
|
|
* open(path [, mode_enc [, perm]] ) {|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 {
|
2004-04-07 06:51:05 +04:00
|
|
|
char *str = StringValuePtr(tmp);
|
|
|
|
if (str && str[0] == '|') {
|
2006-08-31 14:47:44 +04:00
|
|
|
argv[0] = rb_str_new(str+1, RSTRING_LEN(tmp)-1);
|
2004-10-31 20:37:52 +03:00
|
|
|
OBJ_INFECT(argv[0], tmp);
|
|
|
|
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-08-20 18:56:23 +04:00
|
|
|
rb_io_open(const char *fname, VALUE mode, VALUE opt)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2008-08-20 18:56:23 +04:00
|
|
|
int modenum, flags;
|
|
|
|
convconfig_t convconfig;
|
|
|
|
rb_io_extract_modeenc(mode, opt, &modenum, &flags, &convconfig);
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
if (fname[0] == '|') {
|
2004-11-02 08:33:11 +03:00
|
|
|
VALUE cmd = rb_str_new2(fname+1);
|
2008-08-20 20:32:12 +04:00
|
|
|
return pipe_open_s(cmd, rb_io_modenum_mode(modenum)); /* xxx: convconfig ignored */
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-08-20 18:56:23 +04:00
|
|
|
return rb_file_open_generic(io_alloc(rb_cFile), fname,
|
|
|
|
modenum, flags, &convconfig, 0666);
|
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\"",
|
2004-12-23 20:53:58 +03:00
|
|
|
PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
|
|
|
|
rb_io_flags_mode(orig->mode));
|
|
|
|
}
|
|
|
|
}
|
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) {
|
|
|
|
io_fflush(orig);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2003-05-21 21:42:56 +04:00
|
|
|
if (fptr->mode & 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
|
|
|
io_fflush(fptr);
|
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;
|
|
|
|
if (fptr->path) free(fptr->path);
|
|
|
|
if (orig->path) fptr->path = strdup(orig->path);
|
|
|
|
else fptr->path = 0;
|
|
|
|
fptr->finalize = orig->finalize;
|
|
|
|
|
* 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)
|
|
|
|
rb_sys_fail(orig->path);
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
rb_sys_fail(orig->path);
|
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) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
if (io_seek(orig, pos, SEEK_SET) < 0) {
|
|
|
|
rb_sys_fail(orig->path);
|
|
|
|
}
|
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-08-20 17:32:08 +04:00
|
|
|
int modenum;
|
* 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-01-28 06:32:27 +03:00
|
|
|
int flags = rb_io_mode_flags(StringValueCStr(nmode));
|
2004-12-23 20:53:58 +03:00
|
|
|
if (IS_PREP_STDIO(fptr) &&
|
2006-07-02 06:25:11 +04:00
|
|
|
((fptr->mode & FMODE_READWRITE) & (flags & FMODE_READWRITE)) !=
|
|
|
|
(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\"",
|
2004-12-23 20:53:58 +03:00
|
|
|
PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
|
|
|
|
rb_io_flags_mode(flags));
|
|
|
|
}
|
|
|
|
fptr->mode = flags;
|
2007-12-23 19:48:28 +03:00
|
|
|
rb_io_mode_enc(fptr, StringValueCStr(nmode));
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
|
2000-07-06 11:21:26 +04:00
|
|
|
if (fptr->path) {
|
|
|
|
free(fptr->path);
|
|
|
|
fptr->path = 0;
|
|
|
|
}
|
|
|
|
|
2008-01-28 06:32:27 +03:00
|
|
|
fptr->path = strdup(StringValueCStr(fname));
|
2008-08-20 17:32:08 +04:00
|
|
|
modenum = rb_io_flags_modenum(fptr->mode);
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->fd < 0) {
|
2008-08-20 17:32:08 +04:00
|
|
|
fptr->fd = rb_sysopen(fptr->path, modenum, 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) {
|
|
|
|
io_fflush(fptr);
|
|
|
|
}
|
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-08-20 17:32:08 +04:00
|
|
|
if (freopen(fptr->path, rb_io_modenum_mode(modenum), fptr->stdio_file) == 0) {
|
2004-12-08 16:26:27 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
|
|
|
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-01-28 06:32:27 +03:00
|
|
|
rb_warn("setvbuf() can't be honoured for %s", fptr->path);
|
2001-05-02 08:22:21 +04:00
|
|
|
#endif
|
2004-12-08 16:26:27 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (close(fptr->fd) < 0)
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
fptr->fd = -1;
|
2008-08-20 17:32:08 +04:00
|
|
|
fptr->fd = rb_sysopen(fptr->path, modenum, 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;
|
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;
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->pid = orig->pid;
|
|
|
|
fptr->lineno = orig->lineno;
|
|
|
|
if (orig->path) fptr->path = strdup(orig->path);
|
|
|
|
fptr->finalize = orig->finalize;
|
|
|
|
|
* 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;
|
|
|
|
io_seek(fptr, io_tell(orig), 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));
|
|
|
|
rb_str_buf_append(str, rb_default_rs);
|
|
|
|
rb_io_write(rb_stdout, str);
|
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) {
|
|
|
|
fwrite(mesg, sizeof(char), len, stderr);
|
|
|
|
}
|
|
|
|
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
|
* 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
|
|
|
prep_io(int fd, int mode, 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-08-20 13:33:55 +04:00
|
|
|
mode |= 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
|
2004-12-23 21:06:19 +03:00
|
|
|
fp->mode = mode;
|
2005-02-07 17:18:41 +03:00
|
|
|
io_check_tty(fp);
|
2004-12-23 21:06:19 +03:00
|
|
|
if (path) fp->path = strdup(path);
|
|
|
|
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2007-09-29 00:29:32 +04:00
|
|
|
VALUE
|
|
|
|
rb_io_fdopen(int fd, int mode, const char *path)
|
|
|
|
{
|
|
|
|
VALUE klass = rb_cIO;
|
|
|
|
|
|
|
|
if (path && strcmp(path, "-")) klass = rb_cFile;
|
|
|
|
return prep_io(fd, rb_io_modenum_flags(mode), klass, path);
|
|
|
|
}
|
|
|
|
|
2004-12-23 21:06:19 +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
|
|
|
prep_stdio(FILE *f, int mode, 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;
|
2004-12-23 21:06:19 +03:00
|
|
|
VALUE io = prep_io(fileno(f), mode|FMODE_PREP, klass, path);
|
|
|
|
|
|
|
|
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-08-20 17:32:08 +04:00
|
|
|
int modenum = rb_io_flags_modenum(fptr->mode);
|
|
|
|
fptr->stdio_file = rb_fdopen(fptr->fd, rb_io_modenum_mode(modenum));
|
2004-12-08 16:26:27 +03:00
|
|
|
}
|
|
|
|
return fptr->stdio_file;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.new(fd, mode) => 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
|
|
|
|
* <code>IO::for_fd</code>.
|
|
|
|
*
|
|
|
|
* puts IO.new($stdout).fileno # => 1
|
|
|
|
*
|
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
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
2004-02-25 15:17:39 +03:00
|
|
|
VALUE fnum, mode, orig;
|
* 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, *ofp = NULL;
|
2008-08-20 20:10:36 +04:00
|
|
|
int fd, flags, modenum = O_RDONLY;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2003-03-25 06:11:27 +03:00
|
|
|
rb_secure(4);
|
2002-04-01 11:39:09 +04:00
|
|
|
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
|
|
|
if (argc == 2) {
|
2003-06-23 10:52:39 +04:00
|
|
|
if (FIXNUM_P(mode)) {
|
2008-08-20 20:10:36 +04:00
|
|
|
modenum = FIX2LONG(mode);
|
2003-06-23 10:52:39 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(mode);
|
2008-08-20 20:10:36 +04:00
|
|
|
modenum = rb_io_mode_modenum(StringValueCStr(mode));
|
2003-06-23 10:52:39 +04:00
|
|
|
}
|
2002-04-01 11:39:09 +04:00
|
|
|
}
|
2004-11-26 08:30:45 +03:00
|
|
|
orig = rb_io_check_io(fnum);
|
|
|
|
if (NIL_P(orig)) {
|
|
|
|
fd = NUM2INT(fnum);
|
2008-04-24 18:46:39 +04:00
|
|
|
UPDATE_MAXFD(fd);
|
2004-11-26 09:27:45 +03:00
|
|
|
if (argc != 2) {
|
2002-04-01 11:39:09 +04:00
|
|
|
#if defined(HAVE_FCNTL) && defined(F_GETFL)
|
2008-08-20 20:10:36 +04:00
|
|
|
modenum = fcntl(fd, F_GETFL);
|
|
|
|
if (modenum == -1) rb_sys_fail(0);
|
2002-04-01 11:39:09 +04:00
|
|
|
#endif
|
2004-11-26 09:27:45 +03:00
|
|
|
}
|
2004-02-25 15:17:39 +03:00
|
|
|
MakeOpenFile(io, 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
|
|
|
fp->fd = fd;
|
2008-08-20 20:10:36 +04:00
|
|
|
fp->mode = rb_io_modenum_flags(modenum);
|
2004-12-23 13:12:35 +03:00
|
|
|
io_check_tty(fp);
|
2004-02-25 15:17:39 +03:00
|
|
|
}
|
2004-11-29 09:09:40 +03:00
|
|
|
else if (RFILE(io)->fptr) {
|
|
|
|
rb_raise(rb_eRuntimeError, "reinitializing IO");
|
|
|
|
}
|
2004-02-25 15:17:39 +03:00
|
|
|
else {
|
2004-11-26 09:27:45 +03:00
|
|
|
GetOpenFile(orig, ofp);
|
|
|
|
if (ofp->refcnt == LONG_MAX) {
|
|
|
|
VALUE s = rb_inspect(orig);
|
2008-01-28 06:32:27 +03:00
|
|
|
rb_raise(rb_eIOError, "too many shared IO for %s", StringValueCStr(s));
|
2004-11-26 09:27:45 +03:00
|
|
|
}
|
2004-02-25 15:17:39 +03:00
|
|
|
if (argc == 2) {
|
2008-08-20 20:10:36 +04:00
|
|
|
flags = rb_io_modenum_flags(modenum);
|
|
|
|
if ((ofp->mode ^ flags) & (FMODE_READWRITE|FMODE_BINMODE)) {
|
2004-02-25 15:17:39 +03:00
|
|
|
if (FIXNUM_P(mode)) {
|
2008-08-20 20:10:36 +04:00
|
|
|
rb_raise(rb_eArgError, "incompatible mode 0x%x", modenum);
|
2004-02-25 15:17:39 +03:00
|
|
|
}
|
|
|
|
else {
|
2006-08-31 14:47:44 +04:00
|
|
|
rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING_PTR(mode));
|
2004-02-25 15:17:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ofp->refcnt++;
|
|
|
|
RFILE(io)->fptr = ofp;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
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:
|
|
|
|
* File.new(filename, mode="r") => file
|
|
|
|
* File.new(filename [, mode [, perm]]) => 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
|
|
|
|
* <code>File</code> object. 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+). Optional
|
|
|
|
* permission bits may be given in _perm_. These mode and permission
|
|
|
|
* bits are platform dependent; on Unix systems, see
|
|
|
|
* <code>open(2)</code> for details.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.new(fd, mode_string) => 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
|
|
|
|
* integer file descriptor and mode string. See also
|
|
|
|
* <code>IO#fileno</code> and <code>IO::for_fd</code>.
|
2004-06-29 05:17:39 +04: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
|
|
|
|
*/
|
|
|
|
|
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:
|
|
|
|
* IO.for_fd(fd, mode) => io
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +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->lineno);
|
|
|
|
rb_gc_mark(p->argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
p->lineno = Qnil;
|
|
|
|
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
|
2008-03-01 11:59:04 +03:00
|
|
|
#define filename ARGF.filename
|
|
|
|
#define current_file ARGF.current_file
|
|
|
|
#define gets_lineno ARGF.gets_lineno
|
|
|
|
#define init_p ARGF.init_p
|
|
|
|
#define next_p ARGF.next_p
|
|
|
|
#define lineno ARGF.lineno
|
|
|
|
#define ruby_inplace_mode ARGF.inplace
|
|
|
|
#define argf_binmode ARGF.binmode
|
|
|
|
#define argf_enc ARGF.enc
|
|
|
|
#define argf_enc2 ARGF.enc2
|
|
|
|
#define rb_argv ARGF.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);
|
|
|
|
rb_argv = rb_obj_dup(rb_argv);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
gets_lineno = NUM2INT(val);
|
|
|
|
lineno = INT2FIX(gets_lineno);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_lineno(VALUE argf)
|
|
|
|
{
|
|
|
|
return lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
* 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
|
|
|
return rb_funcall3(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() \
|
|
|
|
(current_file == rb_stdin && TYPE(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
|
|
|
|
|
|
|
if (init_p == 0) {
|
2008-03-01 11:59:04 +03:00
|
|
|
if (!NIL_P(rb_argv) && RARRAY_LEN(rb_argv) > 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
next_p = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next_p = -1;
|
|
|
|
}
|
|
|
|
init_p = 1;
|
|
|
|
gets_lineno = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_p == 1) {
|
|
|
|
next_p = 0;
|
2003-12-26 20:05:20 +03:00
|
|
|
retry:
|
2006-09-02 18:42:08 +04:00
|
|
|
if (RARRAY_LEN(rb_argv) > 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
filename = rb_ary_shift(rb_argv);
|
2008-01-28 06:32:27 +03:00
|
|
|
fn = StringValueCStr(filename);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (strlen(fn) == 1 && fn[0] == '-') {
|
|
|
|
current_file = rb_stdin;
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ruby_inplace_mode) {
|
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 {
|
2004-12-23 21:06:19 +03:00
|
|
|
int fr = rb_sysopen(fn, O_RDONLY, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ruby_inplace_mode) {
|
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);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (*ruby_inplace_mode) {
|
|
|
|
str = rb_str_new2(fn);
|
2000-08-25 12:26:06 +04:00
|
|
|
#ifdef NO_LONG_FNAME
|
1999-01-20 07:59:39 +03:00
|
|
|
ruby_add_suffix(str, ruby_inplace_mode);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2000-04-10 09:48:43 +04:00
|
|
|
rb_str_cat2(str, ruby_inplace_mode);
|
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));
|
|
|
|
fr = rb_sysopen(RSTRING_PTR(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
|
|
|
|
}
|
2004-12-23 21:06:19 +03:00
|
|
|
fw = rb_sysopen(fn, 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) {
|
2004-12-23 21:06:19 +03:00
|
|
|
fchown(fw, st.st_uid, st.st_gid);
|
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
|
|
|
}
|
2004-12-23 21:06:19 +03:00
|
|
|
current_file = prep_io(fr, FMODE_READABLE, rb_cFile, fn);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2007-12-24 21:17:35 +03:00
|
|
|
if (argf_binmode) rb_io_binmode(current_file);
|
|
|
|
if (argf_enc) {
|
|
|
|
rb_io_t *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(current_file, fptr);
|
|
|
|
fptr->enc = argf_enc;
|
|
|
|
fptr->enc2 = argf_enc2;
|
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 {
|
2004-10-19 14:25:23 +04:00
|
|
|
next_p = 1;
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
2003-12-26 20:05:20 +03:00
|
|
|
else if (next_p == -1) {
|
|
|
|
current_file = rb_stdin;
|
|
|
|
filename = rb_str_new2("-");
|
|
|
|
if (ruby_inplace_mode) {
|
|
|
|
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()) {
|
2007-08-14 15:03:29 +04:00
|
|
|
line = rb_funcall3(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) {
|
|
|
|
line = rb_io_gets(current_file);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
line = rb_io_getline(argc, argv, current_file);
|
|
|
|
}
|
|
|
|
if (NIL_P(line) && next_p != -1) {
|
|
|
|
argf_close(current_file);
|
|
|
|
next_p = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2003-02-04 10:27:43 +03:00
|
|
|
if (!NIL_P(line)) {
|
|
|
|
gets_lineno++;
|
|
|
|
lineno = INT2FIX(gets_lineno);
|
|
|
|
}
|
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;
|
|
|
|
return lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
argf_lineno_setter(VALUE val, ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
VALUE argf = *var;
|
|
|
|
int n = NUM2INT(val);
|
|
|
|
gets_lineno = n;
|
|
|
|
lineno = INT2FIX(n);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
* would not be longer than the given value. 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);
|
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;
|
1999-08-13 09:45:20 +04:00
|
|
|
line = rb_io_gets(current_file);
|
1999-01-20 07:59:39 +03:00
|
|
|
if (NIL_P(line) && next_p != -1) {
|
2007-08-14 15:03:29 +04:00
|
|
|
rb_io_close(current_file);
|
1999-01-20 07:59:39 +03:00
|
|
|
next_p = 1;
|
|
|
|
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)) {
|
|
|
|
gets_lineno++;
|
|
|
|
lineno = INT2FIX(gets_lineno);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2007-08-04 23:56:27 +04:00
|
|
|
port = pipe_open_s(str, "r");
|
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;
|
1998-01-16 15:13:05 +03:00
|
|
|
fd_set *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;
|
|
|
|
}
|
2005-06-03 18:23:17 +04:00
|
|
|
rp = rb_fd_ptr(&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
|
|
|
}
|
2005-06-03 18:23:17 +04:00
|
|
|
wp = rb_fd_ptr(&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
|
|
|
}
|
2005-06-03 18:23:17 +04:00
|
|
|
ep = rb_fd_ptr(&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++;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
n = rb_thread_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;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(p->fdsets) / sizeof(p->fdsets[0]); ++i)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(args.fdsets) / sizeof(args.fdsets[0]); ++i)
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-03-28 12:43:25 +04:00
|
|
|
#if !defined(MSDOS) && !defined(__human68k__)
|
2000-11-27 12:23:38 +03: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
|
|
|
io_cntl(int fd, int cmd, long narg, int io_p)
|
2000-11-27 12:23:38 +03:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL
|
|
|
|
TRAP_BEG;
|
|
|
|
# if defined(__CYGWIN__)
|
|
|
|
retval = io_p?ioctl(fd, cmd, (void*)narg):fcntl(fd, cmd, narg);
|
|
|
|
# else
|
|
|
|
retval = io_p?ioctl(fd, cmd, narg):fcntl(fd, cmd, narg);
|
|
|
|
# endif
|
|
|
|
TRAP_END;
|
|
|
|
#else
|
|
|
|
if (!io_p) {
|
|
|
|
rb_notimplement();
|
|
|
|
}
|
|
|
|
TRAP_BEG;
|
|
|
|
retval = ioctl(fd, cmd, narg);
|
|
|
|
TRAP_END;
|
|
|
|
#endif
|
|
|
|
return retval;
|
|
|
|
}
|
2001-03-28 12:43:25 +04:00
|
|
|
#endif
|
2000-11-27 12:23:38 +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_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#if !defined(MSDOS) && !defined(__human68k__)
|
1999-10-16 14:33:06 +04:00
|
|
|
int 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);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (retval < 0) rb_sys_fail(fptr->path);
|
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) {
|
|
|
|
if (narg & O_NONBLOCK) {
|
|
|
|
fptr->mode |= FMODE_WSPLIT_INITIALIZED;
|
|
|
|
fptr->mode &= ~FMODE_WSPLIT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fptr->mode &= ~(FMODE_WSPLIT_INITIALIZED|FMODE_WSPLIT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
return INT2NUM(retval);
|
|
|
|
#else
|
|
|
|
rb_notimplement();
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qnil; /* not reached */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
#ifdef HAVE_FCNTL
|
|
|
|
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);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
|
|
|
rb_notimplement();
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qnil; /* not reached */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-08-09 11:35:01 +04:00
|
|
|
#if defined(HAVE_SYSCALL) && !defined(__CHECKER__)
|
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");
|
2007-02-13 09:06:30 +03:00
|
|
|
if (argc > sizeof(arg) / sizeof(arg[0]))
|
|
|
|
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++;
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
TRAP_BEG;
|
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 */
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
TRAP_END;
|
1999-08-13 09:45:20 +04:00
|
|
|
if (retval < 0) rb_sys_fail(0);
|
|
|
|
return INT2NUM(retval);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
|
|
|
rb_notimplement();
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qnil; /* not reached */
|
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
|
2007-12-24 21:17:35 +03:00
|
|
|
io_encoding_set(rb_io_t *fptr, int argc, VALUE v1, VALUE v2)
|
|
|
|
{
|
2008-01-10 04:54:43 +03:00
|
|
|
if (NIL_P(v2)) argc = 1;
|
2007-12-24 21:17:35 +03:00
|
|
|
if (argc == 2) {
|
|
|
|
fptr->enc2 = rb_to_encoding(v1);
|
|
|
|
fptr->enc = rb_to_encoding(v2);
|
2008-08-18 16:06:42 +04:00
|
|
|
clear_codeconv(fptr);
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
|
|
|
else if (argc == 1) {
|
2008-01-10 09:44:30 +03:00
|
|
|
if (NIL_P(v1)) {
|
2008-01-10 09:42:49 +03:00
|
|
|
fptr->enc = 0;
|
2008-08-18 11:55:04 +04:00
|
|
|
fptr->enc2 = 0;
|
2008-08-18 16:06:42 +04:00
|
|
|
clear_codeconv(fptr);
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
|
|
|
else {
|
2008-01-10 09:42:49 +03:00
|
|
|
VALUE tmp = rb_check_string_type(v1);
|
|
|
|
if (!NIL_P(tmp)) {
|
|
|
|
mode_enc(fptr, StringValueCStr(tmp));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fptr->enc = rb_to_encoding(v1);
|
2008-08-18 11:55:04 +04:00
|
|
|
fptr->enc2 = 0;
|
2008-08-18 16:06:42 +04:00
|
|
|
clear_codeconv(fptr);
|
2008-01-10 09:42:49 +03:00
|
|
|
}
|
2007-12-24 21:17:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2008-01-05 06:35:13 +03:00
|
|
|
* IO.pipe -> [read_io, write_io]
|
|
|
|
* IO.pipe(ext_enc) -> [read_io, write_io]
|
|
|
|
* IO.pipe("ext_enc:int_enc") -> [read_io, write_io]
|
|
|
|
* IO.pipe(ext_enc, int_enc) -> [read_io, write_io]
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
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-01-05 06:35:13 +03:00
|
|
|
* <code>[</code> <i>read_io</i>, <i>write_io</i> <code>]</code>. Not
|
2003-12-27 03:44:05 +03:00
|
|
|
* 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.
|
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
|
|
|
{
|
2007-12-23 19:48:28 +03:00
|
|
|
#ifdef __human68k__
|
|
|
|
rb_notimplement();
|
|
|
|
return Qnil; /* not reached */
|
|
|
|
#else
|
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;
|
|
|
|
rb_io_t *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
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);
|
|
|
|
io_encoding_set(fptr, argc, v1, v2);
|
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);
|
|
|
|
}
|
|
|
|
rb_io_synchronized(RFILE(w)->fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-07-04 08:17:26 +04:00
|
|
|
return rb_assoc_new(r, w);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
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-20 18:56:23 +04:00
|
|
|
arg->io = rb_io_open(RSTRING_PTR(argv[0]), INT2NUM(O_RDONLY), Qnil);
|
2007-12-23 19:02:46 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
|
|
|
|
if (NIL_P(opt)) goto no_key;
|
2008-08-20 20:57:46 +04:00
|
|
|
arg->argc--;
|
2007-12-23 19:02:46 +03:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
v = rb_convert_type(v, T_ARRAY, "Array", "to_ary");
|
|
|
|
args = rb_ary_new2(RARRAY_LEN(v)+1);
|
|
|
|
rb_ary_push(args, argv[0]);
|
|
|
|
rb_ary_concat(args, v);
|
2008-02-20 04:09:21 +03:00
|
|
|
|
2008-03-04 08:36:08 +03:00
|
|
|
arg->io = rb_io_open_with_args(RARRAY_LEN(args), RARRAY_PTR(args));
|
2007-12-23 19:02:46 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-06-17 01:31:56 +04:00
|
|
|
v = rb_hash_aref(opt, sym_mode);
|
2007-12-23 19:02:46 +03:00
|
|
|
if (!NIL_P(v)) {
|
2008-08-20 18:56:23 +04:00
|
|
|
arg->io = rb_io_open(RSTRING_PTR(argv[0]), v, opt);
|
2007-12-23 19:02:46 +03:00
|
|
|
}
|
2008-03-04 08:36:08 +03:00
|
|
|
else {
|
2008-08-20 18:56:23 +04:00
|
|
|
arg->io = rb_io_open(RSTRING_PTR(argv[0]), INT2NUM(O_RDONLY), opt);
|
2008-02-20 04:09:21 +03:00
|
|
|
}
|
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:
|
2006-12-29 22:21:50 +03:00
|
|
|
* IO.foreach(name, sep=$/) {|line| block } => nil
|
|
|
|
* IO.foreach(name, limit) {|line| block } => nil
|
|
|
|
* IO.foreach(name, sep, limit) {|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:
|
2006-12-29 22:21:50 +03:00
|
|
|
* IO.readlines(name, sep=$/) => array
|
|
|
|
* IO.readlines(name, limit) => array
|
|
|
|
* IO.readlines(name, sep, limit) => 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
|
2007-12-23 19:02:46 +03:00
|
|
|
* IO.read(name, [length [, offset]], opt) => 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-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;
|
|
|
|
rb_thread_t *th;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
copy_stream_wait_read(struct copy_stream_struct *stp)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
copy_stream_wait_write(struct copy_stream_struct *stp)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
copy_stream_sendfile(struct copy_stream_struct *stp)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retry_sendfile:
|
|
|
|
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
|
2008-03-30 10:38:05 +04:00
|
|
|
if (copy_stream_wait_write(stp) == -1)
|
|
|
|
return -1;
|
|
|
|
if (RUBY_VM_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
|
|
|
|
copy_stream_read(struct copy_stream_struct *stp, char *buf, int len, off_t offset)
|
|
|
|
{
|
|
|
|
ssize_t ss;
|
|
|
|
retry_read:
|
|
|
|
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
|
2008-03-30 10:38:05 +04:00
|
|
|
if (copy_stream_wait_read(stp) == -1)
|
|
|
|
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
|
|
|
|
copy_stream_write(struct copy_stream_struct *stp, char *buf, int len)
|
|
|
|
{
|
|
|
|
ssize_t ss;
|
|
|
|
int off = 0;
|
|
|
|
while (len) {
|
|
|
|
ss = write(stp->dst_fd, buf+off, len);
|
|
|
|
if (ss == -1) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
|
|
if (copy_stream_wait_write(stp) == -1)
|
|
|
|
return -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stp->syserr = "write";
|
|
|
|
stp->error_no = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
off += ss;
|
|
|
|
len -= ss;
|
|
|
|
stp->total += ss;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_stream_read_write(struct copy_stream_struct *stp)
|
|
|
|
{
|
|
|
|
char buf[1024*16];
|
|
|
|
int len;
|
|
|
|
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) {
|
|
|
|
if (!use_eof && copy_length < sizeof(buf)) {
|
|
|
|
len = copy_length;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = sizeof(buf);
|
|
|
|
}
|
|
|
|
if (use_pread) {
|
|
|
|
ss = copy_stream_read(stp, buf, len, src_offset);
|
|
|
|
if (0 < ss)
|
|
|
|
src_offset += ss;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ss = copy_stream_read(stp, buf, len, (off_t)-1);
|
|
|
|
}
|
|
|
|
if (ss <= 0) /* EOF or error */
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret = copy_stream_write(stp, buf, ss);
|
|
|
|
if (ret < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!use_eof)
|
|
|
|
copy_length -= ss;
|
|
|
|
|
|
|
|
if (RUBY_VM_INTERRUPTED(stp->th))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
copy_stream_func(void *arg)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
ret = copy_stream_sendfile(stp);
|
|
|
|
if (ret != 0)
|
|
|
|
goto finish; /* error or success */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
copy_stream_read_write(stp);
|
|
|
|
|
2008-04-20 10:14:49 +04:00
|
|
|
#ifdef USE_SENDFILE
|
2008-03-30 10:38:05 +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);
|
2008-04-20 07:51:57 +04:00
|
|
|
long rest = stp->copy_length;
|
|
|
|
off_t off = stp->src_offset;
|
|
|
|
|
|
|
|
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;
|
|
|
|
l = buflen < rest ? buflen : rest;
|
|
|
|
}
|
|
|
|
if (stp->src_fd == -1) {
|
2008-04-20 10:13:17 +04:00
|
|
|
rb_funcall(stp->src, id_readpartial, 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);
|
|
|
|
ss = copy_stream_read(stp, RSTRING_PTR(buf), l, off);
|
|
|
|
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-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;
|
|
|
|
|
|
|
|
stp->th = GET_THREAD();
|
|
|
|
|
2008-04-19 23:47:16 +04:00
|
|
|
stp->total = 0;
|
|
|
|
|
|
|
|
if (stp->src == argf ||
|
|
|
|
!(TYPE(stp->src) == T_FILE ||
|
|
|
|
rb_respond_to(stp->src, rb_intern("to_io")) ||
|
|
|
|
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-04-20 07:51:57 +04:00
|
|
|
src_io = rb_check_convert_type(stp->src, T_FILE, "IO", "to_io");
|
2008-04-20 10:13:17 +04:00
|
|
|
if (NIL_P(src_io)) {
|
|
|
|
VALUE args[2];
|
|
|
|
int flags = O_RDONLY;
|
2008-03-31 13:58:41 +04:00
|
|
|
#ifdef O_NOCTTY
|
2008-04-20 10:13:17 +04:00
|
|
|
flags |= 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;
|
|
|
|
args[1] = INT2NUM(flags);
|
|
|
|
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 ||
|
|
|
|
rb_respond_to(stp->dst, rb_intern("to_io")) ||
|
|
|
|
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-04-20 07:51:57 +04:00
|
|
|
dst_io = rb_check_convert_type(stp->dst, T_FILE, "IO", "to_io");
|
2008-04-20 10:13:17 +04:00
|
|
|
if (NIL_P(dst_io)) {
|
|
|
|
VALUE args[3];
|
|
|
|
int flags = O_WRONLY|O_CREAT|O_TRUNC;
|
2008-03-31 13:58:41 +04:00
|
|
|
#ifdef O_NOCTTY
|
2008-04-20 10:13:17 +04:00
|
|
|
flags |= 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;
|
|
|
|
args[1] = INT2NUM(flags);
|
|
|
|
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) {
|
2008-03-30 10:38:05 +04:00
|
|
|
long len = src_fptr->rbuf_len;
|
|
|
|
VALUE str;
|
|
|
|
if (stp->copy_length != (off_t)-1 && stp->copy_length < len) {
|
|
|
|
len = stp->copy_length;
|
|
|
|
}
|
|
|
|
str = rb_str_buf_new(len);
|
|
|
|
rb_str_resize(str,len);
|
|
|
|
read_buffered_data(RSTRING_PTR(str), len, src_fptr);
|
2008-04-20 10:13:17 +04:00
|
|
|
if (dst_fptr) /* IO or filename */
|
|
|
|
io_fwrite(str, dst_fptr);
|
|
|
|
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);
|
|
|
|
|
|
|
|
return rb_thread_blocking_region(copy_stream_func, (void*)stp, RB_UBF_DFL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2007-12-23 20:38:32 +03:00
|
|
|
if (fptr->enc2) {
|
|
|
|
return rb_enc_from_encoding(fptr->enc2);
|
|
|
|
}
|
2007-12-25 09:44:58 +03:00
|
|
|
if (fptr->mode & FMODE_WRITABLE) {
|
|
|
|
if (fptr->enc)
|
|
|
|
return rb_enc_from_encoding(fptr->enc);
|
|
|
|
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);
|
|
|
|
if (!fptr->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-01-05 06:35:13 +03:00
|
|
|
* io.set_encoding(ext_enc) => io
|
|
|
|
* io.set_encoding("ext_enc:int_enc") => io
|
|
|
|
* io.set_encoding(ext_enc, int_enc) => 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_io_set_encoding(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
rb_io_t *fptr;
|
|
|
|
VALUE v1, v2;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &v1, &v2);
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
io_encoding_set(fptr, argc, v1, v2);
|
|
|
|
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-05-29 17:30:09 +04:00
|
|
|
if (!RTEST(current_file)) {
|
|
|
|
return rb_enc_from_encoding(rb_default_external_encoding());
|
|
|
|
}
|
|
|
|
return rb_io_external_encoding(rb_io_check_io(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-05-29 17:30:09 +04:00
|
|
|
if (!RTEST(current_file)) {
|
|
|
|
return rb_enc_from_encoding(rb_default_external_encoding());
|
|
|
|
}
|
|
|
|
return rb_io_internal_encoding(rb_io_check_io(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");
|
|
|
|
}
|
2007-12-24 21:17:35 +03:00
|
|
|
rb_io_set_encoding(argc, argv, current_file);
|
2008-02-21 08:47:12 +03:00
|
|
|
GetOpenFile(current_file, fptr);
|
2007-12-24 21:17:35 +03:00
|
|
|
argf_enc = fptr->enc;
|
|
|
|
argf_enc2 = fptr->enc2;
|
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);
|
1999-08-13 09:45:20 +04:00
|
|
|
return rb_io_tell(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);
|
2001-03-13 08:45:13 +03:00
|
|
|
return rb_io_seek_m(argc, argv, 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);
|
1999-08-13 09:45:20 +04:00
|
|
|
return rb_io_set_pos(current_file, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
1999-08-13 09:45:20 +04:00
|
|
|
return rb_io_rewind(current_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
1999-08-13 09:45:20 +04:00
|
|
|
return rb_io_fileno(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);
|
1999-08-13 09:45:20 +04:00
|
|
|
return current_file;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (current_file) {
|
|
|
|
if (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);
|
2003-12-23 22:53:45 +03:00
|
|
|
if (rb_io_eof(current_file)) {
|
|
|
|
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 {
|
|
|
|
tmp = io_read(argc, argv, current_file);
|
|
|
|
}
|
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)) {
|
2003-12-03 20:30:09 +03:00
|
|
|
if (next_p != -1) {
|
|
|
|
argf_close(current_file);
|
|
|
|
next_p = 1;
|
|
|
|
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 {
|
2006-05-22 11:38:42 +04:00
|
|
|
tmp = io_getpartial(argc, argv, current_file, 0);
|
2005-01-01 14:25:43 +03:00
|
|
|
}
|
|
|
|
if (NIL_P(tmp)) {
|
|
|
|
if (next_p == -1) {
|
|
|
|
rb_eof_error();
|
|
|
|
}
|
|
|
|
argf_close(current_file);
|
|
|
|
next_p = 1;
|
2006-09-02 18:42:08 +04:00
|
|
|
if (RARRAY_LEN(rb_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()) {
|
* 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
|
|
|
ch = rb_funcall3(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 {
|
* 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
|
|
|
ch = rb_io_getc(current_file);
|
|
|
|
}
|
|
|
|
if (NIL_P(ch) && next_p != -1) {
|
|
|
|
argf_close(current_file);
|
|
|
|
next_p = 1;
|
|
|
|
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;
|
|
|
|
if (TYPE(current_file) != T_FILE) {
|
|
|
|
ch = rb_funcall3(current_file, rb_intern("getbyte"), 0, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ch = rb_io_getbyte(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
|
|
|
}
|
* 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(ch) && next_p != -1) {
|
* 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
|
|
|
argf_close(current_file);
|
1998-01-16 15:13:05 +03:00
|
|
|
next_p = 1;
|
|
|
|
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();
|
* 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 (TYPE(current_file) != T_FILE) {
|
|
|
|
ch = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ch = rb_io_getc(current_file);
|
|
|
|
}
|
|
|
|
if (NIL_P(ch) && next_p != -1) {
|
|
|
|
argf_close(current_file);
|
|
|
|
next_p = 1;
|
|
|
|
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 (;;) {
|
|
|
|
if (!next_argv()) return Qnil;
|
2008-06-30 17:22:10 +04:00
|
|
|
rb_block_call(current_file, rb_intern("each_line"), argc, argv, rb_yield, 0);
|
2007-08-14 15:03:29 +04:00
|
|
|
next_p = 1;
|
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 argf;
|
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 (;;) {
|
|
|
|
if (!next_argv()) return Qnil;
|
|
|
|
rb_block_call(current_file, rb_intern("each_byte"), 0, 0, rb_yield, 0);
|
|
|
|
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 (;;) {
|
|
|
|
if (!next_argv()) return Qnil;
|
|
|
|
rb_block_call(current_file, rb_intern("each_char"), 0, 0, rb_yield, 0);
|
|
|
|
next_p = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
1998-01-16 15:13:05 +03:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
1999-08-13 09:45:20 +04:00
|
|
|
return 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
|
|
|
{
|
2007-12-24 21:17:35 +03: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);
|
2003-04-25 13:20:51 +04:00
|
|
|
rb_io_binmode(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)
|
|
|
|
{
|
|
|
|
return argf_binmode ? Qtrue : Qfalse;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (next_p != -1) {
|
* 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
|
|
|
argf_close(current_file);
|
1998-01-16 15:13:05 +03:00
|
|
|
next_p = 1;
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
argf_close(current_file);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (next_p != -1) {
|
|
|
|
next_p = 1;
|
|
|
|
}
|
|
|
|
gets_lineno = 0;
|
|
|
|
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);
|
1999-08-13 09:45:20 +04:00
|
|
|
return rb_io_closed(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
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!ruby_inplace_mode) return Qnil;
|
|
|
|
return rb_str_new2(ruby_inplace_mode);
|
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)) {
|
|
|
|
if (ruby_inplace_mode) free(ruby_inplace_mode);
|
|
|
|
ruby_inplace_mode = 0;
|
|
|
|
}
|
2008-03-01 11:59:04 +03:00
|
|
|
else {
|
|
|
|
StringValue(val);
|
|
|
|
if (ruby_inplace_mode) free(ruby_inplace_mode);
|
|
|
|
ruby_inplace_mode = 0;
|
|
|
|
ruby_inplace_mode = strdup(RSTRING_PTR(val));
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return ruby_inplace_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ruby_set_inplace_mode(const char *suffix)
|
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
if (ruby_inplace_mode) free(ruby_inplace_mode);
|
2001-06-19 08:35:17 +04:00
|
|
|
ruby_inplace_mode = 0;
|
2008-03-01 11:59:04 +03:00
|
|
|
if (suffix) ruby_inplace_mode = strdup(suffix);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2008-03-01 11:59:04 +03:00
|
|
|
static VALUE
|
|
|
|
argf_argv(VALUE argf)
|
|
|
|
{
|
|
|
|
return rb_argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_argv_getter(ID id, VALUE *var)
|
|
|
|
{
|
|
|
|
return argf_argv(*var);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_get_argv(void)
|
|
|
|
{
|
|
|
|
return rb_argv;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
* -----+--------------------------------------------------------
|
2004-06-29 05:17:39 +04:00
|
|
|
* "b" | (DOS/Windows only) Binary file mode (may appear with
|
2003-12-24 07:24:29 +03:00
|
|
|
* | any of the key letters listed above).
|
|
|
|
*
|
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);
|
|
|
|
|
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);
|
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);
|
|
|
|
|
2005-12-12 03:36:54 +03:00
|
|
|
rb_global_variable(&rb_default_rs);
|
2001-10-29 08:07:26 +03:00
|
|
|
rb_rs = rb_default_rs = rb_str_new2("\n");
|
|
|
|
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);
|
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);
|
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);
|
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);
|
|
|
|
rb_define_method(rb_cIO, "write", io_write, 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);
|
|
|
|
rb_define_hooked_variable("$FILENAME", &argf, argf_filename_getter, 0);
|
2005-12-12 06:04:53 +03:00
|
|
|
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);
|
|
|
|
rb_define_hooked_variable("$*", &argf, argf_argv_getter, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
* 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 (_WIN32) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__)
|
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
|
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"));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|