+struct zebra_lock_info {
+ int fd;
+ int excl_flag;
+};
+
+ZebraLockHandle zebra_lock_create (const char *name, int excl_flag)
+{
+ ZebraLockHandle h = xmalloc (sizeof(*h));
+ h->excl_flag = excl_flag;
+ h->fd = -1;
+#ifdef WINDOWS
+ if (!h->excl_flag)
+ h->fd = open (name, O_BINARY|O_RDONLY);
+ if (h->fd == -1)
+ h->fd = open (name, ((h->excl_flag > 1) ? O_EXCL : 0)|
+ (O_BINARY|O_CREAT|O_RDWR), 0666);
+#else
+ h->fd= open (name, ((h->excl_flag > 1) ? O_EXCL : 0)|
+ (O_BINARY|O_CREAT|O_RDWR|O_SYNC), 0666);
+#endif
+ if (h->fd == -1)
+ {
+ if (h->excl_flag <= 1)
+ logf (LOG_WARN|LOG_ERRNO, "open %s", name);
+ xfree (h);
+ return NULL;
+ }
+ return h;
+}
+
+void zebra_lock_destroy (ZebraLockHandle h)
+{
+ if (!h)
+ return;
+ if (h->fd != -1)
+ close (h->fd);
+ xfree (h);
+}