Index: include/ruby/win32.h =================================================================== --- include/ruby/win32.h (リビジョン 50766) +++ include/ruby/win32.h (作業コピー) @@ -124,6 +124,8 @@ typedef unsigned int uintptr_t; #define WNOHANG -1 +#define O_DELETE 0x80000000 /* for rb_w32_open(), rb_w32_wopen() */ + typedef int clockid_t; #define CLOCK_REALTIME 0 #define CLOCK_MONOTONIC 1 Index: io.c =================================================================== --- io.c (リビジョン 50766) +++ io.c (作業コピー) @@ -175,6 +175,9 @@ static VALUE argf; static ID id_write, id_read, id_getc, id_flush, id_readpartial, id_set_encoding; static VALUE sym_mode, sym_perm, sym_extenc, sym_intenc, sym_encoding, sym_open_args; static VALUE sym_textmode, sym_binmode, sym_autoclose; +#ifdef O_DELETE +static VALUE sym_share_delete; +#endif static VALUE sym_SET, sym_CUR, sym_END; #ifdef SEEK_DATA static VALUE sym_DATA; @@ -5383,6 +5386,10 @@ rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm /* perm no use, just ignore */ } } +#ifdef O_DELETE + v = rb_hash_aref(opthash, sym_share_delete); + if (!NIL_P(v)) oflags |= O_DELETE; +#endif ecflags = (fmode & FMODE_READABLE) ? MODE_BTMODE(ECONV_DEFAULT_NEWLINE_DECORATOR, 0, ECONV_UNIVERSAL_NEWLINE_DECORATOR) : 0; @@ -12430,6 +12437,9 @@ Init_IO(void) sym_textmode = ID2SYM(rb_intern("textmode")); sym_binmode = ID2SYM(rb_intern("binmode")); sym_autoclose = ID2SYM(rb_intern("autoclose")); +#ifdef O_DELETE + sym_share_delete = ID2SYM(rb_intern("share_delete")); +#endif sym_normal = ID2SYM(rb_intern("normal")); sym_sequential = ID2SYM(rb_intern("sequential")); sym_random = ID2SYM(rb_intern("random")); Index: win32/win32.c =================================================================== --- win32/win32.c (リビジョン 50766) +++ win32/win32.c (作業コピー) @@ -5775,6 +5775,7 @@ rb_w32_open(const char *file, int oflag, ...) va_end(arg); if ((oflag & O_TEXT) || !(oflag & O_BINARY)) { + oflag &= ~O_DELETE; ret = _open(file, oflag, pmode); if (ret == -1 && errno == EACCES) check_if_dir(file); return ret; @@ -5797,7 +5798,10 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...) DWORD attr = FILE_ATTRIBUTE_NORMAL; SECURITY_ATTRIBUTES sec; HANDLE h; + int delete; + delete = oflag & O_DELETE; + oflag &= ~O_DELETE; if ((oflag & O_TEXT) || !(oflag & O_BINARY)) { va_list arg; int pmode; @@ -5919,8 +5923,7 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...) _set_osfhnd(fd, (intptr_t)INVALID_HANDLE_VALUE); _set_osflags(fd, 0); - h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec, - create, attr, NULL); + h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE | (delete ? FILE_SHARE_DELETE : 0), &sec, create, attr, NULL); if (h == INVALID_HANDLE_VALUE) { DWORD e = GetLastError(); if (e != ERROR_ACCESS_DENIED || !check_if_wdir(file))