- /*
- * We MUST have write permission or
- * lockf/fcntl() won't work
- */
- if ((access & 03) == O_RDONLY) {
- access &= ~O_RDONLY;
- access |= O_RDWR;
- }
-# endif /* LOCKF_LOCKING || FCNTL_LOCKING */
+#ifdef HAVE_FLOCK
+ case FLOCK_LOCKING:
+ return lkopen_flock(file, access, mode);
+#endif /* HAVE_FLOCK */
+
+#ifdef HAVE_LOCKF
+ case LOCKF_LOCKING:
+ return lkopen_lockf(file, access, mode);
+#endif /* HAVE_FLOCK */
+
+ default:
+ adios(NULL, "Internal locking error: unsupported lock type used!");
+ }
+
+ return -1;
+}
+
+
+/*
+ * Routine to clean up the dot locking file
+ */
+
+static void
+lkclose_dot (int fd, const char *file)
+{
+ struct lockinfo lkinfo;
+
+ lockname (file, &lkinfo, 0); /* get name of lock file */
+#if !defined(HAVE_LIBLOCKFILE)
+ unlink (lkinfo.curlock); /* remove lock file */
+#else
+ lockfile_remove(lkinfo.curlock);
+#endif /* HAVE_LIBLOCKFILE */
+ timerOFF (fd); /* turn off lock timer */
+}
+
+
+/*
+ * Open and lock a file, using fcntl locking
+ */
+
+static int
+lkopen_fcntl(const char *file, int access, mode_t mode)
+{
+ int fd, i, saved_errno;
+ struct flock flk;