summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-io/src
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <[email protected]>2017-12-12 23:21:41 +0900
committerYasuhiro Matsumoto <[email protected]>2017-12-12 23:21:41 +0900
commitf1ea7a31c091d3caa74ed0fe9f411ed17db4680f (patch)
tree4e94cbe8b62911fec328ada7bdfd9d9dce721afd /mrbgems/mruby-io/src
parentdf2c3771f806e12ae62a2cf9d506580b348335b1 (diff)
downloadmruby-f1ea7a31c091d3caa74ed0fe9f411ed17db4680f.tar.gz
mruby-f1ea7a31c091d3caa74ed0fe9f411ed17db4680f.zip
implement flock on Windows
Diffstat (limited to 'mrbgems/mruby-io/src')
-rw-r--r--mrbgems/mruby-io/src/file.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c
index 19603c856..e38e6a2b6 100644
--- a/mrbgems/mruby-io/src/file.c
+++ b/mrbgems/mruby-io/src/file.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32) || defined(_WIN64)
+ #include <windows.h>
#define NULL_FILE "NUL"
#define UNLINK _unlink
#define GETCWD _getcwd
@@ -70,6 +71,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)
@@ -283,7 +296,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;