diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-23 05:35:32 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-05-23 05:35:32 +0000 |
commit | 6e87a54aecec13d500f90ed4a19ffebc6883794b (patch) | |
tree | 8dad6991e36a9eb9ad560c31b6e16ea9edb2a682 /io.c | |
parent | 730d8f1d326a62d86e41faa0482f9a3c329832cb (diff) | |
download | ruby-6e87a54aecec13d500f90ed4a19ffebc6883794b.tar.gz |
* ruby.c (proc_options): removed "-*-" support for #! line.
* io.c (rb_io_s_sysopen): new method to get a raw file
descriptor. [new]
* ext/socket/socket.c (tcp_sysaccept): new method to return an
accepted socket fd (integer). [new]
* ext/socket/socket.c (unix_sysaccept,sock_sysaccept): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -1966,7 +1966,7 @@ rb_open_file(argc, argv, io) VALUE *argv; VALUE io; { - VALUE fname, vmode, file, perm; + VALUE fname, vmode, perm; char *path, *mode; int flags, fmode; @@ -1978,11 +1978,11 @@ rb_open_file(argc, argv, io) flags = FIXNUM_P(vmode) ? NUM2INT(vmode) : rb_io_mode_modenum(StringValuePtr(vmode)); fmode = NIL_P(perm) ? 0666 : NUM2INT(perm); - file = rb_file_sysopen_internal(io, path, flags, fmode); + rb_file_sysopen_internal(io, path, flags, fmode); } else { mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode); - file = rb_file_open_internal(io, RSTRING(fname)->ptr, mode); + rb_file_open_internal(io, RSTRING(fname)->ptr, mode); } return io; } @@ -2003,6 +2003,29 @@ rb_io_s_open(argc, argv, klass) } static VALUE +rb_io_s_sysopen(argc, argv) + int argc; + VALUE *argv; +{ + VALUE fname, vmode, perm; + int flags, fmode, fd; + + rb_scan_args(argc, argv, "12", &fname, &vmode, &perm); + SafeStringValue(fname); + + if (NIL_P(vmode)) flags = O_RDONLY; + else if (FIXNUM_P(vmode)) flags = NUM2INT(vmode); + else { + flags = rb_io_mode_modenum(StringValuePtr(vmode)); + } + if (NIL_P(perm)) fmode = 0666; + else fmode = NUM2INT(perm); + + fd = rb_sysopen(RSTRING(fname)->ptr, flags, fmode); + return INT2NUM(fd); +} + +static VALUE rb_f_open(argc, argv) int argc; VALUE *argv; @@ -3706,6 +3729,7 @@ Init_IO() rb_define_singleton_method(rb_cIO, "allocate", rb_io_s_alloc, 0); rb_define_singleton_method(rb_cIO, "new", rb_io_s_new, -1); rb_define_singleton_method(rb_cIO, "open", rb_io_s_open, -1); + rb_define_singleton_method(rb_cIO, "sysopen", rb_io_s_sysopen, -1); rb_define_singleton_method(rb_cIO, "for_fd", rb_class_new_instance, -1); rb_define_singleton_method(rb_cIO, "popen", rb_io_s_popen, -1); rb_define_singleton_method(rb_cIO, "foreach", rb_io_s_foreach, -1); |