From a89e21037e48b2fe96c4ef335a51b31f07a91ff8 Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Mon, 7 Aug 2006 17:15:04 +0000 Subject: [PATCH] (ef_open) [_WIN32]: Provide file locking for WIN32. --- src/lib/common/file.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/common/file.c b/src/lib/common/file.c index 84e17c8e8..a75666324 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -38,6 +38,7 @@ #include #if defined(_WIN32) && !defined(__GNUC__) #include +#include #endif #include #include @@ -66,7 +67,9 @@ int ef_open(int type, int how) { struct empfile *ep; +#if !defined(_WIN32) struct flock lock; +#endif int oflags, fd, fsiz, size; if (ef_check(type) < 0) @@ -85,7 +88,13 @@ ef_open(int type, int how) oflags |= O_CREAT | O_TRUNC; #if defined(_WIN32) oflags |= O_BINARY; -#endif + if ((fd = sopen(ep->file, oflags, + how & EFF_RDONLY ? SH_DENYWR : SH_DENYRW, + 0660)) < 0) { + logerror("Can't open %s (%s)", ep->file, strerror(errno)); + return 0; + } +#else if ((fd = open(ep->file, oflags, 0660)) < 0) { logerror("Can't open %s (%s)", ep->file, strerror(errno)); return 0; @@ -98,6 +107,7 @@ ef_open(int type, int how) logerror("Can't lock %s (%s)", ep->file, strerror(errno)); return 0; } +#endif /* get file size */ fsiz = fsize(fd); -- 2.43.0