/*
- * $Id: ad_lock.c,v 1.18 2009-11-12 06:28:40 didg Exp $
+ * $Id: ad_lock.c,v 1.19 2010-02-26 12:57:50 didg Exp $
*
* Copyright (c) 1998,1999 Adrian Sun (asun@zoology.washington.edu)
* All Rights Reserved. See COPYRIGHT for more information.
#define fcntl(a, b, c ) (0)
#endif
+/* ----------------------- */
+static int set_lock(int fd, int cmd, struct flock *lock)
+{
+ if (!fd) {
+ /* We assign fd = 0 for symlinks -> do nothing */
+ if (cmd == F_GETLK)
+ lock->l_type = F_UNLCK;
+ return 0;
+ }
+ return fcntl(fd, cmd, lock);
+}
+
/* ----------------------- */
static int XLATE_FCNTL_LOCK(int type)
{
free(lock->refcount);
if (!ad->adf_excl) {
lock->lock.l_type = F_UNLCK;
- fcntl(ad->adf_fd, F_SETLK, &lock->lock); /* unlock */
+ set_lock(ad->adf_fd, F_SETLK, &lock->lock); /* unlock */
}
}
if (!ad->adf_excl) for (i = 0; i < ad->adf_lockcount; i++) {
if (OVERLAP(off, len, lock[i].lock.l_start, lock[i].lock.l_len))
- fcntl(fd, F_SETLK, &lock[i].lock);
+ set_lock(fd, F_SETLK, &lock[i].lock);
}
}
}
/* attempt to lock the file. */
- if (!adf->adf_excl && fcntl(adf->adf_fd, F_SETLK, &lock) < 0)
+ if (!adf->adf_excl && set_lock(adf->adf_fd, F_SETLK, &lock) < 0)
return -1;
/* we upgraded this lock. */
fcntl_lock_err:
lock.l_type = F_UNLCK;
- if (!adf->adf_excl) fcntl(adf->adf_fd, F_SETLK, &lock);
+ if (!adf->adf_excl) set_lock(adf->adf_fd, F_SETLK, &lock);
return -1;
}
*/
lock.l_type = (adf->adf_flags & O_RDWR) ?F_WRLCK : F_RDLCK;
- if (fcntl(adf->adf_fd, F_GETLK, &lock) < 0) {
+ if (set_lock(adf->adf_fd, F_GETLK, &lock) < 0) {
/* is that kind of error possible ?*/
return (errno == EACCES || errno == EAGAIN)?1:-1;
}
* we just want to upgrade all the locks and then downgrade them
* here. */
if (!adf->adf_excl) {
- err = fcntl(adf->adf_fd, F_SETLK, &lock);
+ err = set_lock(adf->adf_fd, F_SETLK, &lock);
}
else {
err = 0;
lock.l_start = ad_getentryoff(ad, eid);
}
- err = fcntl(adf->adf_fd, F_SETLK, &lock);
+ err = set_lock(adf->adf_fd, F_SETLK, &lock);
if (!err)
adf->adf_excl = 1;
return err;