fix mkstemp implementation for MSVC
@@ -19,8 +19,14 @@ typedef int mode_t;
static int
mkstemp(char *p)
{
- _mktemp(p);
- return 0;
+ int fd;
+ char* fname = _mktemp(p);
+ if (fname == NULL)
+ return -1;
+ fd = open(fname, O_RDWR | O_CREAT | O_EXCL, _S_IREAD | _S_IWRITE);
+ if (fd >= 0)
+ return fd;
+ return -1;
}
#endif
@@ -75,6 +81,9 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
mrb_raise(mrb, E_RUNTIME_ERROR, "can't create temporary file");
return mrb_nil_value();
}
+ close(fd0);
+ close(fd1);
+
#if !defined(_WIN32) && !defined(_WIN64)
fd2 = mkstemp(symlinkname);
fd3 = mkstemp(socketname);
