From e7e5db51de46cf6710e7019ac4931614ccdd448f Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 14 Dec 2017 00:43:38 +0900 Subject: fix mkstemp implementation for MSVC --- mrbgems/mruby-io/test/mruby_io_test.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'mrbgems/mruby-io/test/mruby_io_test.c') diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c index 7e25dddc2..c0bbb91ac 100644 --- a/mrbgems/mruby-io/test/mruby_io_test.c +++ b/mrbgems/mruby-io/test/mruby_io_test.c @@ -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); -- cgit v1.2.3