[#19261] lstripped here-document (Re: comments and continuing strings on the next line) — nobu.nakada@...

なかだです。

29 messages 2003/01/01
[#19360] Re: lstripped here-document (Re: comments and continuing strings on the next line) — "K.Kosako" <kosako@...> 2003/01/15

nobu.nakada@nifty.ne.jpさんの

[#19361] Re: lstripped here-document (Re: comments and continuing strings on the next line) — "NAKAMURA, Hiroshi" <nakahiro@...> 2003/01/15

なひです。

[#19364] Re: lstripped here-document (Re: comments and continuing strings on the next line) — nobu.nakada@... 2003/01/17

なかだです。

[#19366] Re: lstripped here-document (Re: comments and continuing strings on the next line) — "NAKAMURA, Hiroshi" <nakahiro@...> 2003/01/17

なひです。

[#19299] [BUG] errno == 0 — Kazuhiro Yoshida <moriq@...>

もりきゅうです。win32だけかもしれません。

22 messages 2003/01/04
[#19301] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19302] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19303] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19304] Re: [BUG] errno == 0 — "U.Nakamura" <usa@...> 2003/01/04

こんにちは、なかむら(う)です。

[#19306] Re: [BUG] errno == 0 — nobu.nakada@... 2003/01/05

なかだです。

[ruby-dev:19442] pipe reopen

From: nobu.nakada@...
Date: 2003-01-27 03:46:43 UTC
List: ruby-dev #19442
なかだです。

R/Wで作ったpipeに対するreopenの動作がちょっとおかしいような気が
します。最初のSTDIN.closeがなければ正常に動きますが、あると最後
のputsでErrno::EBADFになります。

STDIN.close
unless pi = IO.popen("-", "r+")
  sleep(1)
  exit
end
pi.reopen(open("xyzzy", "w+"))
pi.puts("foo")

一応こんなのを考えてみましたが、どうもlinux(というかglibc)では、
fdopen()のときのモードを覚えておいてそれに合わない操作はエラー
になるようで、fptr->fからは書き込みはできないようです。


Index: io.c
===================================================================
RCS file: /cvs/ruby/src/ruby/io.c,v
retrieving revision 1.182
diff -u -2 -p -r1.182 io.c
--- io.c	16 Jan 2003 07:34:01 -0000	1.182
+++ io.c	27 Jan 2003 03:44:05 -0000
@@ -2304,11 +2304,9 @@ io_reopen(io, nfile)
     if (fptr == orig) return io;
     if (orig->mode & FMODE_READABLE) {
-	pos = io_tell(orig);
+	io_fflush(GetWriteFile(orig), orig);
+	pos = ftello(orig->f);
     }
-    if (orig->f2) {
-	io_fflush(orig->f2, orig);
-    }
-    else if (orig->mode & FMODE_WRITABLE) {
-	io_fflush(orig->f, orig);
+    if (fptr->f2) {
+	io_fflush(fptr->f2, orig);
     }
     rb_thread_fd_close(fileno(fptr->f));
@@ -2342,14 +2340,7 @@ io_reopen(io, nfile)
     }
 
-    if (fptr->f2) {
-	fd = fileno(fptr->f2);
-	fclose(fptr->f2);
-	if (orig->f2) {
-	    if (dup2(fileno(orig->f2), fd) < 0)
-		rb_sys_fail(orig->path);
-	    fptr->f2 = rb_fdopen(fd, "w");
-	}
-	else {
-	    fptr->f2 = 0;
+    if (fptr->f2 && fd != fileno(fptr->f2)) {
+	if (dup2(fileno(GetWriteFile(orig)), fileno(fptr->f2)) < 0) {
+	    rb_sys_fail(orig->path);
 	}
     }


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next