2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
io.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Fri Oct 15 18:08:59 JST 1993
|
|
|
|
|
2003-01-16 10:34:03 +03:00
|
|
|
Copyright (C) 1993-2003 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
|
|
|
|
|
|
|
#include "ruby.h"
|
1999-01-20 07:59:39 +03:00
|
|
|
#include "rubyio.h"
|
|
|
|
#include "rubysig.h"
|
1998-01-16 15:13:05 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
* 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>
|
2004-12-06 17:04:05 +03:00
|
|
|
#if !defined(_WIN32) && !defined(__DJGPP__)
|
2004-12-06 14:19:27 +03:00
|
|
|
# if defined(__BEOS__)
|
|
|
|
# include <net/socket.h>
|
|
|
|
# else
|
|
|
|
# include <sys/socket.h>
|
|
|
|
# endif
|
|
|
|
#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
|
|
|
#include <net/socket.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "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;
|
|
|
|
|
* 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 ID id_write, id_read, id_getc, id_flush;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
extern char *ruby_inplace_mode;
|
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
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static VALUE filename, current_file;
|
1999-01-20 07:59:39 +03:00
|
|
|
static int gets_lineno;
|
2003-04-25 13:41:08 +04:00
|
|
|
static int init_p = 0, next_p = 0;
|
2003-12-30 22:29:56 +03:00
|
|
|
static VALUE lineno = INT2FIX(0);
|
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 fopen(file_spec, mode) fopen(file_spec, mode, "rfm=stmlf")
|
|
|
|
#define open(file_spec, flags, mode) open(file_spec, flags, mode, "rfm=stmlf")
|
|
|
|
#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
|
|
|
#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
|
|
|
|
|
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
|
|
|
|
#define shutdown(a,b) 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
|
|
|
{
|
|
|
|
if (!OBJ_TAINTED(io) && rb_safe_level() >= 4)
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: operation on untainted 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
|
* 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_initialized(OpenFile *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
|
* 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_closed(OpenFile *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
|
|
|
}
|
|
|
|
|
* 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
|
|
|
static int io_fflush(OpenFile *);
|
2002-10-02 18:59:25 +04:00
|
|
|
|
2004-04-07 06:51:05 +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_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");
|
|
|
|
}
|
|
|
|
|
* 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
|
|
|
|
io_unread(OpenFile *fptr)
|
|
|
|
{
|
|
|
|
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 */
|
|
|
|
r = lseek(fptr->fd, -fptr->rbuf_len, SEEK_CUR);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
io_ungetc(int c, OpenFile *fptr)
|
|
|
|
{
|
|
|
|
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 (c < 0 || fptr->rbuf_len == fptr->rbuf_capa) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (fptr->rbuf_off == 0) {
|
|
|
|
if (fptr->rbuf_len)
|
|
|
|
MEMMOVE(fptr->rbuf+1, fptr->rbuf, char, fptr->rbuf_len);
|
|
|
|
fptr->rbuf_off = 1;
|
|
|
|
}
|
|
|
|
fptr->rbuf_off--;
|
|
|
|
fptr->rbuf_len++;
|
|
|
|
fptr->rbuf[fptr->rbuf_off] = c;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2002-10-02 18:59:25 +04:00
|
|
|
static OpenFile *
|
* 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
|
|
|
flush_before_seek(OpenFile *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);
|
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
|
* 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_readable(OpenFile *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
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +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_io_check_writable(OpenFile *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
|
|
|
|
rb_io_read_pending(OpenFile *fptr)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
rb_io_read_check(OpenFile *fptr)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
if (errno == EMFILE || errno == ENFILE) {
|
|
|
|
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
|
|
|
|
wsplit_p(OpenFile *fptr)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
* 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
|
* 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_fflush(OpenFile *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;
|
2005-07-18 05:00:23 +04:00
|
|
|
l = fptr->wbuf_len;
|
|
|
|
if (PIPE_BUF < l &&
|
|
|
|
!rb_thread_critical &&
|
|
|
|
!rb_thread_alone() &&
|
|
|
|
wsplit_p(fptr)) {
|
|
|
|
l = PIPE_BUF;
|
|
|
|
}
|
* 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
|
|
|
TRAP_BEG;
|
2005-07-18 05:00:23 +04:00
|
|
|
r = write(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
TRAP_END; /* xxx: signal handler may modify wbuf */
|
|
|
|
if (r == fptr->wbuf_len) {
|
|
|
|
fptr->wbuf_off = 0;
|
|
|
|
fptr->wbuf_len = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (0 <= r) {
|
|
|
|
fptr->wbuf_off = (wbuf_off += r);
|
|
|
|
fptr->wbuf_len = (wbuf_len -= r);
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/* writing functions */
|
2004-12-06 18:31:26 +03:00
|
|
|
static 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
|
|
|
io_fwrite(VALUE str, OpenFile *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
|
|
|
|
2004-12-06 18:31:26 +03:00
|
|
|
len = RSTRING(str)->len;
|
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);
|
|
|
|
}
|
|
|
|
if ((fptr->mode & FMODE_SYNC) ||
|
|
|
|
(fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len) ||
|
2005-02-07 17:18:41 +03:00
|
|
|
((fptr->mode & FMODE_TTY) && memchr(RSTRING(str)->ptr+offset, '\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
|
|
|
/* 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;
|
|
|
|
}
|
2004-12-06 18:31:26 +03:00
|
|
|
MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, RSTRING(str)->ptr+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;
|
|
|
|
}
|
* 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
|
|
|
TRAP_BEG;
|
2005-07-18 05:00:23 +04:00
|
|
|
r = write(fptr->fd, RSTRING(str)->ptr+offset, 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
|
|
|
TRAP_END; /* xxx: signal handler 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);
|
2004-12-06 18:31:26 +03:00
|
|
|
if (offset < RSTRING(str)->len)
|
|
|
|
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
|
|
|
}
|
2004-12-06 18:31:26 +03:00
|
|
|
MEMMOVE(fptr->wbuf+fptr->wbuf_off+fptr->wbuf_len, RSTRING(str)->ptr+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
|
|
|
{
|
|
|
|
OpenFile of;
|
|
|
|
|
* 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
|
|
|
{
|
|
|
|
OpenFile *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);
|
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;
|
2003-06-06 13:24:59 +04:00
|
|
|
if (RSTRING(str)->len == 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
|
|
|
{
|
|
|
|
OpenFile *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
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *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);
|
2003-08-04 09:28:50 +04:00
|
|
|
if (pos < 0) 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
|
|
|
{
|
|
|
|
OpenFile *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);
|
2003-08-04 09:28:50 +04:00
|
|
|
if (pos < 0) 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
|
|
|
{
|
|
|
|
OpenFile *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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
2004-06-25 03:10:55 +04:00
|
|
|
if (io_seek(fptr, 0L, 0) < 0) rb_sys_fail(fptr->path);
|
2000-06-19 12:38:11 +04:00
|
|
|
if (io == current_file) {
|
|
|
|
gets_lineno -= fptr->lineno;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
io_getc(OpenFile *fptr)
|
|
|
|
{
|
|
|
|
int r;
|
* 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
|
|
|
if (fptr->fd == 0 && (fptr->mode & FMODE_TTY) && TYPE(rb_stdout) == T_FILE) {
|
2005-02-07 17:40:22 +03:00
|
|
|
OpenFile *ofp;
|
|
|
|
GetOpenFile(rb_stdout, ofp);
|
|
|
|
if (ofp->mode & FMODE_TTY) {
|
|
|
|
rb_io_flush(rb_stdout);
|
|
|
|
}
|
2005-02-07 17:18:41 +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->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:
|
|
|
|
TRAP_BEG;
|
|
|
|
r = read(fptr->fd, fptr->rbuf, fptr->rbuf_capa);
|
|
|
|
TRAP_END; /* xxx: signal handler may modify rbuf */
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
fptr->rbuf_off++;
|
|
|
|
fptr->rbuf_len--;
|
|
|
|
return (unsigned char)fptr->rbuf[fptr->rbuf_off-1];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
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);
|
|
|
|
ch = io_getc(fptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (ch != EOF) {
|
* 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_ungetc(ch, fptr);
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qfalse;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qtrue;
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
2005-09-24 04:17:43 +04:00
|
|
|
char *cname, *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
|
* 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_buffered_data(char *ptr, long len, OpenFile *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
|
* 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_fread(VALUE str, long offset, OpenFile *fptr)
|
2000-07-14 11:18:58 +04:00
|
|
|
{
|
2004-12-06 18:31:26 +03:00
|
|
|
long len = RSTRING(str)->len - offset;
|
2000-11-20 10:31:55 +03:00
|
|
|
long n = len;
|
2000-07-14 11:18:58 +04:00
|
|
|
int c;
|
|
|
|
|
2001-07-24 13:07:33 +04:00
|
|
|
while (n > 0) {
|
2004-12-06 18:31:26 +03:00
|
|
|
c = read_buffered_data(RSTRING(str)->ptr+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);
|
* 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
|
|
|
c = io_getc(fptr);
|
|
|
|
if (c < 0) {
|
2000-07-14 11:18:58 +04:00
|
|
|
break;
|
|
|
|
}
|
2004-12-06 18:31:26 +03:00
|
|
|
RSTRING(str)->ptr[offset++] = c;
|
|
|
|
if (offset > RSTRING(str)->len) break;
|
2001-07-24 13:07:33 +04:00
|
|
|
n--;
|
2000-07-14 11:18:58 +04:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
OpenFile 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);
|
|
|
|
MEMCPY(ptr, RSTRING(str)->ptr, char, n);
|
|
|
|
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
|
* 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
|
|
|
remain_size(OpenFile *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) {
|
2005-01-11 14:59:00 +03:00
|
|
|
siz += st.st_size - pos + 1;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
read_all(OpenFile *fptr, long siz, VALUE str)
|
2002-12-11 12:32:41 +03:00
|
|
|
{
|
2002-03-25 17:50:40 +03:00
|
|
|
long bytes = 0;
|
2002-04-24 08:54:16 +04:00
|
|
|
long n;
|
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) {
|
* 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
|
|
|
break;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
bytes += n;
|
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);
|
2004-11-25 04:58:31 +03:00
|
|
|
OBJ_TAINT(str);
|
1999-01-20 07:59:39 +03:00
|
|
|
|
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2005-01-01 14:25:43 +03:00
|
|
|
static VALUE
|
|
|
|
io_getpartial(int argc, VALUE *argv, VALUE io)
|
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
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;
|
|
|
|
|
|
|
|
READ_CHECK(fptr);
|
|
|
|
if (RSTRING(str)->len != len) {
|
|
|
|
modified:
|
|
|
|
rb_raise(rb_eRuntimeError, "buffer string modified");
|
|
|
|
}
|
|
|
|
n = read_buffered_data(RSTRING(str)->ptr, len, fptr);
|
|
|
|
if (n <= 0) {
|
|
|
|
again:
|
|
|
|
if (RSTRING(str)->len != len) goto modified;
|
|
|
|
TRAP_BEG;
|
|
|
|
n = read(fptr->fd, RSTRING(str)->ptr, len);
|
|
|
|
TRAP_END;
|
|
|
|
if (n < 0) {
|
|
|
|
if (rb_io_wait_readable(fptr->fd))
|
|
|
|
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:
|
2004-09-19 22:42:32 +04:00
|
|
|
* ios.readpartial(maxlen[, outbuf]) => string, outbuf
|
2004-08-11 20:57:14 +04:00
|
|
|
*
|
2004-09-19 22:42:32 +04:00
|
|
|
* Reads at most <i>maxlen</i> bytes from the I/O stream but
|
2004-08-11 20:57:14 +04:00
|
|
|
* it blocks only if <em>ios</em> has no data immediately available.
|
|
|
|
* 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,
|
|
|
|
* it returns the data in the stream.
|
|
|
|
* 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" "" ""
|
|
|
|
*
|
|
|
|
* Note that readpartial is nonblocking-flag insensitive.
|
2006-05-09 06:12:11 +04:00
|
|
|
* It blocks on the situation IO#sysread causes Errno::EAGAIN.
|
2004-08-11 20:57:14 +04:00
|
|
|
*
|
|
|
|
* Also note that readpartial behaves similar to sysread in blocking mode.
|
2005-01-08 21:18:36 +03:00
|
|
|
* The behavior is identical when the buffer is empty.
|
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
|
|
|
|
2005-01-01 14:25:43 +03:00
|
|
|
ret = io_getpartial(argc, argv, io);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *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);
|
|
|
|
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)) {
|
2004-11-25 04:58:31 +03:00
|
|
|
str = rb_tainted_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);
|
2004-11-10 10:17:53 +03:00
|
|
|
if (RSTRING(str)->len != len) {
|
|
|
|
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);
|
1998-01-16 15:13:05 +03:00
|
|
|
RSTRING(str)->len = n;
|
|
|
|
RSTRING(str)->ptr[n] = '\0';
|
1999-01-20 07:59:39 +03:00
|
|
|
OBJ_TAINT(str);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-03-25 17:50:40 +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
|
|
|
appendline(OpenFile *fptr, int delim, VALUE *strp)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-03-25 17:50:40 +03:00
|
|
|
VALUE str = *strp;
|
|
|
|
int c = EOF;
|
2002-02-06 10:30:13 +03:00
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
do {
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
long pending = READ_DATA_PENDING_COUNT(fptr);
|
2002-03-25 17:50:40 +03:00
|
|
|
if (pending > 0) {
|
* 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
|
|
|
const char *e = memchr(p, delim, pending);
|
2002-08-28 18:36:38 +04:00
|
|
|
long last = 0, len = (c != EOF);
|
2002-03-25 17:50:40 +03:00
|
|
|
if (e) pending = e - p + 1;
|
2002-08-28 18:36:38 +04:00
|
|
|
len += pending;
|
2002-03-25 17:50:40 +03:00
|
|
|
if (!NIL_P(str)) {
|
|
|
|
last = RSTRING(str)->len;
|
2002-08-28 18:36:38 +04:00
|
|
|
rb_str_resize(str, last + len);
|
2002-03-25 17:50:40 +03:00
|
|
|
}
|
|
|
|
else {
|
2002-08-28 18:36:38 +04:00
|
|
|
*strp = str = rb_str_buf_new(len);
|
|
|
|
RSTRING(str)->len = len;
|
2002-09-25 11:03:05 +04:00
|
|
|
RSTRING(str)->ptr[len] = '\0';
|
2002-03-25 17:50:40 +03:00
|
|
|
}
|
|
|
|
if (c != EOF) {
|
|
|
|
RSTRING(str)->ptr[last++] = c;
|
|
|
|
}
|
* 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_buffered_data(RSTRING(str)->ptr + last, pending, fptr); /* must not fail */
|
2002-03-25 17:50:40 +03:00
|
|
|
if (e) return delim;
|
|
|
|
}
|
2002-08-28 18:36:38 +04:00
|
|
|
else if (c != EOF) {
|
|
|
|
if (!NIL_P(str)) {
|
|
|
|
char ch = c;
|
|
|
|
rb_str_buf_cat(str, &ch, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*strp = str = rb_str_buf_new(1);
|
|
|
|
RSTRING(str)->ptr[RSTRING(str)->len++] = c;
|
|
|
|
}
|
|
|
|
}
|
* 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);
|
* 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
|
|
|
c = io_getc(fptr);
|
|
|
|
if (c < 0) {
|
2002-03-25 17:50:40 +03:00
|
|
|
return c;
|
2002-02-06 10:30:13 +03:00
|
|
|
}
|
2002-03-25 17:50:40 +03:00
|
|
|
} while (c != delim);
|
|
|
|
|
|
|
|
{
|
|
|
|
char ch = c;
|
|
|
|
if (!NIL_P(str)) {
|
|
|
|
rb_str_cat(str, &ch, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*strp = str = rb_str_new(&ch, 1);
|
|
|
|
}
|
2002-02-06 10:30:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
return c;
|
|
|
|
}
|
2002-02-06 10:30:13 +03:00
|
|
|
|
2002-03-25 17:50:40 +03:00
|
|
|
static inline 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
|
|
|
swallow(OpenFile *fptr, int term)
|
2002-03-25 17:50:40 +03:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
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);
|
* 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
|
|
|
c = io_getc(fptr);
|
2002-03-25 17:50:40 +03:00
|
|
|
if (c != 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
|
|
|
io_ungetc(c, fptr);
|
2002-03-25 17:50:40 +03:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
} while (c != EOF);
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
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_getline_fast(OpenFile *fptr, unsigned char delim)
|
2002-03-25 17:50:40 +03:00
|
|
|
{
|
|
|
|
VALUE str = Qnil;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while ((c = appendline(fptr, delim, &str)) != EOF && c != delim);
|
2002-02-06 10:30:13 +03:00
|
|
|
|
|
|
|
if (!NIL_P(str)) {
|
|
|
|
fptr->lineno++;
|
|
|
|
lineno = INT2FIX(fptr->lineno);
|
|
|
|
OBJ_TAINT(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2004-10-19 14:25:23 +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
|
|
|
rscheck(char *rsptr, long rslen, VALUE rs)
|
2004-10-19 14:25:23 +04:00
|
|
|
{
|
|
|
|
if (RSTRING(rs)->ptr != rsptr && RSTRING(rs)->len != rslen)
|
|
|
|
rb_raise(rb_eRuntimeError, "rs modified");
|
2004-10-27 13:29:26 +04:00
|
|
|
return 0;
|
2004-10-19 14:25:23 +04:00
|
|
|
}
|
|
|
|
|
2002-02-06 10:30: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_getline(VALUE rs, VALUE io)
|
2002-02-06 10:30:13 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE str = Qnil;
|
2004-11-23 20:37:51 +03:00
|
|
|
OpenFile *fptr;
|
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);
|
2003-12-26 20:05:20 +03:00
|
|
|
if (RSTRING(str)->len == 0) return Qnil;
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
2000-05-01 13:42:38 +04:00
|
|
|
else if (rs == rb_default_rs) {
|
2002-03-25 17:50:40 +03:00
|
|
|
return rb_io_getline_fast(fptr, '\n');
|
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;
|
|
|
|
char *rsptr;
|
2002-08-21 19:47:54 +04:00
|
|
|
long rslen;
|
|
|
|
int rspara = 0;
|
2002-03-25 17:50:40 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
rslen = RSTRING(rs)->len;
|
|
|
|
if (rslen == 0) {
|
|
|
|
rsptr = "\n\n";
|
|
|
|
rslen = 2;
|
|
|
|
rspara = 1;
|
2002-03-25 17:50:40 +03:00
|
|
|
swallow(fptr, '\n');
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2002-03-25 17:50:40 +03:00
|
|
|
else if (rslen == 1) {
|
2004-10-09 14:51:11 +04:00
|
|
|
return rb_io_getline_fast(fptr, (unsigned char)RSTRING(rs)->ptr[0]);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
else {
|
|
|
|
rsptr = RSTRING(rs)->ptr;
|
|
|
|
}
|
2002-03-25 17:50:40 +03:00
|
|
|
newline = rsptr[rslen - 1];
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2004-11-20 17:26:23 +03:00
|
|
|
while ((c = appendline(fptr, newline, &str)) != EOF) {
|
|
|
|
if (c == newline) {
|
|
|
|
if (RSTRING(str)->len < rslen) continue;
|
|
|
|
if (!rspara) rscheck(rsptr, rslen, rs);
|
|
|
|
if (memcmp(RSTRING(str)->ptr + RSTRING(str)->len - rslen,
|
|
|
|
rsptr, rslen) == 0) break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
if (!NIL_P(str)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
fptr->lineno++;
|
|
|
|
lineno = INT2FIX(fptr->lineno);
|
1999-01-20 07:59:39 +03:00
|
|
|
OBJ_TAINT(str);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
GetOpenFile(io, fptr);
|
|
|
|
rb_io_check_readable(fptr);
|
2002-03-25 17:50:40 +03:00
|
|
|
return rb_io_getline_fast(fptr, '\n');
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.gets(sep_string=$/) => 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
|
|
|
|
* <i>sep_string</i>. A separator of <code>nil</code> reads the entire
|
|
|
|
* 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
|
|
|
|
* file.
|
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
|
|
|
{
|
2002-02-06 10:30:13 +03:00
|
|
|
VALUE rs, str;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
rs = rb_rs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "1", &rs);
|
2004-11-23 20:37:51 +03:00
|
|
|
if (!NIL_P(rs)) StringValue(rs);
|
2002-02-06 10:30:13 +03:00
|
|
|
}
|
2004-11-23 20:37:51 +03:00
|
|
|
str = rb_io_getline(rs, 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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
|
* $. # lineno of last read #=> 1
|
|
|
|
* f.gets #=> "This is line two\n"
|
|
|
|
* $. # lineno of last read #=> 1001
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
lineno_setter(VALUE val, ID id, VALUE *var)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
gets_lineno = NUM2INT(val);
|
|
|
|
*var = INT2FIX(gets_lineno);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
argf_set_lineno(VALUE argf, VALUE val)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
gets_lineno = NUM2INT(val);
|
|
|
|
lineno = INT2FIX(gets_lineno);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
argf_lineno(void)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
return lineno;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.readline(sep_string=$/) => 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:
|
|
|
|
* ios.readlines(sep_string=$/) => 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
|
|
|
|
* <i>anArray</i>. Lines are separated by the optional
|
2005-01-25 07:03:02 +03:00
|
|
|
* <i>sep_string</i>. If <i>sep_string</i> is <code>nil</code>, the
|
2003-12-27 03:44:05 +03:00
|
|
|
* rest of the stream is returned as a single record.
|
|
|
|
* The stream must be opened for reading or an
|
* 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
|
|
|
* <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
|
|
|
{
|
|
|
|
VALUE line, ary;
|
2002-04-24 08:54:16 +04:00
|
|
|
VALUE rs;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-02-06 10:30:13 +03:00
|
|
|
if (argc == 0) {
|
|
|
|
rs = rb_rs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "1", &rs);
|
2004-11-23 20:37:51 +03:00
|
|
|
if (!NIL_P(rs)) StringValue(rs);
|
2002-02-06 10:30:13 +03:00
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
ary = rb_ary_new();
|
2004-11-23 20:37:51 +03:00
|
|
|
while (!NIL_P(line = rb_io_getline(rs, 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:
|
|
|
|
* ios.each(sep_string=$/) {|line| block } => ios
|
|
|
|
* ios.each_line(sep_string=$/) {|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
|
|
|
|
* separated by <i>sep_string</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
|
|
|
{
|
|
|
|
VALUE str;
|
2002-02-06 10:30:13 +03:00
|
|
|
VALUE rs;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-08-30 18:49:51 +04:00
|
|
|
RETURN_ENUMERATOR(io, argc, argv);
|
2002-02-06 10:30:13 +03:00
|
|
|
if (argc == 0) {
|
|
|
|
rs = rb_rs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "1", &rs);
|
2004-11-23 20:37:51 +03:00
|
|
|
if (!NIL_P(rs)) StringValue(rs);
|
2002-02-06 10:30:13 +03:00
|
|
|
}
|
2004-11-23 20:37:51 +03:00
|
|
|
while (!NIL_P(str = rb_io_getline(rs, 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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
int c;
|
|
|
|
|
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 (;;) {
|
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);
|
|
|
|
c = io_getc(fptr);
|
|
|
|
if (c < 0) {
|
2000-06-13 13:42:40 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_yield(INT2FIX(c & 0xff));
|
|
|
|
}
|
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:
|
|
|
|
* ios.getc => fixnum or nil
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Gets the next 8-bit byte (0..255) from <em>ios</em>. Returns
|
|
|
|
* <code>nil</code> if called 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.getc #=> 84
|
|
|
|
* f.getc #=> 104
|
|
|
|
*/
|
|
|
|
|
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_getc(VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
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
|
|
|
READ_CHECK(fptr);
|
|
|
|
c = io_getc(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 (c < 0) {
|
1998-01-16 15:13:05 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return INT2FIX(c & 0xff);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2004-12-30 16:49:56 +03:00
|
|
|
if (!STDIO_READ_DATA_PENDING(f)) {
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_thread_wait_fd(fileno(f));
|
|
|
|
}
|
|
|
|
TRAP_BEG;
|
|
|
|
c = getc(f);
|
|
|
|
TRAP_END;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.readchar => fixnum
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* Reads a character as with <code>IO#getc</code>, but raises an
|
|
|
|
* <code>EOFError</code> on end of file.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE c = rb_io_getc(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;
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.ungetc(integer) => 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>
|
|
|
|
* c = f.getc #=> 84
|
|
|
|
* f.ungetc(c) #=> nil
|
|
|
|
* f.getc #=> 84
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
2000-01-05 07:41:21 +03:00
|
|
|
int cc = NUM2INT(c);
|
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 (io_ungetc(cc, fptr) == EOF && cc != EOF) {
|
2004-03-10 10:05:19 +03:00
|
|
|
rb_raise(rb_eIOError, "ungetc failed");
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
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
|
|
|
fptr_finalize(OpenFile *fptr, int noraise)
|
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) {
|
|
|
|
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) {
|
|
|
|
/* fptr->fd is still not closed */
|
2004-12-08 16:26:27 +03:00
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
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);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2000-12-12 10:42:35 +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
|
|
|
rb_io_fptr_cleanup(OpenFile *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
|
|
|
}
|
|
|
|
|
2004-04-07 06:51:05 +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_fptr_finalize(OpenFile *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
|
|
|
}
|
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
|
|
|
{
|
2002-02-05 10:56:31 +03:00
|
|
|
OpenFile *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;
|
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
|
|
|
{
|
1999-12-14 09:50:43 +03:00
|
|
|
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
|
|
|
|
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
|
* 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_close(VALUE io)
|
2003-03-04 10:04:11 +03:00
|
|
|
{
|
2005-09-19 20:01:06 +04:00
|
|
|
if (TYPE(io) == T_FILE) {
|
|
|
|
rb_io_close(io);
|
|
|
|
return Qnil;
|
|
|
|
}
|
2003-03-04 10:04:11 +03:00
|
|
|
return rb_funcall(io, rb_intern("close"), 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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
|
|
|
|
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
|
|
|
}
|
* 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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
|
1999-12-14 09:50:43 +03:00
|
|
|
if (rb_safe_level() >= 4 && !OBJ_TAINTED(io)) {
|
|
|
|
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_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))
|
|
|
|
return rb_io_close(io);
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
return rb_io_close(io);
|
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;
|
2002-03-27 08:28:00 +03:00
|
|
|
OpenFile *fptr;
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *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
|
|
|
|
|
|
|
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;
|
* 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 = write(fptr->fd, RSTRING(str)->ptr, RSTRING(str)->len);
|
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;
|
1998-01-16 15:13:05 +03:00
|
|
|
OpenFile *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);
|
2004-11-29 18:58:18 +03:00
|
|
|
if (RSTRING(str)->len != ilen) {
|
|
|
|
rb_raise(rb_eRuntimeError, "buffer string modified");
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
TRAP_BEG;
|
* 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(fptr->fd, RSTRING(str)->ptr, ilen);
|
1998-01-16 15:13:05 +03:00
|
|
|
TRAP_END;
|
|
|
|
|
2003-03-20 09:27:22 +03:00
|
|
|
if (n == -1) {
|
|
|
|
rb_sys_fail(fptr->path);
|
|
|
|
}
|
2004-11-30 12:36:39 +03:00
|
|
|
rb_str_resize(str, n);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (n == 0 && ilen > 0) {
|
|
|
|
rb_eof_error();
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
RSTRING(str)->len = n;
|
|
|
|
RSTRING(str)->ptr[n] = '\0';
|
1999-01-20 07:59:39 +03:00
|
|
|
OBJ_TAINT(str);
|
|
|
|
|
|
|
|
return str;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* ios.binmode => ios
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-27 03:44:05 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
* 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__) || defined(__EMX__)
|
1998-01-16 15:13:05 +03:00
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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_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);
|
|
|
|
|
|
|
|
fptr->mode |= FMODE_BINMODE;
|
|
|
|
#endif
|
|
|
|
return io;
|
|
|
|
}
|
|
|
|
|
2004-10-05 05:37:46 +04:00
|
|
|
static 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
|
|
|
}
|
* 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_eArgError, "illegal access modenum %o", 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':
|
2004-10-18 06:29:43 +04:00
|
|
|
flags |= FMODE_WRITABLE | 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:
|
|
|
|
rb_raise(rb_eArgError, "illegal access mode %s", mode);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
while (*m) {
|
|
|
|
switch (*m++) {
|
|
|
|
case 'b':
|
|
|
|
flags |= FMODE_BINMODE;
|
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
flags |= FMODE_READWRITE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto error;
|
|
|
|
}
|
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;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2001-09-03 09:37:42 +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
|
|
|
rb_io_mode_modenum(const char *mode)
|
2001-06-05 11:19:39 +04:00
|
|
|
{
|
|
|
|
int flags = 0;
|
|
|
|
const char *m = mode;
|
|
|
|
|
|
|
|
switch (*m++) {
|
|
|
|
case 'r':
|
|
|
|
flags |= O_RDONLY;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
flags |= O_WRONLY | O_CREAT | O_TRUNC;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
flags |= O_WRONLY | O_CREAT | O_APPEND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error:
|
|
|
|
rb_raise(rb_eArgError, "illegal access mode %s", mode);
|
|
|
|
}
|
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
while (*m) {
|
|
|
|
switch (*m++) {
|
|
|
|
case 'b':
|
2001-06-05 11:19:39 +04:00
|
|
|
#ifdef O_BINARY
|
2002-04-24 08:54:16 +04:00
|
|
|
flags |= O_BINARY;
|
2001-06-05 11:19:39 +04:00
|
|
|
#endif
|
2002-04-24 08:54:16 +04:00
|
|
|
break;
|
|
|
|
case '+':
|
2004-12-22 05:15:35 +03:00
|
|
|
flags = (flags & ~O_ACCMODE) | O_RDWR;
|
2002-04-24 08:54:16 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto error;
|
|
|
|
}
|
2001-06-05 11:19:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2004-10-04 09:04:22 +04:00
|
|
|
#define MODENUM_MAX 4
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static 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
|
|
|
}
|
2004-10-06 11:40:06 +04:00
|
|
|
rb_raise(rb_eArgError, "illegal access modenum %o", flags);
|
|
|
|
return NULL; /* not reached */
|
1999-08-13 09:45:20 +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
|
|
|
rb_sysopen(char *fname, int flags, unsigned int mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2001-02-02 14:38:20 +03:00
|
|
|
fd = open(fname, flags, mode);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (fd < 0) {
|
|
|
|
if (errno == EMFILE || errno == ENFILE) {
|
|
|
|
rb_gc();
|
2001-02-02 14:38:20 +03:00
|
|
|
fd = open(fname, flags, mode);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
if (fd < 0) {
|
|
|
|
rb_sys_fail(fname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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_fopen(const char *fname, 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-10-31 20:37:52 +03:00
|
|
|
file = fopen(fname, mode);
|
2000-07-06 11:21:26 +04:00
|
|
|
if (!file) {
|
1998-01-16 15:13:05 +03:00
|
|
|
if (errno == EMFILE || errno == ENFILE) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_gc();
|
2004-10-31 20:37:52 +03:00
|
|
|
file = fopen(fname, mode);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-07-06 11:21:26 +04:00
|
|
|
if (!file) {
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_sys_fail(fname);
|
|
|
|
}
|
|
|
|
}
|
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 for %s", fname);
|
2001-05-02 08:22:21 +04:00
|
|
|
#endif
|
2000-01-05 07:41:21 +03:00
|
|
|
#ifdef __human68k__
|
2004-12-23 13:12:35 +03:00
|
|
|
setmode(fileno(file), O_TEXT);
|
2000-01-05 07:41:21 +03:00
|
|
|
#endif
|
1999-08-13 09:45:20 +04:00
|
|
|
return file;
|
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
|
|
|
|
io_check_tty(OpenFile *fptr)
|
|
|
|
{
|
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
|
* 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_internal(VALUE io, const char *fname, const char *mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
2000-03-23 11:37:35 +03:00
|
|
|
|
|
|
|
MakeOpenFile(io, fptr);
|
1999-08-13 09:45:20 +04:00
|
|
|
fptr->mode = rb_io_mode_flags(mode);
|
|
|
|
fptr->path = strdup(fname);
|
* 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 = rb_sysopen(fptr->path, rb_io_mode_modenum(rb_io_flags_mode(fptr->mode)), 0666);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-03-23 11:37:35 +03:00
|
|
|
static VALUE
|
2005-09-12 15:03:24 +04:00
|
|
|
rb_file_sysopen_internal(VALUE io, const char *fname, int flags, int mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
2000-03-23 11:37:35 +03:00
|
|
|
|
|
|
|
MakeOpenFile(io, fptr);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2004-10-06 19:10:43 +04:00
|
|
|
fptr->path = strdup(fname);
|
2002-04-01 11:39:09 +04:00
|
|
|
fptr->mode = rb_io_modenum_flags(flags);
|
* 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 = rb_sysopen(fptr->path, flags, mode);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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_sysopen(const char *fname, int flags, int mode)
|
1999-08-13 09:45:20 +04:00
|
|
|
{
|
2003-02-09 21:36:22 +03:00
|
|
|
return rb_file_sysopen_internal(io_alloc(rb_cFile), fname, flags, mode);
|
1998-01-16 15:13:05 +03: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 {
|
|
|
|
OpenFile *fptr;
|
|
|
|
struct pipe_list *next;
|
|
|
|
} *pipe_list;
|
|
|
|
|
|
|
|
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
|
|
|
pipe_add_fptr(OpenFile *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
|
* 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
|
|
|
pipe_del_fptr(OpenFile *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
|
* 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
|
|
|
pipe_finalize(OpenFile *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
|
|
|
extern VALUE rb_last_status;
|
|
|
|
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
|
2000-07-10 10:30:11 +04:00
|
|
|
rb_last_status = INT2FIX(status);
|
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
|
* 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_synchronized(OpenFile *fptr)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
fptr->mode |= FMODE_SYNC;
|
|
|
|
}
|
|
|
|
|
1999-09-20 11:14:18 +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_io_unbuffered(OpenFile *fptr)
|
1999-09-20 11:14:18 +04:00
|
|
|
{
|
|
|
|
rb_io_synchronized(fptr);
|
|
|
|
}
|
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
struct popen_arg {
|
|
|
|
struct rb_exec_arg exec;
|
* 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];
|
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)) {
|
|
|
|
close(p->pair[0]);
|
|
|
|
dup2(p->pair[1], 0);
|
|
|
|
dup2(p->pair[1], 1);
|
|
|
|
if (2 <= p->pair[1])
|
|
|
|
close(p->pair[1]);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
#ifdef HAVE_FORK
|
|
|
|
static int
|
2006-03-01 13:06:03 +03:00
|
|
|
popen_exec(struct popen_arg *p)
|
2004-02-16 09:45:32 +03:00
|
|
|
{
|
|
|
|
int fd;
|
2002-06-28 22:26:01 +04:00
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
popen_redirect(p);
|
|
|
|
for (fd = 3; fd < NOFILE; fd++) {
|
|
|
|
#ifdef FD_CLOEXEC
|
|
|
|
fcntl(fd, F_SETFL, FD_CLOEXEC);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
2004-02-16 09:45:32 +03:00
|
|
|
close(fd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return rb_exec(&p->exec);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static VALUE
|
2006-03-01 13:06:03 +03:00
|
|
|
pipe_open(int argc, VALUE *argv, const char *mode)
|
2004-02-16 09:45:32 +03:00
|
|
|
{
|
|
|
|
int modef = rb_io_mode_flags(mode);
|
|
|
|
int pid = 0;
|
|
|
|
OpenFile *fptr;
|
2004-10-31 20:37:52 +03:00
|
|
|
VALUE port, prog;
|
2005-11-11 14:08:17 +03:00
|
|
|
#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
|
2004-02-16 09:45:32 +03:00
|
|
|
int status;
|
|
|
|
struct popen_arg arg;
|
1998-01-16 15:13:05 +03:00
|
|
|
volatile int doexec;
|
2004-02-16 09:45:32 +03:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
int openmode = rb_io_mode_modenum(mode);
|
2004-11-01 05:55:29 +03:00
|
|
|
char *exename = NULL;
|
2004-02-16 09:45:32 +03:00
|
|
|
#endif
|
2004-10-31 20:37:52 +03:00
|
|
|
char *cmd;
|
2004-12-08 16:26:27 +03:00
|
|
|
FILE *fp = 0;
|
|
|
|
int fd = -1;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-11-02 08:33:11 +03:00
|
|
|
prog = rb_check_argv(argc, argv);
|
|
|
|
if (!prog) {
|
|
|
|
if (argc == 1) argc = 0;
|
|
|
|
prog = argv[0];
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2005-11-11 14:08:17 +03:00
|
|
|
#if defined(HAVE_FORK) && defined(HAVE_SOCKETPAIR)
|
2004-11-02 08:33:11 +03:00
|
|
|
cmd = StringValueCStr(prog);
|
|
|
|
doexec = (strcmp("-", cmd) != 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
if (!doexec) {
|
|
|
|
fflush(stdin); /* is it really needed? */
|
* 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);
|
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
|
|
|
arg.modef = modef;
|
|
|
|
arg.pair[0] = arg.pair[1] = -1;
|
|
|
|
if ((modef & FMODE_READABLE) && (modef & FMODE_WRITABLE)) {
|
|
|
|
if (socketpair(AF_UNIX, SOCK_STREAM, 0, arg.pair) < 0)
|
|
|
|
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
|
|
|
else if (modef & FMODE_READABLE) {
|
|
|
|
if (pipe(arg.pair) < 0)
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
}
|
|
|
|
else if (modef & FMODE_WRITABLE) {
|
|
|
|
if (pipe(arg.pair) < 0)
|
|
|
|
rb_sys_fail(cmd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_sys_fail(cmd);
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
if (doexec) {
|
|
|
|
arg.exec.argc = argc;
|
|
|
|
arg.exec.argv = argv;
|
2004-03-02 10:30:35 +03:00
|
|
|
arg.exec.prog = cmd;
|
2004-02-16 09:45:32 +03:00
|
|
|
pid = rb_fork(&status, popen_exec, &arg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pid = rb_fork(&status, 0, 0);
|
|
|
|
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;
|
* rubyio.h, intern.h, io.c, file.c, process.c, ext/socket/socket.c,
ext/pty/pty.c, ext/io/wait/wait.c, ext/openssl/ossl_ssl.c:
Use own buffering mechanism instead of stdio.
* io.c, ext/stringio/stringio.c, test/ruby/ut_eof.rb:
EOF flag removed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-12-06 11:40:30 +03:00
|
|
|
close(arg.pair[0]);
|
|
|
|
close(arg.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];
|
* 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) {
|
2004-11-02 08:33:11 +03:00
|
|
|
char **args = ALLOCA_N(char *, argc+1);
|
2004-02-16 09:45:32 +03:00
|
|
|
int i;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-02-16 09:45:32 +03:00
|
|
|
for (i = 0; i < argc; ++i) {
|
|
|
|
args[i] = RSTRING(argv[i])->ptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2004-02-16 09:45:32 +03:00
|
|
|
args[i] = NULL;
|
|
|
|
cmd = ALLOCA_N(char, rb_w32_argv_size(args));
|
|
|
|
rb_w32_join_argv(cmd, args);
|
2004-11-02 08:33:11 +03:00
|
|
|
exename = RSTRING(prog)->ptr;
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
2004-11-02 08:54:45 +03:00
|
|
|
else {
|
|
|
|
cmd = StringValueCStr(prog);
|
|
|
|
}
|
2004-12-07 18:47:59 +03:00
|
|
|
while ((pid = rb_w32_pipe_exec(cmd, exename, openmode, &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:
|
2004-11-02 08:33:11 +03:00
|
|
|
rb_sys_fail(RSTRING(prog)->ptr);
|
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
|
|
|
}
|
|
|
|
#else
|
2004-12-09 06:34:47 +03:00
|
|
|
if (argc)
|
|
|
|
prog = rb_ary_join(rb_ary_new4(argc, argv), rb_str_new2(" "));
|
* 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 = popen(StringValueCStr(prog), mode);
|
|
|
|
if (!fp) rb_sys_fail(RSTRING(prog)->ptr);
|
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;
|
2004-02-16 09:45:32 +03:00
|
|
|
fptr->pid = pid;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
* be used as the subprocess's +argv+ bypassing a shell. The default
|
|
|
|
* mode for the new file object is ``r'', but <i>mode</i> may be set
|
|
|
|
* to any of the modes listed in the description for class IO.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
2004-02-16 09:45:32 +03:00
|
|
|
char *mode;
|
|
|
|
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 {
|
2004-10-31 20:37:52 +03:00
|
|
|
mode = rb_io_flags_mode(rb_io_mode_flags(StringValuePtr(pmode)));
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
tmp = rb_check_array_type(pname);
|
|
|
|
if (!NIL_P(tmp)) {
|
2004-11-02 08:33:11 +03:00
|
|
|
VALUE *argv = ALLOCA_N(VALUE, RARRAY(tmp)->len);
|
|
|
|
|
|
|
|
MEMCPY(argv, RARRAY(tmp)->ptr, VALUE, RARRAY(tmp)->len);
|
|
|
|
port = pipe_open(RARRAY(tmp)->len, argv, mode);
|
2004-11-02 02:49:16 +03:00
|
|
|
pname = tmp;
|
2004-02-16 09:45:32 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(pname);
|
2004-11-02 08:33:11 +03:00
|
|
|
port = pipe_open(1, &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
|
|
|
}
|
|
|
|
|
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_open_file(int argc, VALUE *argv, VALUE io)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2002-05-23 09:35:32 +04:00
|
|
|
VALUE fname, vmode, perm;
|
2004-10-06 19:10:43 +04:00
|
|
|
char *mode;
|
2001-06-05 11:19:39 +04:00
|
|
|
int flags, fmode;
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
|
2004-04-07 10:30:15 +04:00
|
|
|
FilePathValue(fname);
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2001-06-05 11:19:39 +04:00
|
|
|
if (FIXNUM_P(vmode) || !NIL_P(perm)) {
|
2003-06-23 10:52:39 +04:00
|
|
|
if (FIXNUM_P(vmode)) {
|
2004-03-15 05:27:29 +03:00
|
|
|
flags = FIX2INT(vmode);
|
2003-06-23 10:52:39 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(vmode);
|
2003-06-23 11:19:03 +04:00
|
|
|
flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
|
2003-06-23 10:52:39 +04:00
|
|
|
}
|
2001-06-05 11:19:39 +04:00
|
|
|
fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
|
2001-09-03 09:37:42 +04:00
|
|
|
|
2004-10-06 19:10:43 +04:00
|
|
|
rb_file_sysopen_internal(io, RSTRING(fname)->ptr, flags, fmode);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
2001-05-02 08:22:21 +04:00
|
|
|
mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
|
2002-05-23 09:35:32 +04:00
|
|
|
rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
|
1999-08-13 09:45:20 +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
|
|
|
{
|
|
|
|
VALUE fname, vmode, perm;
|
|
|
|
int flags, fmode, fd;
|
2004-10-06 19:10:43 +04:00
|
|
|
char *path;
|
2002-05-23 09:35:32 +04:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
|
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);
|
|
|
|
flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
|
2002-05-23 09:35:32 +04:00
|
|
|
}
|
|
|
|
if (NIL_P(perm)) fmode = 0666;
|
|
|
|
else fmode = NUM2INT(perm);
|
|
|
|
|
2004-10-06 19:10:43 +04:00
|
|
|
path = ALLOCA_N(char, strlen(RSTRING(fname)->ptr)+1);
|
|
|
|
strcpy(path, RSTRING(fname)->ptr);
|
|
|
|
fd = rb_sysopen(path, flags, fmode);
|
2002-05-23 09:35:32 +04:00
|
|
|
return INT2NUM(fd);
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* open(path [, mode [, perm]] ) => io or nil
|
2005-01-25 07:03:02 +03:00
|
|
|
* open(path [, mode [, 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
|
|
|
|
* the specified mode (defaulting to ``<code>r</code>''). (See the table
|
|
|
|
* of valid modes on page 331.) 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
|
|
|
{
|
2000-05-24 08:34:26 +04:00
|
|
|
if (argc >= 1) {
|
2004-04-05 19:55:09 +04:00
|
|
|
ID to_open = rb_intern("to_open");
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2004-04-05 19:55:09 +04:00
|
|
|
if (rb_respond_to(argv[0], to_open)) {
|
2004-05-08 12:12:08 +04:00
|
|
|
VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1);
|
* 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
|
|
|
|
2004-05-08 12:12:08 +04:00
|
|
|
if (rb_block_given_p()) {
|
|
|
|
return rb_ensure(rb_yield, io, io_close, io);
|
|
|
|
}
|
|
|
|
return io;
|
2004-04-05 19:55:09 +04:00
|
|
|
}
|
|
|
|
else {
|
2004-04-07 06:51:05 +04:00
|
|
|
VALUE tmp = rb_check_string_type(argv[0]);
|
|
|
|
if (!NIL_P(tmp)) {
|
|
|
|
char *str = StringValuePtr(tmp);
|
|
|
|
if (str && str[0] == '|') {
|
2004-10-31 20:37:52 +03:00
|
|
|
argv[0] = rb_str_new(str+1, RSTRING(tmp)->len-1);
|
|
|
|
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
|
|
|
}
|
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
|
2006-03-01 13:06:03 +03:00
|
|
|
rb_io_open(const char *fname, const char *mode)
|
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);
|
|
|
|
return pipe_open(1, &cmd, mode);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return rb_file_open(fname, mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *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);
|
1999-12-14 09:50:43 +03:00
|
|
|
if (rb_safe_level() >= 4 && (!OBJ_TAINTED(io) || !OBJ_TAINTED(nfile))) {
|
|
|
|
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;
|
2004-12-23 20:53:58 +03:00
|
|
|
#if !defined __CYGWIN__
|
|
|
|
if (IS_PREP_STDIO(fptr)) {
|
|
|
|
if ((fptr->mode & FMODE_READWRITE) != (orig->mode & FMODE_READWRITE)) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
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
|
|
|
|
|
|
|
/* copy OpenFile structure */
|
|
|
|
fptr->mode = orig->mode;
|
|
|
|
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) {
|
2004-11-20 11:49:16 +03:00
|
|
|
#if !defined __CYGWIN__
|
2004-12-23 20:53:58 +03: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-11-20 11:49:16 +03:00
|
|
|
#endif
|
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;
|
2004-11-20 11:49:16 +03:00
|
|
|
#if !defined __CYGWIN__
|
2003-07-26 22:10:47 +04:00
|
|
|
}
|
2004-11-20 11:49:16 +03:00
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
RBASIC(io)->klass = RBASIC(nfile)->klass;
|
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;
|
2004-10-06 11:40:06 +04:00
|
|
|
char *mode;
|
1999-08-13 09:45:20 +04:00
|
|
|
OpenFile *fptr;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
fptr = RFILE(file)->fptr = ALLOC(OpenFile);
|
2004-08-17 13:02:40 +04:00
|
|
|
MEMZERO(fptr, OpenFile, 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)) {
|
2004-12-23 20:53:58 +03:00
|
|
|
int flags = rb_io_mode_flags(StringValuePtr(nmode));
|
|
|
|
if (IS_PREP_STDIO(fptr) &&
|
|
|
|
(fptr->mode & FMODE_READWRITE) != (flags & FMODE_READWRITE)) {
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
fptr->path = strdup(RSTRING(fname)->ptr);
|
2004-10-06 11:40:06 +04:00
|
|
|
mode = rb_io_flags_mode(fptr->mode);
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->fd < 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->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(mode), 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);
|
|
|
|
}
|
|
|
|
|
2004-12-08 16:26:27 +03:00
|
|
|
if (fptr->stdio_file) {
|
|
|
|
if (freopen(RSTRING(fname)->ptr, mode, fptr->stdio_file) == 0) {
|
|
|
|
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)
|
|
|
|
rb_warn("setvbuf() can't be honoured for %s", RSTRING(fname)->ptr);
|
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;
|
|
|
|
fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(mode), 0666);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr, *orig;
|
|
|
|
int fd;
|
|
|
|
|
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
|
|
|
|
|
|
|
/* copy OpenFile 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
|
|
|
}
|
|
|
|
|
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++) {
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!NIL_P(rb_output_fs) && i>0) {
|
|
|
|
rb_io_write(out, rb_output_fs);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
switch (TYPE(argv[i])) {
|
|
|
|
case T_NIL:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, rb_str_new2("nil"));
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
default:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, argv[i]);
|
1998-01-16 15:13:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!NIL_P(rb_output_rs)) {
|
|
|
|
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
|
|
|
{
|
* 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_io_putc(rb_stdout, 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
|
|
|
|
|
|
|
for (i=0; i<RARRAY(ary)->len; i++) {
|
|
|
|
tmp = RARRAY(ary)->ptr[i];
|
* 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
|
|
|
if (recur) {
|
2001-12-10 10:18:16 +03:00
|
|
|
tmp = rb_str_new2("[...]");
|
|
|
|
}
|
|
|
|
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++) {
|
2001-10-30 11:43:28 +03:00
|
|
|
if (NIL_P(argv[i])) {
|
1999-01-20 07:59:39 +03:00
|
|
|
line = rb_str_new2("nil");
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2001-10-30 11:43:28 +03:00
|
|
|
else {
|
2002-12-19 12:20:20 +03:00
|
|
|
line = rb_check_array_type(argv[i]);
|
2001-12-10 10:18:16 +03:00
|
|
|
if (!NIL_P(line)) {
|
* 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_exec_recursive(io_puts_ary, line, out);
|
2001-12-10 10:18:16 +03:00
|
|
|
continue;
|
2001-11-19 08:03:03 +03:00
|
|
|
}
|
2001-10-30 11:43:28 +03:00
|
|
|
line = rb_obj_as_string(argv[i]);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_io_write(out, line);
|
2002-09-06 05:58:32 +04:00
|
|
|
if (RSTRING(line)->len == 0 ||
|
|
|
|
RSTRING(line)->ptr[RSTRING(line)->len-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
|
* 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_puts(int argc, VALUE *argv)
|
1998-01-16 15:19:22 +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_puts(argc, argv, rb_stdout);
|
1998-01-16 15:19:22 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
* 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_write(rb_stdout, rb_obj_as_string(rb_inspect(obj)));
|
|
|
|
rb_io_write(rb_stdout, rb_default_rs);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* p(obj, ...) => 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
|
* 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_p(int argc, VALUE *argv)
|
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
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
for (i=0; i<argc; i++) {
|
|
|
|
rb_p(argv[i]);
|
|
|
|
}
|
* 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
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "01", &out) == 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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +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
|
|
|
defout_setter(VALUE val, ID id, VALUE *variable)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-07-29 22:26:55 +04:00
|
|
|
stdout_setter(val, id, variable);
|
2004-01-26 16:54:41 +03:00
|
|
|
rb_warn("$defout is obsolete; use $stdout instead");
|
* 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 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
|
|
|
deferr_setter(VALUE val, ID id, VALUE *variable)
|
* ext/stringio/stringio.c (strio_gets): only "gets" should set $_.
* ext/stringio/stringio.c (strio_getline): should not set $_ here.
* io.c (argf_to_s): argf.to_s returns "ARGF".
* io.c (set_defout_var, set_deferr_var): make $defout and $deferr
obsolete.
* io.c (set_input_var, set_output_var): allow $stdin, $stdout,
$stderr not to be instance of IO.
* io.c (rb_f_readline): forward method to current_file. gets,
readline, readlines, getc, readchar, tell, seek, pos=, rewind,
fileno, to_io, eof, each_line, each_byte, binmode, and closed?
as well.
* io.c (argf_forward): utility function to forward method to
current_file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-07-28 11:31:52 +04:00
|
|
|
{
|
2003-07-29 22:26:55 +04:00
|
|
|
stdout_setter(val, id, variable);
|
2004-01-26 16:54:41 +03:00
|
|
|
rb_warn("$deferr is obsolete; use $stderr instead");
|
1998-01-16 15:19:22 +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
|
|
|
prep_io(int fd, int mode, VALUE klass, const char *path)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
OpenFile *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)) {
|
2003-03-12 10:59:28 +03:00
|
|
|
mode |= O_BINARY;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
OpenFile *fptr;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-12-08 16:26:27 +03:00
|
|
|
FILE *rb_io_stdio_file(OpenFile *fptr)
|
|
|
|
{
|
|
|
|
if (!fptr->stdio_file) {
|
|
|
|
fptr->stdio_file = rb_fdopen(fptr->fd, rb_io_flags_mode(fptr->mode));
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
OpenFile *fp, *ofp = NULL;
|
|
|
|
int fd, flags, fmode;
|
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)) {
|
|
|
|
flags = FIX2LONG(mode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SafeStringValue(mode);
|
|
|
|
flags = rb_io_mode_modenum(RSTRING(mode)->ptr);
|
|
|
|
}
|
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);
|
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)
|
2004-11-26 09:27:45 +03:00
|
|
|
flags = fcntl(fd, F_GETFL);
|
|
|
|
if (flags == -1) rb_sys_fail(0);
|
2002-04-01 11:39:09 +04:00
|
|
|
#else
|
2004-11-26 09:27:45 +03:00
|
|
|
flags = O_RDONLY;
|
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;
|
2004-11-26 09:27:45 +03:00
|
|
|
fp->mode = rb_io_modenum_flags(flags);
|
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);
|
|
|
|
rb_raise(rb_eIOError, "too many shared IO for %s", StringValuePtr(s));
|
|
|
|
}
|
2004-02-25 15:17:39 +03:00
|
|
|
if (argc == 2) {
|
2004-11-26 09:27:45 +03:00
|
|
|
fmode = rb_io_modenum_flags(flags);
|
2004-02-25 15:17:39 +03:00
|
|
|
if ((ofp->mode ^ fmode) & (FMODE_READWRITE|FMODE_BINMODE)) {
|
|
|
|
if (FIXNUM_P(mode)) {
|
|
|
|
rb_raise(rb_eArgError, "incompatible mode 0%o", flags);
|
|
|
|
}
|
|
|
|
else {
|
2004-11-26 09:27:45 +03:00
|
|
|
rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING(mode)->ptr);
|
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()) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
static int binmode = 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
|
|
|
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
|
|
|
argf_forward(int argc, VALUE *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
|
|
|
{
|
* 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
|
|
|
}
|
|
|
|
|
* 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 {\
|
2004-10-27 13:29:26 +04:00
|
|
|
if (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
|
|
|
return argf_forward(argc, argv);\
|
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 {\
|
* 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 (!next_argv()) return Qnil;\
|
* 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);\
|
* 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
|
|
|
{
|
|
|
|
if (TYPE(file) == T_FILE)
|
|
|
|
rb_io_close(file);
|
|
|
|
else
|
|
|
|
rb_funcall3(file, rb_intern("close"), 0, 0);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +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
|
|
|
next_argv(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
extern VALUE rb_argv;
|
1998-01-16 15:13:05 +03:00
|
|
|
char *fn;
|
2003-01-12 12:24:28 +03:00
|
|
|
OpenFile *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) {
|
1998-01-16 15:19:22 +03:00
|
|
|
if (RARRAY(rb_argv)->len > 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:
|
1998-01-16 15:19:22 +03:00
|
|
|
if (RARRAY(rb_argv)->len > 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
filename = rb_ary_shift(rb_argv);
|
2001-05-02 08:22:21 +04:00
|
|
|
fn = StringValuePtr(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) {
|
1998-01-16 15:13:05 +03:00
|
|
|
struct stat st, st2;
|
|
|
|
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);
|
1998-01-16 15:13:05 +03:00
|
|
|
(void)unlink(RSTRING(str)->ptr);
|
|
|
|
(void)rename(fn, RSTRING(str)->ptr);
|
2004-12-23 21:06:19 +03:00
|
|
|
fr = rb_sysopen(RSTRING(str)->ptr, O_RDONLY, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
|
|
|
if (rename(fn, RSTRING(str)->ptr) < 0) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_warn("Can't rename %s to %s: %s, skipping file",
|
1998-01-16 15:13:05 +03:00
|
|
|
fn, RSTRING(str)->ptr, 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
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
if (binmode) rb_io_binmode(current_file);
|
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
|
* 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_getline(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE line;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
if (!next_argv()) return Qnil;
|
2003-04-25 13:41:08 +04:00
|
|
|
if (argc == 0 && rb_rs == rb_default_rs) {
|
1999-08-13 09:45:20 +04:00
|
|
|
line = rb_io_gets(current_file);
|
|
|
|
}
|
|
|
|
else {
|
2002-02-06 10:30:13 +03:00
|
|
|
VALUE rs;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
rs = rb_rs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_scan_args(argc, argv, "1", &rs);
|
2004-11-23 20:37:51 +03:00
|
|
|
if (!NIL_P(rs)) StringValue(rs);
|
2002-02-06 10:30:13 +03:00
|
|
|
}
|
2004-11-23 20:37:51 +03:00
|
|
|
line = rb_io_getline(rs, current_file);
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (NIL_P(line) && 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;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* gets(separator=$/) => 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
|
|
|
|
* 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 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
|
* 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_gets(int argc, VALUE *argv)
|
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
|
|
|
|
2003-09-05 09:07:54 +04:00
|
|
|
if (!next_argv()) return Qnil;
|
* 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(current_file) != T_FILE) {
|
|
|
|
line = rb_funcall3(current_file, rb_intern("gets"), argc, argv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
line = argf_getline(argc, argv);
|
|
|
|
}
|
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) {
|
|
|
|
return rb_f_gets(0, 0);
|
|
|
|
}
|
|
|
|
|
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) {
|
* 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);
|
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
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2005-01-25 07:03:02 +03:00
|
|
|
* readline(separator=$/) => 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
|
* 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_readline(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
|
|
|
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);
|
* 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
|
|
|
line = rb_f_gets(argc, argv);
|
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-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* obsolete
|
|
|
|
*/
|
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_getc(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_warn("getc is obsolete; use STDIN.getc instead");
|
2003-07-29 11:52:55 +04:00
|
|
|
if (TYPE(rb_stdin) != T_FILE) {
|
|
|
|
return rb_funcall3(rb_stdin, rb_intern("getc"), 0, 0);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
return rb_io_getc(rb_stdin);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-30 19:38:32 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* readlines(separator=$/) => 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
|
2005-01-25 07:03:02 +03:00
|
|
|
* <code>Kernel.gets(<i>separator</i>)</code> until the end of file.
|
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_readlines(int argc, VALUE *argv)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE line, ary;
|
|
|
|
|
* 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(argc, argv);
|
1999-01-20 07:59:39 +03:00
|
|
|
ary = rb_ary_new();
|
2002-02-06 10:30:13 +03:00
|
|
|
while (!NIL_P(line = argf_getline(argc, argv))) {
|
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;
|
2002-03-25 17:50:40 +03:00
|
|
|
OpenFile *fptr;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
SafeStringValue(str);
|
2004-11-02 08:33:11 +03:00
|
|
|
port = pipe_open(1, &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;
|
|
|
|
OpenFile *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);
|
|
|
|
for (i=0; i<RARRAY(read)->len; i++) {
|
1999-08-13 09:45:20 +04:00
|
|
|
GetOpenFile(rb_io_get_io(RARRAY(read)->ptr[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);
|
|
|
|
for (i=0; i<RARRAY(write)->len; i++) {
|
1999-08-13 09:45:20 +04:00
|
|
|
GetOpenFile(rb_io_get_io(RARRAY(write)->ptr[i]), 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);
|
|
|
|
for (i=0; i<RARRAY(except)->len; i++) {
|
1999-08-13 09:45:20 +04:00
|
|
|
GetOpenFile(rb_io_get_io(RARRAY(except)->ptr[i]), 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;
|
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) {
|
|
|
|
list = RARRAY(res)->ptr[0];
|
|
|
|
for (i=0; i< RARRAY(read)->len; i++) {
|
1999-08-13 09:45:20 +04:00
|
|
|
GetOpenFile(rb_io_get_io(RARRAY(read)->ptr[i]), fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
if (rb_fd_isset(fptr->fd, &fds[0]) ||
|
|
|
|
rb_fd_isset(fptr->fd, &fds[3])) {
|
2005-01-09 08:12:29 +03:00
|
|
|
rb_ary_push(list, rb_ary_entry(read, i));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wp) {
|
|
|
|
list = RARRAY(res)->ptr[1];
|
|
|
|
for (i=0; i< RARRAY(write)->len; i++) {
|
1999-08-13 09:45:20 +04:00
|
|
|
GetOpenFile(rb_io_get_io(RARRAY(write)->ptr[i]), fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
if (rb_fd_isset(fptr->fd, &fds[1])) {
|
2005-01-09 08:12:29 +03:00
|
|
|
rb_ary_push(list, rb_ary_entry(write, i));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ep) {
|
|
|
|
list = RARRAY(res)->ptr[2];
|
|
|
|
for (i=0; i< RARRAY(except)->len; i++) {
|
1999-08-13 09:45:20 +04:00
|
|
|
GetOpenFile(rb_io_get_io(RARRAY(except)->ptr[i]), fptr);
|
2005-06-03 18:23:17 +04:00
|
|
|
if (rb_fd_isset(fptr->fd, &fds[2])) {
|
2005-01-09 08:12:29 +03:00
|
|
|
rb_ary_push(list, rb_ary_entry(except, i));
|
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);
|
1998-01-16 15:13:05 +03:00
|
|
|
OpenFile *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
|
|
|
|
2003-06-07 19:34:31 +04:00
|
|
|
if (len <= RSTRING(arg)->len) {
|
|
|
|
len = RSTRING(arg)->len;
|
|
|
|
}
|
|
|
|
if (RSTRING(arg)->len < len) {
|
|
|
|
rb_str_resize(arg, len+1);
|
|
|
|
}
|
|
|
|
RSTRING(arg)->ptr[len] = 17; /* a little sanity check here */
|
|
|
|
narg = (long)RSTRING(arg)->ptr;
|
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);
|
1998-01-16 15:19:22 +03:00
|
|
|
if (TYPE(arg) == T_STRING && RSTRING(arg)->ptr[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");
|
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);
|
2001-05-02 08:22:21 +04:00
|
|
|
arg[i] = (unsigned long)RSTRING(v)->ptr;
|
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);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.pipe -> array
|
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:
|
|
|
|
* <code>[</code> <i>read_file</i>, <i>write_file</i> <code>]</code>. Not
|
|
|
|
* available on all platforms.
|
2004-06-29 05:17:39 +04: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
|
* 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_pipe(VALUE klass)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
#ifndef __human68k__
|
2003-06-23 12:41:07 +04:00
|
|
|
int pipes[2], state;
|
|
|
|
VALUE r, w, args[3];
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
if (pipe(pipes) == -1)
|
|
|
|
rb_sys_fail(0);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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
|
|
|
#else
|
|
|
|
rb_notimplement();
|
1999-01-20 07:59:39 +03:00
|
|
|
return Qnil; /* not reached */
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
struct foreach_arg {
|
|
|
|
int argc;
|
|
|
|
VALUE sep;
|
|
|
|
VALUE 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_foreach(struct foreach_arg *arg)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
|
2004-11-23 20:37:51 +03:00
|
|
|
while (!NIL_P(str = rb_io_getline(arg->sep, 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:
|
|
|
|
* IO.foreach(name, sep_string=$/) {|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
|
|
|
|
* are separated by <em>sep_string</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...
|
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
|
|
|
{
|
2004-11-23 20:37:51 +03:00
|
|
|
VALUE fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct foreach_arg arg;
|
|
|
|
|
2005-08-30 18:49:51 +04:00
|
|
|
RETURN_ENUMERATOR(self, argc, argv);
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_scan_args(argc, argv, "11", &fname, &arg.sep);
|
2004-04-07 10:30:15 +04:00
|
|
|
FilePathValue(fname);
|
2002-02-06 10:30:13 +03:00
|
|
|
if (argc == 1) {
|
|
|
|
arg.sep = rb_default_rs;
|
|
|
|
}
|
2004-11-23 20:37:51 +03:00
|
|
|
else if (!NIL_P(arg.sep)) {
|
|
|
|
StringValue(arg.sep);
|
|
|
|
}
|
|
|
|
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
|
|
|
if (NIL_P(arg.io)) return Qnil;
|
2002-02-06 10:30:13 +03:00
|
|
|
|
2004-11-23 20:37:51 +03:00
|
|
|
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
|
|
|
{
|
2001-01-18 11:43:14 +03:00
|
|
|
return rb_io_readlines(arg->argc, &arg->sep, arg->io);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* IO.readlines(name, sep_string=$/) => 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
|
|
|
|
* <i>sep_string</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
|
|
|
*
|
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
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE fname;
|
1998-01-16 15:13:05 +03:00
|
|
|
struct foreach_arg arg;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &fname, &arg.sep);
|
2004-04-07 10:30:15 +04:00
|
|
|
FilePathValue(fname);
|
1998-01-16 15:13:05 +03:00
|
|
|
arg.argc = argc - 1;
|
1999-01-20 07:59:39 +03:00
|
|
|
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
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
|
|
|
{
|
|
|
|
return io_read(arg->argc, &arg->sep, arg->io);
|
|
|
|
}
|
|
|
|
|
2003-12-27 03:44:05 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2005-01-25 07:03:02 +03:00
|
|
|
* IO.read(name, [length [, offset]] ) => 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
|
|
|
*
|
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
|
|
|
{
|
|
|
|
VALUE fname, offset;
|
|
|
|
struct foreach_arg arg;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "12", &fname, &arg.sep, &offset);
|
2004-04-07 10:30:15 +04:00
|
|
|
FilePathValue(fname);
|
2001-01-18 11:43:14 +03:00
|
|
|
arg.argc = argc ? 1 : 0;
|
|
|
|
arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
|
|
|
|
if (NIL_P(arg.io)) return Qnil;
|
|
|
|
if (!NIL_P(offset)) {
|
2001-03-13 08:45:13 +03:00
|
|
|
rb_io_seek(arg.io, offset, SEEK_SET);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
argf_tell(void)
|
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
|
* 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_seek_m(int argc, VALUE *argv, VALUE self)
|
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
|
* 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_set_pos(VALUE self, 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
|
* 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_rewind(void)
|
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
|
* 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_fileno(void)
|
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
|
* 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_to_io(void)
|
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
|
* 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_eof(void)
|
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
|
* 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_read(int argc, VALUE *argv)
|
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
|
|
|
|
2003-12-30 22:29:56 +03:00
|
|
|
rb_scan_args(argc, argv, "02", &length, &str);
|
|
|
|
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;
|
|
|
|
}
|
* 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(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
|
|
|
tmp = 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
|
|
|
}
|
|
|
|
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) {
|
2003-12-03 20:30:09 +03:00
|
|
|
if (RSTRING(str)->len < len) {
|
|
|
|
len -= RSTRING(str)->len;
|
|
|
|
argv[0] = INT2NUM(len);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2005-01-01 14:25:43 +03:00
|
|
|
static VALUE
|
|
|
|
argf_readpartial_rescue(VALUE dummy)
|
|
|
|
{
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
argf_readpartial(int argc, VALUE *argv)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
if (TYPE(current_file) != T_FILE) {
|
|
|
|
tmp = rb_rescue2(argf_forward, (VALUE)argv,
|
|
|
|
argf_readpartial_rescue, (VALUE)Qnil,
|
|
|
|
rb_eEOFError, (VALUE)0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmp = io_getpartial(argc, argv, current_file);
|
|
|
|
}
|
|
|
|
if (NIL_P(tmp)) {
|
|
|
|
if (next_p == -1) {
|
|
|
|
rb_eof_error();
|
|
|
|
}
|
|
|
|
argf_close(current_file);
|
|
|
|
next_p = 1;
|
|
|
|
if (RARRAY(rb_argv)->len == 0)
|
|
|
|
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
|
* 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_getc(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE byte;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
if (!next_argv()) return Qnil;
|
* 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(current_file) != T_FILE) {
|
|
|
|
byte = rb_funcall3(current_file, rb_intern("getc"), 0, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
byte = rb_io_getc(current_file);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
if (NIL_P(byte) && 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
argf_readchar(void)
|
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);
|
* 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
|
|
|
c = argf_getc();
|
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
|
* 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_each_line(int argc, VALUE *argv, VALUE self)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE str;
|
|
|
|
|
2005-08-30 18:49:51 +04:00
|
|
|
RETURN_ENUMERATOR(self, 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 (!next_argv()) return Qnil;
|
|
|
|
if (TYPE(current_file) != T_FILE) {
|
|
|
|
for (;;) {
|
|
|
|
if (!next_argv()) return argf;
|
2006-02-03 12:15:42 +03:00
|
|
|
rb_block_call(current_file, rb_intern("each"), 0, 0, rb_yield, 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
|
|
|
next_p = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!NIL_P(str = argf_getline(argc, argv))) {
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_yield(str);
|
|
|
|
}
|
1999-08-13 09:45:20 +04:00
|
|
|
return argf;
|
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
|
|
|
argf_each_byte(VALUE self)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE byte;
|
|
|
|
|
2005-08-30 18:49:51 +04:00
|
|
|
RETURN_ENUMERATOR(self, 0, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
while (!NIL_P(byte = argf_getc())) {
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_yield(byte);
|
|
|
|
}
|
2004-01-02 19:21:26 +03:00
|
|
|
return argf;
|
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
|
|
|
argf_filename(void)
|
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
|
* 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_file(void)
|
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
|
* 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_binmode(void)
|
2002-03-28 12:17:54 +03:00
|
|
|
{
|
|
|
|
binmode = 1;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
argf_skip(void)
|
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
|
* 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_m(void)
|
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
|
* 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_closed(void)
|
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
|
* 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_to_s(void)
|
* 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
|
* 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
|
|
|
opt_i_get(void)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
opt_i_set(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;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StringValue(val);
|
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;
|
2001-05-02 08:22:21 +04:00
|
|
|
ruby_inplace_mode = strdup(RSTRING(val)->ptr);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2003-12-24 07:24:29 +03:00
|
|
|
/*
|
|
|
|
* Class <code>IO</code> is the basis for all input and output in Ruby.
|
|
|
|
* An I/O stream may be <em>duplexed</em> (that is, bidirectional), and
|
|
|
|
* so may use more than one native operating system stream.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* Many of the examples in this section use class <code>File</code>,
|
|
|
|
* the only standard subclass of <code>IO</code>. The two classes are
|
|
|
|
* closely associated.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* As used in this section, <em>portname</em> may take any of the
|
|
|
|
* following forms.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* * A plain string represents a filename suitable for the underlying
|
|
|
|
* operating system.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* * A string starting with ``<code>|</code>'' indicates a subprocess.
|
|
|
|
* The remainder of the string following the ``<code>|</code>'' is
|
|
|
|
* invoked as a process with appropriate input/output channels
|
|
|
|
* connected to it.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* * A string equal to ``<code>|-</code>'' will create another Ruby
|
|
|
|
* instance as a subprocess.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* Ruby will convert pathnames between different operating system
|
|
|
|
* conventions if possible. For instance, on a Windows system the
|
|
|
|
* filename ``<code>/gumby/ruby/test.rb</code>'' will be opened as
|
|
|
|
* ``<code>\gumby\ruby\test.rb</code>''. When specifying a
|
|
|
|
* Windows-style filename in a Ruby string, remember to escape the
|
|
|
|
* backslashes:
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* "c:\\gumby\\ruby\\test.rb"
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* Our examples here will use the Unix-style forward slashes;
|
|
|
|
* <code>File::SEPARATOR</code> can be used to get the
|
|
|
|
* platform-specific separator character.
|
2004-06-29 05:17:39 +04:00
|
|
|
*
|
2003-12-24 07:24:29 +03:00
|
|
|
* I/O ports may be opened in any one of several different modes, which
|
2003-12-27 03:44:05 +03:00
|
|
|
* are shown in this section as <em>mode</em>. The mode may
|
|
|
|
* either be a Fixnum or a String. If numeric, it should be
|
|
|
|
* one of the operating system specific constants (O_RDONLY,
|
|
|
|
* O_WRONLY, O_RDWR, O_APPEND and so on). See man open(2) for
|
|
|
|
* more information.
|
|
|
|
*
|
|
|
|
* If the mode is given as a String, it must be one of the
|
|
|
|
* values listed in the following table.
|
2003-12-24 07:24:29 +03:00
|
|
|
*
|
|
|
|
* Mode | Meaning
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "r" | Read-only, starts at beginning of file (default mode).
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "r+" | Read-write, starts at beginning of file.
|
|
|
|
* -----+--------------------------------------------------------
|
2004-06-29 05:17:39 +04:00
|
|
|
* "w" | Write-only, truncates existing file
|
2003-12-24 07:24:29 +03:00
|
|
|
* | to zero length or creates a new file for writing.
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "w+" | Read-write, truncates existing file to zero length
|
|
|
|
* | or creates a new file for reading and writing.
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "a" | Write-only, starts at end of file if file exists,
|
|
|
|
* | otherwise creates a new file for writing.
|
|
|
|
* -----+--------------------------------------------------------
|
|
|
|
* "a+" | Read-write, starts at end of file if file exists,
|
2004-06-29 05:17:39 +04:00
|
|
|
* | otherwise creates a new file for reading and
|
2003-12-24 07:24:29 +03:00
|
|
|
* | writing.
|
|
|
|
* -----+--------------------------------------------------------
|
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
|
|
|
{
|
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");
|
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("getc", rb_f_getc, 0);
|
|
|
|
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);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_singleton_method(rb_cIO, "pipe", rb_io_s_pipe, 0);
|
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_hooked_variable("$.", &lineno, 0, lineno_setter);
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
rb_define_method(rb_cIO, "getc", rb_io_getc, 0);
|
|
|
|
rb_define_method(rb_cIO, "readchar", rb_io_readchar, 0);
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
rb_define_method(rb_cIO, "binmode", rb_io_binmode, 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
|
|
|
|
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
|
|
|
|
|
|
|
/* variables to be removed in 1.8.1 */
|
2003-07-29 22:26:55 +04:00
|
|
|
rb_define_hooked_variable("$defout", &rb_stdout, 0, defout_setter);
|
|
|
|
rb_define_hooked_variable("$deferr", &rb_stderr, 0, deferr_setter);
|
* 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);
|
|
|
|
|
2005-12-12 06:04:53 +03:00
|
|
|
rb_define_readonly_variable("$<", &argf);
|
1999-01-20 07:59:39 +03:00
|
|
|
argf = rb_obj_alloc(rb_cObject);
|
|
|
|
rb_extend_object(argf, rb_mEnumerable);
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_define_global_const("ARGF", 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
|
|
|
rb_define_singleton_method(argf, "to_s", argf_to_s, 0);
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_singleton_method(argf, "fileno", argf_fileno, 0);
|
|
|
|
rb_define_singleton_method(argf, "to_i", argf_fileno, 0);
|
|
|
|
rb_define_singleton_method(argf, "to_io", argf_to_io, 0);
|
|
|
|
rb_define_singleton_method(argf, "each", argf_each_line, -1);
|
|
|
|
rb_define_singleton_method(argf, "each_line", argf_each_line, -1);
|
|
|
|
rb_define_singleton_method(argf, "each_byte", argf_each_byte, 0);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_singleton_method(argf, "read", argf_read, -1);
|
2005-01-01 14:25:43 +03:00
|
|
|
rb_define_singleton_method(argf, "readpartial", argf_readpartial, -1);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_singleton_method(argf, "readlines", rb_f_readlines, -1);
|
|
|
|
rb_define_singleton_method(argf, "to_a", rb_f_readlines, -1);
|
|
|
|
rb_define_singleton_method(argf, "gets", rb_f_gets, -1);
|
|
|
|
rb_define_singleton_method(argf, "readline", rb_f_readline, -1);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_singleton_method(argf, "getc", argf_getc, 0);
|
|
|
|
rb_define_singleton_method(argf, "readchar", argf_readchar, 0);
|
|
|
|
rb_define_singleton_method(argf, "tell", argf_tell, 0);
|
2001-03-13 08:45:13 +03:00
|
|
|
rb_define_singleton_method(argf, "seek", argf_seek_m, -1);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_singleton_method(argf, "rewind", argf_rewind, 0);
|
|
|
|
rb_define_singleton_method(argf, "pos", argf_tell, 0);
|
|
|
|
rb_define_singleton_method(argf, "pos=", argf_set_pos, 1);
|
|
|
|
rb_define_singleton_method(argf, "eof", argf_eof, 0);
|
|
|
|
rb_define_singleton_method(argf, "eof?", argf_eof, 0);
|
|
|
|
rb_define_singleton_method(argf, "binmode", argf_binmode, 0);
|
|
|
|
|
|
|
|
rb_define_singleton_method(argf, "filename", argf_filename, 0);
|
2003-05-19 10:27:06 +04:00
|
|
|
rb_define_singleton_method(argf, "path", argf_filename, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_singleton_method(argf, "file", argf_file, 0);
|
|
|
|
rb_define_singleton_method(argf, "skip", argf_skip, 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
|
|
|
rb_define_singleton_method(argf, "close", argf_close_m, 0);
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_define_singleton_method(argf, "closed?", argf_closed, 0);
|
|
|
|
|
|
|
|
rb_define_singleton_method(argf, "lineno", argf_lineno, 0);
|
|
|
|
rb_define_singleton_method(argf, "lineno=", argf_set_lineno, 1);
|
|
|
|
|
|
|
|
rb_global_variable(¤t_file);
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_define_readonly_variable("$FILENAME", &filename);
|
2005-12-12 06:04:53 +03:00
|
|
|
filename = rb_str_new2("-");
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
rb_define_virtual_variable("$-i", opt_i_get, opt_i_set);
|
|
|
|
|
* 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));
|
|
|
|
#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
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|