summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-18 01:11:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-18 01:11:01 +0000
commit61566f4b7cb6668d6c52bd472d8c146abe2a522e (patch)
tree4ae7693e5b15ba0183969f847fd523ef4027ce0b
parent10e6c73f3c0396e641567a09bf5cc326f57244be (diff)
* io.c, rubyio.h (rb_io_modenum_flags): exported.
* ext/stringio/stringio.c (strio_initialize): allow Fixnum as mode as well as IO.new does. [ruby-dev:24896] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--ext/stringio/stringio.c22
-rw-r--r--io.c2
-rw-r--r--rubyio.h1
4 files changed, 22 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 562a643d97..f926139f62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Nov 18 10:10:14 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c, rubyio.h (rb_io_modenum_flags): exported.
+
+ * ext/stringio/stringio.c (strio_initialize): allow Fixnum as mode as
+ well as IO.new does. [ruby-dev:24896]
+
Wed Nov 17 23:42:40 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
* test/ruby/test_settracefunc.rb: added. [ruby-dev:24884]
@@ -11,7 +18,7 @@ Wed Nov 17 04:33:01 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* pack.c: all features are backport from 1.9. [ruby-dev:24826]
- * bignum.c (rb_big2ulong_pack): new function to pack Bignums.
+ * bignum.c (rb_big2ulong_pack): new function to pack Bignums.
Tue Nov 16 23:45:07 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index a6879c052f..916b64e0b6 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -201,7 +201,7 @@ strio_initialize(argc, argv, self)
{
struct StringIO *ptr = check_strio(self);
VALUE string, mode;
- const char* m;
+ int trunc = Qfalse;
if (!ptr) {
DATA_PTR(self) = ptr = strio_alloc();
@@ -209,21 +209,23 @@ strio_initialize(argc, argv, self)
rb_call_super(0, 0);
switch (rb_scan_args(argc, argv, "02", &string, &mode)) {
case 2:
- StringValue(mode);
+ if (FIXNUM_P(mode)) {
+ int flags = FIX2INT(mode);
+ ptr->flags = rb_io_modenum_flags(flags);
+ trunc = flags & O_TRUNC;
+ }
+ else {
+ const char *m = StringValueCStr(mode);
+ ptr->flags = rb_io_mode_flags(m);
+ trunc = *m == 'w';
+ }
StringValue(string);
- if (!(m = RSTRING(mode)->ptr)) m = "";
- ptr->flags = rb_io_mode_flags(m);
if ((ptr->flags & FMODE_WRITABLE) && OBJ_FROZEN(string)) {
errno = EACCES;
rb_sys_fail(0);
}
- switch (*m) {
- case 'a':
- ptr->flags |= FMODE_APPEND;
- break;
- case 'w':
+ if (trunc) {
rb_str_resize(string, 0);
- break;
}
break;
case 1:
diff --git a/io.c b/io.c
index 289242d9b1..29077a6768 100644
--- a/io.c
+++ b/io.c
@@ -2245,7 +2245,7 @@ rb_io_mode_flags(mode)
return flags;
}
-static int
+int
rb_io_modenum_flags(mode)
int mode;
{
diff --git a/rubyio.h b/rubyio.h
index 44f679494e..3fe3282190 100644
--- a/rubyio.h
+++ b/rubyio.h
@@ -63,6 +63,7 @@ int rb_getc _((FILE*));
long rb_io_fread _((char *, long, FILE *));
long rb_io_fwrite _((const char *, long, FILE *));
int rb_io_mode_flags _((const char*));
+int rb_io_modenum_flags _((int));
void rb_io_check_writable _((OpenFile*));
void rb_io_check_readable _((OpenFile*));
void rb_io_fptr_finalize _((OpenFile*));