1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (rb_io_initialize): [ruby-dev:24963]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-11-26 06:27:45 +00:00
parent c97c359053
commit 6d0f22ebc6
2 changed files with 15 additions and 17 deletions

View file

@ -1,5 +1,7 @@
Fri Nov 26 14:29:39 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_initialize): [ruby-dev:24963]
* io.c (rb_io_initialize): [ruby-dev:24962]
Fri Nov 26 13:49:06 2004 Yukihiro Matsumoto <matz@ruby-lang.org>

30
io.c
View file

@ -3970,6 +3970,17 @@ rb_io_initialize(argc, argv, io)
orig = rb_io_check_io(fnum);
if (NIL_P(orig)) {
fd = NUM2INT(fnum);
if (argc != 2) {
#if defined(HAVE_FCNTL) && defined(F_GETFL)
flags = fcntl(fd, F_GETFL);
if (flags == -1) rb_sys_fail(0);
#else
flags = O_RDONLY;
#endif
}
MakeOpenFile(io, fp);
fp->mode = rb_io_modenum_flags(flags);
fp->f = rb_fdopen(fd, rb_io_modenum_mode(flags));
}
else {
GetOpenFile(orig, ofp);
@ -3977,29 +3988,14 @@ rb_io_initialize(argc, argv, io)
VALUE s = rb_inspect(orig);
rb_raise(rb_eIOError, "too many shared IO for %s", StringValuePtr(s));
}
}
if (argc != 2) {
#if defined(HAVE_FCNTL) && defined(F_GETFL)
flags = fcntl(fd, F_GETFL);
if (flags == -1) rb_sys_fail(0);
#else
flags = O_RDONLY;
#endif
}
fmode = rb_io_modenum_flags(flags);
if (!ofp) {
MakeOpenFile(io, fp);
fp->mode = fmode;
fp->f = rb_fdopen(fd, rb_io_modenum_mode(flags));
}
else {
if (argc == 2) {
fmode = rb_io_modenum_flags(flags);
if ((ofp->mode ^ fmode) & (FMODE_READWRITE|FMODE_BINMODE)) {
if (FIXNUM_P(mode)) {
rb_raise(rb_eArgError, "incompatible mode 0%o", flags);
}
else {
rb_raise(rb_eArgError, "incompatible mode %s", RSTRING(mode)->ptr);
rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING(mode)->ptr);
}
}
}