summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io/src/file.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-12-13 07:56:24 +0900
committerGitHub <[email protected]>2017-12-13 07:56:24 +0900
commit5a5adafabf754163e9ce9022236a6e52b4e66a0b (patch)
tree0fabe7197d2861c5d8ce626d2d805b79cf805651 /mrbgems/mruby-io/src/file.c
parentc863e0dac85b2251a77e2a137d7bac0548e23932 (diff)
parentb07269584ce9a255655cff167ecf09d1dddf62f7 (diff)
downloadmruby-5a5adafabf754163e9ce9022236a6e52b4e66a0b.tar.gz
mruby-5a5adafabf754163e9ce9022236a6e52b4e66a0b.zip
Merge pull request #3886 from mattn/io-windows
implement popen/flock on Windows
Diffstat (limited to 'mrbgems/mruby-io/src/file.c')
-rw-r--r--mrbgems/mruby-io/src/file.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c
index 17fdeeed5..bcfd42408 100644
--- a/mrbgems/mruby-io/src/file.c
+++ b/mrbgems/mruby-io/src/file.c
@@ -24,6 +24,8 @@
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
+ #include <windows.h>
+ #include <io.h>
#define NULL_FILE "NUL"
#define UNLINK _unlink
#define GETCWD _getcwd
@@ -70,6 +72,18 @@
#define STAT(p, s) stat(p, s)
+#ifdef _WIN32
+static int
+flock(int fd, int operation) {
+ OVERLAPPED ov;
+ HANDLE h = (HANDLE)_get_osfhandle(fd);
+ DWORD flags;
+ flags = ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0)
+ | ((operation & LOCK_SH) ? LOCKFILE_EXCLUSIVE_LOCK : 0);
+ memset(&ov, 0, sizeof(ov));
+ return LockFileEx(h, flags, 0, 0xffffffff, 0xffffffff, &ov) ? 0 : -1;
+}
+#endif
mrb_value
mrb_file_s_umask(mrb_state *mrb, mrb_value klass)
@@ -284,7 +298,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass)
mrb_value
mrb_file_flock(mrb_state *mrb, mrb_value self)
{
-#if defined(_WIN32) || defined(_WIN64) || defined(sun)
+#if defined(sun)
mrb_raise(mrb, E_NOTIMP_ERROR, "flock is not supported on Illumos/Solaris/Windows");
#else
mrb_int operation;