From 3976feed73bf4ec27183824870ee077c2b5b00b1 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 24 Feb 1999 04:31:29 +0000 Subject: 990224 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 142 +++++++++++++++++++++++++++++++------------------------------------ 1 file changed, 65 insertions(+), 77 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 24122f9e13..9eba04ad7e 100644 --- a/io.c +++ b/io.c @@ -59,6 +59,9 @@ struct timeval { extern void Init_File _((void)); #ifdef __BEOS__ +# ifdef _X86_ +# define NOFILE (OPEN_MAX) +# endif #include #endif @@ -1229,6 +1232,7 @@ rb_file_sysopen(fname, flags, mode) MakeOpenFile(port, fptr); fd = rb_open(fname, flags, mode); + m = rb_io_flags_mode(flags); fptr->mode = rb_io_mode_flags2(flags); fptr->f = rb_fdopen(fd, m); fptr->path = strdup(fname); @@ -2207,76 +2211,13 @@ rb_f_readline(argc, argv) return line; } -static VALUE -rb_f_tell() -{ - return rb_io_tell(file); -} - -static VALUE -rb_f_seek(self, offset, ptrname) - VALUE self, offset, ptrname; -{ - if (!next_argv()) { - rb_raise(rb_eArgError, "no stream to seek"); - } - - return rb_io_seek(file, offset, ptrname); -} - -static VALUE -rb_f_set_pos(self, offset) - VALUE self, offset; -{ - if (!next_argv()) { - rb_raise(rb_eArgError, "no stream to pos"); - } - - return rb_io_set_pos(file, offset); -} - -static VALUE -rb_f_rewind() -{ - return rb_io_rewind(file); -} - -static VALUE -rb_f_eof() -{ - if (init_p == 0 && !next_argv()) - return Qtrue; - if (rb_io_eof(file)) { - next_p = 1; - return Qtrue; - } - return Qfalse; -} - static VALUE rb_f_getc() { + rb_warn("getc is obsolete; use STDIN.getc instead"); return rb_io_getc(rb_stdin); } -static VALUE -rb_f_ungetc(self, c) - VALUE self, c; -{ - return rb_io_ungetc(rb_stdin, c); -} - -static VALUE -rb_f_readchar() -{ - VALUE c = rb_f_getc(); - - if (NIL_P(c)) { - rb_eof_error(); - } - return c; -} - static VALUE rb_f_readlines(argc, argv) int argc; @@ -2780,6 +2721,40 @@ rb_io_s_readlines(argc, argv, io) return rb_ensure(rb_io_readline_line, (VALUE)&arg, rb_io_close, arg.io); } +static VALUE +arg_tell() +{ + return rb_io_tell(file); +} + +static VALUE +arg_seek(self, offset, ptrname) + VALUE self, offset, ptrname; +{ + if (!next_argv()) { + rb_raise(rb_eArgError, "no stream to seek"); + } + + return rb_io_seek(file, offset, ptrname); +} + +static VALUE +arg_set_pos(self, offset) + VALUE self, offset; +{ + if (!next_argv()) { + rb_raise(rb_eArgError, "no stream to pos"); + } + + return rb_io_set_pos(file, offset); +} + +static VALUE +arg_rewind() +{ + return rb_io_rewind(file); +} + static VALUE arg_fileno() { @@ -2854,6 +2829,25 @@ arg_readchar() return c; } +static VALUE +arg_eof() +{ + if (init_p == 0 && !next_argv()) + return Qtrue; + if (rb_io_eof(file)) { + next_p = 1; + return Qtrue; + } + return Qfalse; +} + +static VALUE +rb_f_eof() +{ + rb_warn("eof? is obsolete; use ARGF.eof? instead"); + return arg_eof(); +} + static VALUE arg_each_line(argc, argv) int argc; @@ -2952,15 +2946,10 @@ Init_IO() 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("tell", rb_f_tell, 0); - rb_define_global_function("seek", rb_f_seek, 2); - rb_define_global_function("rewind", rb_f_rewind, 0); rb_define_global_function("eof", rb_f_eof, 0); rb_define_global_function("eof?", rb_f_eof, 0); rb_define_global_function("getc", rb_f_getc, 0); - rb_define_global_function("readchar", rb_f_readchar, 0); rb_define_global_function("select", rb_f_select, -1); - rb_define_global_function("ungetc", rb_f_ungetc, 1); rb_define_global_function("readlines", rb_f_readlines, -1); @@ -3086,14 +3075,13 @@ Init_IO() rb_define_singleton_method(argf, "readline", rb_f_readline, -1); rb_define_singleton_method(argf, "getc", arg_getc, 0); rb_define_singleton_method(argf, "readchar", arg_readchar, 0); - rb_define_singleton_method(argf, "tell", rb_f_tell, 0); - rb_define_singleton_method(argf, "seek", rb_f_seek, 2); - rb_define_singleton_method(argf, "rewind", rb_f_rewind, 0); - rb_define_singleton_method(argf, "pos", rb_f_tell, 0); - rb_define_singleton_method(argf, "pos=", rb_f_set_pos, 1); - rb_define_singleton_method(argf, "eof", rb_f_eof, 0); - rb_define_singleton_method(argf, "eof?", rb_f_eof, 0); - rb_define_singleton_method(argf, "ungetc", rb_f_ungetc, 1); + rb_define_singleton_method(argf, "tell", arg_tell, 0); + rb_define_singleton_method(argf, "seek", arg_seek, 2); + rb_define_singleton_method(argf, "rewind", arg_rewind, 0); + rb_define_singleton_method(argf, "pos", arg_tell, 0); + rb_define_singleton_method(argf, "pos=", arg_set_pos, 1); + rb_define_singleton_method(argf, "eof", arg_eof, 0); + rb_define_singleton_method(argf, "eof?", arg_eof, 0); rb_define_singleton_method(argf, "to_s", arg_filename, 0); rb_define_singleton_method(argf, "filename", arg_filename, 0); -- cgit v1.2.3