]> git.pond.sub.org Git - empserver/commitdiff
(ef_open) [_WIN32]: Provide file locking for WIN32.
authorRon Koenderink <rkoenderink@yahoo.ca>
Mon, 7 Aug 2006 17:15:04 +0000 (17:15 +0000)
committerRon Koenderink <rkoenderink@yahoo.ca>
Mon, 7 Aug 2006 17:15:04 +0000 (17:15 +0000)
src/lib/common/file.c

index 84e17c8e891e0053dfc069bbecbeeaed5805c6c8..a75666324c2acf00d5e4c5c96fe0bb035b5d6ccf 100644 (file)
@@ -38,6 +38,7 @@
 #include <errno.h>
 #if defined(_WIN32) && !defined(__GNUC__)
 #include <io.h>
 #include <errno.h>
 #if defined(_WIN32) && !defined(__GNUC__)
 #include <io.h>
+#include <share.h>
 #endif
 #include <fcntl.h>
 #include <signal.h>
 #endif
 #include <fcntl.h>
 #include <signal.h>
@@ -66,7 +67,9 @@ int
 ef_open(int type, int how)
 {
     struct empfile *ep;
 ef_open(int type, int how)
 {
     struct empfile *ep;
+#if !defined(_WIN32)
     struct flock lock;
     struct flock lock;
+#endif
     int oflags, fd, fsiz, size;
 
     if (ef_check(type) < 0)
     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;
        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;
     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;
     }
        logerror("Can't lock %s (%s)", ep->file, strerror(errno));
        return 0;
     }
+#endif
 
     /* get file size */
     fsiz = fsize(fd);
 
     /* get file size */
     fsiz = fsize(fd);