+#ifdef HAVE_FLOCK
+/*
+ * Open and lock a file, using flock locking
+ */
+
+static int
+lkopen_flock(const char *file, int access, mode_t mode)
+{
+ int fd, i, saved_errno, locktype;
+
+ /*
+ * The assumption here is that if you open the file for writing, you
+ * need an exclusive lock.
+ */
+
+ locktype = (((access & O_ACCMODE) == O_RDONLY) ? LOCK_SH : LOCK_EX) |
+ LOCK_NB;
+
+ for (i = 0; i < LOCK_RETRIES; i++) {
+ if ((fd = open(file, access, mode)) == -1)