2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1997-09-09 13:38:08 adam
8 * Partial port to WIN95/NT.
10 * Revision 1.6 1996/10/29 14:08:14 adam
11 * Uses resource lockDir instead of lockPath.
13 * Revision 1.5 1996/03/26 16:01:13 adam
14 * New setting lockPath: directory of various lock files.
16 * Revision 1.4 1995/12/13 08:46:10 adam
17 * Locking uses F_WRLCK and F_RDLCK again!
19 * Revision 1.3 1995/12/12 16:00:57 adam
20 * System call sync(2) used after update/commit.
21 * Locking (based on fcntl) uses F_EXLCK and F_SHLCK instead of F_WRLCK
24 * Revision 1.2 1995/12/11 11:43:29 adam
25 * Locking based on fcntl instead of flock.
26 * Setting commitEnable removed. Command line option -n can be used to
27 * prevent commit if commit setting is defined in the configuration file.
29 * Revision 1.1 1995/12/07 17:38:47 adam
30 * Work locking mechanisms for concurrent updates/commit.
38 #include <sys/types.h>
47 static char *lockDir = NULL;
49 void zebraLockPrefix (char *pathPrefix)
52 lockDir = res_get_def (common_resource, "lockDir", "");
55 strcpy (pathPrefix, lockDir);
56 if (*pathPrefix && pathPrefix[strlen(pathPrefix)-1] != '/')
57 strcat (pathPrefix, "/");
60 static int intLock (int fd, int type, int cmd)
64 area.l_whence = SEEK_SET;
65 area.l_len = area.l_start = 0L;
66 return fcntl (fd, cmd, &area);
69 int zebraLock (int fd, int wr)
72 return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLKW);
74 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLKW);
78 int zebraLockNB (int fd, int wr)
81 return intLock (fd, wr ? F_EXLCK : F_SHLCK, F_SETLK);
83 return intLock (fd, wr ? F_WRLCK : F_RDLCK, F_SETLK);
87 int zebraUnlock (int fd)
89 return intLock (fd, F_UNLCK, F_SETLKW);