git » libjio » commit 048f1ae

In jclose(), before closing the descriptors check if they're opened to avoid unnecesary close() calls.

author Alberto Bertogli
2004-08-30 04:30:41 UTC
committer Alberto Bertogli
2007-07-15 13:17:52 UTC
parent 8bec7feb396189a48ff624b56e64a8b43fba0aff

In jclose(), before closing the descriptors check if they're opened to avoid unnecesary close() calls.

In jclose(), before closing the descriptors check if they're opened to avoid
unnecesary close() calls.

They don't harm, but it looks cleaner if we don't do them (and makes straces
easier to follow).

trans.c +6 -3

diff --git a/trans.c b/trans.c
index 03604eb..438a53c 100644
--- a/trans.c
+++ b/trans.c
@@ -598,6 +598,9 @@ int jsync(struct jfs *fs)
 	int rv;
 	struct jlinger *linger, *ltmp;
 
+	if (fs->fd < 0)
+		return -1;
+
 	rv = fsync(fs->fd);
 	if (rv != 0)
 		return rv;
@@ -628,11 +631,11 @@ int jclose(struct jfs *fs)
 
 	if (jsync(fs))
 		ret = -1;
-	if (close(fs->fd))
+	if (fs->fd < 0 || close(fs->fd))
 		ret = -1;
-	if (close(fs->jfd))
+	if (fs->jfd < 0 || close(fs->jfd))
 		ret = -1;
-	if (close(fs->jdirfd))
+	if (fs->jdirfd < 0 || close(fs->jdirfd))
 		ret = -1;
 	if (fs->name)
 		/* allocated by strdup() in jopen() */