[前][次][番号順一覧][スレッド一覧]

ruby-changes:10272

From: yugui <ko1@a...>
Date: Wed, 28 Jan 2009 18:21:28 +0900 (JST)
Subject: [ruby-changes:10272] Ruby:r21816 (ruby_1_9_1): merges r21709, r21710 from trunk into ruby_1_9_1.

yugui	2009-01-28 18:20:37 +0900 (Wed, 28 Jan 2009)

  New Revision: 21816

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21816

  Log:
    merges r21709, r21710 from trunk into ruby_1_9_1.
    * include/ruby/io.h (FMODE_EOF): EOF flag on TTY.
    * io.c (io_set_eof): sets EOF flag for TTY.
    * io.c (io_seek): clears EOF flag.
    * io.c (io_fillbuf): returns EOF if already met EOF.  [ruby-dev:37798]
    * io.c (io_fillbuf, io_fread, io_getpartial): sets EOF.

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/include/ruby/io.h
    branches/ruby_1_9_1/io.c

Index: ruby_1_9_1/include/ruby/io.h
===================================================================
--- ruby_1_9_1/include/ruby/io.h	(revision 21815)
+++ ruby_1_9_1/include/ruby/io.h	(revision 21816)
@@ -92,6 +92,7 @@
 #define FMODE_WSPLIT_INITIALIZED    0x00000400
 #define FMODE_TRUNC                 0x00000800
 #define FMODE_TEXTMODE              0x00001000
+#define FMODE_EOF                   0x00002000
 /* #define FMODE_PREP               0x00010000 */
 
 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 21815)
+++ ruby_1_9_1/ChangeLog	(revision 21816)
@@ -1,3 +1,15 @@
+Wed Jan 21 13:58:17 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* include/ruby/io.h (FMODE_EOF): EOF flag on TTY.
+
+	* io.c (io_set_eof): sets EOF flag for TTY.
+
+	* io.c (io_seek): clears EOF flag.
+
+	* io.c (io_fillbuf): returns EOF if already met EOF.  [ruby-dev:37798]
+
+	* io.c (io_fillbuf, io_fread, io_getpartial): sets EOF.
+
 Wed Jan 21 14:41:48 2009  NAKAMURA Usaku  <usa@r...>
 
 	* array.c (take_items): to_ary() raises ArgumentError if cannot to
Index: ruby_1_9_1/io.c
===================================================================
--- ruby_1_9_1/io.c	(revision 21815)
+++ ruby_1_9_1/io.c	(revision 21816)
@@ -353,7 +353,8 @@
     return fptr;
 }
 
-#define io_seek(fptr, ofs, whence) lseek(flush_before_seek(fptr)->fd, ofs, whence)
+#define io_set_eof(fptr) (void)(((fptr)->mode & FMODE_TTY) && ((fptr)->mode |= FMODE_EOF))
+#define io_seek(fptr, ofs, whence) (fptr->mode &= ~FMODE_EOF, lseek(flush_before_seek(fptr)->fd, ofs, whence))
 #define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
 
 #ifndef SEEK_CUR
@@ -1147,6 +1148,9 @@
 {
     int r;
 
+    if (fptr->mode & FMODE_EOF) {
+	return -1;
+    }
     if (fptr->rbuf == NULL) {
         fptr->rbuf_off = 0;
         fptr->rbuf_len = 0;
@@ -1165,8 +1169,10 @@
         }
         fptr->rbuf_off = 0;
         fptr->rbuf_len = r;
-        if (r == 0)
+        if (r == 0) {
+	    io_set_eof(fptr);
             return -1; /* EOF */
+	}
     }
     return 0;
 }
@@ -1422,7 +1428,10 @@
     if (READ_DATA_PENDING(fptr) == 0) {
 	while (n > 0) {
 	    c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n);
-	    if (c == 0) break;
+	    if (c == 0) {
+		io_set_eof(fptr);
+		break;
+	    }
 	    if (c < 0) {
 		rb_sys_fail_path(fptr->pathv);
 	    }
@@ -1729,6 +1738,9 @@
                 goto again;
             rb_sys_fail_path(fptr->pathv);
         }
+	else if (n == 0) {
+	    io_set_eof(fptr);
+	}
     }
     rb_str_resize(str, n);
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]