X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Flockutil.c;h=431cb9c748b5b11ab4b6a15d7a6d9505c5febb0f;hp=366f93627d9a7bcfc8a6cabd6890aa57e4a6f5d8;hb=3c5f6226f97612c0d6ac40591f600587c5ffa858;hpb=c5ef994b26d692fbfecc3ac97f69e4bf7bd0fcea diff --git a/index/lockutil.c b/index/lockutil.c index 366f936..431cb9c 100644 --- a/index/lockutil.c +++ b/index/lockutil.c @@ -1,10 +1,16 @@ /* - * Copyright (C) 1994-1997, Index Data I/S + * Copyright (C) 1994-1999, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: lockutil.c,v $ - * Revision 1.9 1997-09-25 14:54:43 adam + * Revision 1.11 1999-02-02 14:50:59 adam + * Updated WIN32 code specific sections. Changed header. + * + * Revision 1.10 1997/09/29 09:08:36 adam + * Revised locking system to be thread safe for the server. + * + * Revision 1.9 1997/09/25 14:54:43 adam * WIN32 files lock support. * * Revision 1.8 1997/09/17 12:19:15 adam @@ -43,7 +49,7 @@ #include #include #include -#ifdef WINDOWS +#ifdef WIN32 #include #include #else @@ -52,8 +58,6 @@ #include "index.h" -static char *lockDir = NULL; - struct zebra_lock_info { int fd; int excl_flag; @@ -64,7 +68,7 @@ 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 +#ifdef WIN32 if (!h->excl_flag) h->fd = open (name, O_BINARY|O_RDONLY); if (h->fd == -1) @@ -93,20 +97,16 @@ void zebra_lock_destroy (ZebraLockHandle h) xfree (h); } -void zebraLockPrefix (Res res, char *pathPrefix) +void zebra_lock_prefix (Res res, char *path) { - if (!lockDir) - lockDir = res_get_def (res, "lockDir", ""); - assert (lockDir); - - strcpy (pathPrefix, lockDir); - if (*pathPrefix && pathPrefix[strlen(pathPrefix)-1] != '/') - strcat (pathPrefix, "/"); -} + char *lock_dir = res_get_def (res, "lockDir", ""); -#ifdef WINDOWS + strcpy (path, lock_dir); + if (*path && path[strlen(path)-1] != '/') + strcat (path, "/"); +} -#else +#ifndef WIN32 static int unixLock (int fd, int type, int cmd) { struct flock area; @@ -119,7 +119,7 @@ static int unixLock (int fd, int type, int cmd) int zebra_lock (ZebraLockHandle h) { -#ifdef WINDOWS +#ifdef WIN32 return _locking (h->fd, _LK_LOCK, 1); #else return unixLock (h->fd, h->excl_flag ? F_WRLCK : F_RDLCK, F_SETLKW); @@ -128,7 +128,7 @@ int zebra_lock (ZebraLockHandle h) int zebra_lock_nb (ZebraLockHandle h) { -#ifdef WINDOWS +#ifdef WIN32 return _locking (h->fd, _LK_NBLCK, 1); #else return unixLock (h->fd, h->excl_flag ? F_WRLCK : F_RDLCK, F_SETLK); @@ -137,7 +137,7 @@ int zebra_lock_nb (ZebraLockHandle h) int zebra_unlock (ZebraLockHandle h) { -#ifdef WINDOWS +#ifdef WIN32 return _locking (h->fd, _LK_UNLCK, 1); #else return unixLock (h->fd, F_UNLCK, F_SETLKW);