diff --git a/ChangeLog b/ChangeLog index b447a68298..2472558606 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Oct 18 11:29:32 2004 Nobuyoshi Nakada + + * io.c (rb_io_flags_mode, rb_io_mode_flags): distinguish whether file + not existing is created. [ruby-dev:24505] + Mon Oct 18 07:26:21 2004 Nobuyoshi Nakada * file.c (rb_file_truncate): discard read buffer before truncation. diff --git a/io.c b/io.c index 1f2a351624..e1acaca1a8 100644 --- a/io.c +++ b/io.c @@ -2304,6 +2304,9 @@ rb_io_flags_mode(flags) case FMODE_WRITABLE: return MODE_BINMODE("w", "wb"); case FMODE_READWRITE: + if (flags & FMODE_CREATE) { + return MODE_BINMODE("w+", "wb+"); + } return MODE_BINMODE("r+", "rb+"); } rb_raise(rb_eArgError, "illegal access mode %o", flags); @@ -2322,10 +2325,10 @@ rb_io_mode_flags(mode) flags |= FMODE_READABLE; break; case 'w': - flags |= FMODE_WRITABLE; + flags |= FMODE_WRITABLE | FMODE_CREATE; break; case 'a': - flags |= FMODE_WRITABLE | FMODE_APPEND; + flags |= FMODE_WRITABLE | FMODE_APPEND | FMODE_CREATE; break; default: error: diff --git a/rubyio.h b/rubyio.h index efafe0c6a8..0b77fa1794 100644 --- a/rubyio.h +++ b/rubyio.h @@ -31,6 +31,7 @@ typedef struct OpenFile { #define FMODE_WRITABLE 2 #define FMODE_READWRITE 3 #define FMODE_APPEND 64 +#define FMODE_CREATE 128 #define FMODE_BINMODE 4 #define FMODE_SYNC 8 #define FMODE_WBUF 16