2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-12-11 11:43:29 adam
8 * Locking based on fcntl instead of flock.
9 * Setting commitEnable removed. Command line option -n can be used to
10 * prevent commit if commit setting is defined in the configuration file.
12 * Revision 1.1 1995/12/07 17:38:47 adam
13 * Work locking mechanisms for concurrent updates/commit.
21 #include <sys/types.h>
27 static char *lockDir = NULL;
29 void zebraLockPrefix (char *pathPrefix)
32 lockDir = res_get_def (common_resource, "lockDir", "");
35 strcpy (pathPrefix, lockDir);
36 if (*pathPrefix && pathPrefix[strlen(pathPrefix)-1] != '/')
37 strcat (pathPrefix, "/");
40 static int intLock (int fd, int type, int cmd)
44 area.l_whence = SEEK_SET;
45 area.l_len = area.l_start = 0L;
46 return fcntl (fd, cmd, &area);
49 int zebraLock (int fd, int wr)
51 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLKW);
54 int zebraLockNB (int fd, int wr)
56 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLK);
59 int zebraUnlock (int fd)
61 return intLock (fd, F_UNLCK, F_SETLKW);