summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-25 10:56:41 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-12-25 10:56:41 +0000
commit918bb50674e565621b6b370756eff50d224274f1 (patch)
tree63c8baa5d8032e4332084140f594e6ed3354bed1 /io.c
parentae434c6035a54dc0a1ddf65d3567f2c6c375092f (diff)
* stable version 1.8.2 released.
* lib/fileutils.rb (mkdir, mkdir_p): should ensure directory permission. (backportted from HEAD, 1.47) * lib/fileutils.rb (traverse, remove_dir): untaint trasted objects. (backportted from HEAD, 1.46) * io.c: cancel io_reopen() change on Dec. 24th. * dln.c: use <dlfcn.h> for NetBSD. [ruby-dev:25313] * io.c (rb_f_select): [ruby-dev:25312] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c66
1 files changed, 28 insertions, 38 deletions
diff --git a/io.c b/io.c
index f827e4e..a22802b 100644
--- a/io.c
+++ b/io.c
@@ -1815,10 +1815,6 @@ rb_io_isatty(io)
return Qtrue;
}
-#define FMODE_PREP (1<<16)
-#define IS_PREP_STDIO(f) ((f)->mode & FMODE_PREP)
-#define PREP_STDIO_NAME(f) ((f)->path)
-
static void
fptr_finalize(fptr, noraise)
OpenFile *fptr;
@@ -3155,16 +3151,6 @@ io_reopen(io, nfile)
GetOpenFile(nfile, orig);
if (fptr == orig) return io;
-#if !defined __CYGWIN__
- if (IS_PREP_STDIO(fptr)) {
- if ((fptr->mode & FMODE_READWRITE) != (orig->mode & FMODE_READWRITE)) {
- rb_raise(rb_eArgError,
- "%s cannot change access mode from \"%s\" to \"%s\"",
- PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
- rb_io_flags_mode(orig->mode));
- }
- }
-#endif
if (orig->mode & FMODE_READABLE) {
pos = io_tell(orig);
}
@@ -3191,7 +3177,7 @@ io_reopen(io, nfile)
fd = fileno(fptr->f);
fd2 = fileno(orig->f);
if (fd != fd2) {
- if (IS_PREP_STDIO(fptr)) {
+ if (fptr->f == stdin || fptr->f == stdout || fptr->f == stderr) {
clearerr(fptr->f);
/* need to keep stdio objects */
if (dup2(fd2, fd) < 0)
@@ -3289,15 +3275,7 @@ rb_io_reopen(argc, argv, file)
}
if (!NIL_P(nmode)) {
- int flags = rb_io_mode_flags(StringValuePtr(nmode));
- if (IS_PREP_STDIO(fptr) &&
- (fptr->mode & FMODE_READWRITE) != (flags & FMODE_READWRITE)) {
- rb_raise(rb_eArgError,
- "%s cannot change access mode from \"%s\" to \"%s\"",
- PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
- rb_io_flags_mode(flags));
- }
- fptr->mode = flags;
+ fptr->mode = rb_io_mode_flags(StringValuePtr(nmode));
}
if (fptr->path) {
@@ -3804,11 +3782,10 @@ deferr_setter(val, id, variable)
}
static VALUE
-prep_stdio(f, mode, klass, path)
+prep_stdio(f, mode, klass)
FILE *f;
int mode;
VALUE klass;
- const char *path;
{
OpenFile *fp;
VALUE io = io_alloc(klass);
@@ -3821,12 +3798,23 @@ prep_stdio(f, mode, klass, path)
}
#endif
fp->f = f;
- fp->mode = mode | FMODE_PREP;
- fp->path = strdup(path);
+ fp->mode = mode;
return io;
}
+static void
+prep_path(io, path)
+ VALUE io;
+ char *path;
+{
+ OpenFile *fptr;
+
+ GetOpenFile(io, fptr);
+ if (fptr->path) rb_bug("illegal prep_path() call");
+ fptr->path = strdup(path);
+}
+
/*
* call-seq:
* IO.new(fd, mode) => io
@@ -4097,10 +4085,12 @@ next_argv()
fchown(fileno(fw), st.st_uid, st.st_gid);
}
#endif
- rb_stdout = prep_stdio(fw, FMODE_WRITABLE, rb_cFile, fn);
+ rb_stdout = prep_stdio(fw, FMODE_WRITABLE, rb_cFile);
+ prep_path(rb_stdout, fn);
if (stdout_binmode) rb_io_binmode(rb_stdout);
}
- current_file = prep_stdio(fr, FMODE_READABLE, rb_cFile, fn);
+ current_file = prep_stdio(fr, FMODE_READABLE, rb_cFile);
+ prep_path(current_file, fn);
}
if (binmode) rb_io_binmode(current_file);
}
@@ -4440,7 +4430,7 @@ rb_f_select(argc, argv, obj)
GetOpenFile(rb_io_get_io(RARRAY(read)->ptr[i]), fptr);
if (FD_ISSET(fileno(fptr->f), rp)
|| FD_ISSET(fileno(fptr->f), &pset)) {
- rb_ary_push(list, RARRAY(read)->ptr[i]);
+ rb_ary_push(list, rb_ary_entry(read, i));
}
}
}
@@ -4450,10 +4440,10 @@ rb_f_select(argc, argv, obj)
for (i=0; i< RARRAY(write)->len; i++) {
GetOpenFile(rb_io_get_io(RARRAY(write)->ptr[i]), fptr);
if (FD_ISSET(fileno(fptr->f), wp)) {
- rb_ary_push(list, RARRAY(write)->ptr[i]);
+ rb_ary_push(list, rb_ary_entry(write, i));
}
else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), wp)) {
- rb_ary_push(list, RARRAY(write)->ptr[i]);
+ rb_ary_push(list, rb_ary_entry(write, i));
}
}
}
@@ -4463,10 +4453,10 @@ rb_f_select(argc, argv, obj)
for (i=0; i< RARRAY(except)->len; i++) {
GetOpenFile(rb_io_get_io(RARRAY(except)->ptr[i]), fptr);
if (FD_ISSET(fileno(fptr->f), ep)) {
- rb_ary_push(list, RARRAY(except)->ptr[i]);
+ rb_ary_push(list, rb_ary_entry(except, i));
}
else if (fptr->f2 && FD_ISSET(fileno(fptr->f2), ep)) {
- rb_ary_push(list, RARRAY(except)->ptr[i]);
+ rb_ary_push(list, rb_ary_entry(except, i));
}
}
}
@@ -5454,11 +5444,11 @@ Init_IO()
rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
rb_define_method(rb_cIO, "inspect", rb_io_inspect, 0);
- rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO, "<STDIN>");
+ rb_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
rb_define_variable("$stdin", &rb_stdin);
- rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO, "<STDOUT>");
+ rb_stdout = prep_stdio(stdout, FMODE_WRITABLE, rb_cIO);
rb_define_hooked_variable("$stdout", &rb_stdout, 0, stdout_setter);
- rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO, "<STDERR>");
+ rb_stderr = prep_stdio(stderr, FMODE_WRITABLE, rb_cIO);
rb_define_hooked_variable("$stderr", &rb_stderr, 0, stdout_setter);
rb_define_hooked_variable("$>", &rb_stdout, 0, stdout_setter);
orig_stdout = rb_stdout;