git » libfilo » commit 8aae4ca

Make length match fcntl() semantics.

author Alberto Bertogli
2005-04-27 20:51:07 UTC
committer Alberto Bertogli
2005-04-27 20:51:07 UTC
parent e8ce5f590625365e538b784db029352a83a0b570

Make length match fcntl() semantics.

libfilo.c +16 -4

diff --git a/libfilo.c b/libfilo.c
index be41ae3..645a8df 100644
--- a/libfilo.c
+++ b/libfilo.c
@@ -293,7 +293,10 @@ static int region_free(filock_t *fl, off_t start, off_t end) {
 int filo_trylock(filock_t *fl, off_t start, off_t len, int mode)
 {
 	int rv = 0;
-	int end = start + len;
+	off_t end = start + len - 1;
+
+	if (len <= 0)
+		return 0;
 
 	fl_lock(fl);
 
@@ -407,7 +410,10 @@ static void wake_up(filock_t *fl, off_t start, off_t end)
 /* Get a lock, blocking until available */
 int filo_lock(filock_t *fl, off_t start, off_t len, int mode)
 {
-	off_t end = start + len;
+	off_t end = start + len - 1;
+
+	if (len <= 0)
+		return 0;
 
 	fl_lock(fl);
 
@@ -437,7 +443,10 @@ int filo_lock(filock_t *fl, off_t start, off_t len, int mode)
 int filo_unlock(filock_t *fl, off_t start, off_t len)
 {
 	struct locked_range *lr, *next;
-	off_t end = start + len;
+	off_t end = start + len - 1;
+
+	if (len <= 0)
+		return 0;
 
 	fl_lock(fl);
 
@@ -473,7 +482,10 @@ int filo_unlock(filock_t *fl, off_t start, off_t len)
 int filo_plockf(filock_t *fl, int cmd, off_t start, off_t len)
 {
 	int rv, mode = 0;
-	off_t end = start + len;
+	off_t end = start + len - 1;
+
+	if (len <= 0)
+		return 0;
 
 	if (cmd & _FL_READ)
 		mode = FL_RD_MODE;