diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-06-23 08:41:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-06-23 08:41:07 +0000 |
commit | 69459d98ef81c26291d8504dbcd904eda71e7e31 (patch) | |
tree | 25516e057647a261ce2521cbafd60ec582892eb3 /io.c | |
parent | 2aba26fa521e1a4405546b50c08de0d90b5bfd44 (diff) |
* dir.c (find_dirsep): get rid of warnings.
* eval.c (error_print): temporary value might be disposed by GC.
* hash.c (env_has_value, env_index): should not increment NULL.
* io.c (io_read, rb_io_sysread): not read when length is 0.
* io.c (rb_io_reopen): ensure initialized IO.
* io.c (rb_io_init_copy): sychronize file pointer.
* io.c (rb_io_s_pipe): make exception proof.
* string.c (rb_str_rindex_m): Fixnum 0 matched end of string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 45 |
1 files changed, 39 insertions, 6 deletions
@@ -823,13 +823,13 @@ io_read(argc, argv, io) if (feof(fptr->f)) return Qnil; if (NIL_P(str)) { str = rb_str_new(0, len); - if (len == 0) return str; } else { StringValue(str); rb_str_modify(str); rb_str_resize(str,len); } + if (len == 0) return str; READ_CHECK(fptr->f); n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f); @@ -1573,6 +1573,7 @@ rb_io_sysread(argc, argv, io) rb_str_modify(str); rb_str_resize(str, ilen); } + if (ilen == 0) return str; n = fileno(fptr->f); rb_thread_wait_fd(fileno(fptr->f)); @@ -2439,6 +2440,9 @@ rb_io_reopen(argc, argv, file) rb_io_taint_check(file); fptr = RFILE(file)->fptr; + if (!fptr) { + fptr = RFILE(file)->fptr = ALLOC(OpenFile); + } if (!NIL_P(nmode)) { mode = StringValuePtr(nmode); @@ -2497,10 +2501,14 @@ rb_io_init_copy(dest, io) if (orig->f2) { io_fflush(orig->f2, orig); + fseeko(orig->f, 0L, SEEK_CUR); } else if (orig->mode & FMODE_WRITABLE) { io_fflush(orig->f, orig); } + else { + fseeko(orig->f, 0L, SEEK_CUR); + } /* copy OpenFile structure */ fptr->mode = orig->mode; @@ -3528,12 +3536,21 @@ rb_f_syscall(argc, argv) #endif } +static VALUE io_new_instance _((VALUE)); static VALUE -rb_io_s_pipe() +io_new_instance(args) + VALUE args; +{ + return rb_class_new_instance(2, (VALUE*)args+1, *(VALUE*)args); +} + +static VALUE +rb_io_s_pipe(klass) + VALUE klass; { #ifndef __human68k__ - int pipes[2]; - VALUE r, w; + int pipes[2], state; + VALUE r, w, args[3]; #ifdef _WIN32 if (_pipe(pipes, 1024, O_BINARY) == -1) @@ -3542,8 +3559,24 @@ rb_io_s_pipe() #endif rb_sys_fail(0); - r = prep_stdio(rb_fdopen(pipes[0], "r"), FMODE_READABLE, rb_cIO); - w = prep_stdio(rb_fdopen(pipes[1], "w"), FMODE_WRITABLE|FMODE_SYNC, rb_cIO); + 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); return rb_assoc_new(r, w); #else |