From ce4e9dff9b79af947bb19bbe96c4b842bffd4611 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 26 Oct 2009 03:06:29 +0000 Subject: [PATCH] * io.c (io_fwrite): adjust stdio file position after direct write on BSDish platforms. [ruby-core:26300] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@25485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ io.c | 11 +++++++++++ test/ruby/test_io.rb | 15 +++++++++++++++ version.h | 6 +++--- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3221562ea5..f1512309c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Oct 26 12:06:27 2009 Nobuyoshi Nakada + + * io.c (io_fwrite): adjust stdio file position after direct write on + BSDish platforms. [ruby-core:26300] + Sun Oct 25 20:04:35 2009 Akinori MUSHA * object.c (rb_class_initialize): The inherited hook should be run diff --git a/io.c b/io.c index d45d448e1b..d136c76cf6 100644 --- a/io.c +++ b/io.c @@ -37,6 +37,14 @@ # define USE_SETVBUF #endif +#ifndef BSD_STDIO +# if defined(__MACH__) || defined(__DARWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) +# define BSD_STDIO 1 +# else +# define BSD_STDIO 0 +# endif +#endif + #ifdef __QNXNTO__ #include "unix.h" #endif @@ -481,6 +489,9 @@ io_fwrite(str, fptr) TRAP_BEG; r = write(fileno(f), RSTRING(str)->ptr+offset, l); TRAP_END; +#if BSD_STDIO + fseeko(f, lseek(fileno(f), (off_t)0, SEEK_CUR), SEEK_SET); +#endif if (r == n) return len; if (0 <= r) { offset += r; diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 7137b5f772..feab552582 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -34,4 +34,19 @@ class TestIO < Test::Unit::TestCase t.close assert_raise(IOError) {t.binmode} end + + def test_pos + t = make_tempfile + + open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f| + f.write "Hello" + assert_equal(5, f.pos) + end + open(t.path, IO::RDWR|IO::CREAT|IO::TRUNC, 0600) do |f| + f.sync = true + f.read + f.write "Hello" + assert_equal(5, f.pos) + end + end end diff --git a/version.h b/version.h index 4756e4b0ad..36f3f7b5a0 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.8.8" -#define RUBY_RELEASE_DATE "2009-10-25" +#define RUBY_RELEASE_DATE "2009-10-26" #define RUBY_VERSION_CODE 188 -#define RUBY_RELEASE_CODE 20091025 +#define RUBY_RELEASE_CODE 20091026 #define RUBY_PATCHLEVEL -1 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 8 #define RUBY_RELEASE_YEAR 2009 #define RUBY_RELEASE_MONTH 10 -#define RUBY_RELEASE_DAY 25 +#define RUBY_RELEASE_DAY 26 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[];