[PATCH 01/25] dbench: simplify open_loadfile() as check_loadfile_ok()

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



open_loadfile() just checks to see if the file.gz exists
and is present. Note that if the file is not in the gzip format,
gzopen and gzread will not produce an error but just read it
without doing any uncompressing. So just rename it to
check_loadfile_ok().

While at it fix the incorrect use of gzFile as a pointer.
Using it as a pointer works just because the file descriptor
can cast to the pointer, but this generates compilation warnings.
Fix that as well.

And lastly, just use gzclose(f) for correctness;

Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>
---
 dbench.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/dbench.c b/dbench.c
index 178a175..c8f2fee 100644
--- a/dbench.c
+++ b/dbench.c
@@ -25,6 +25,7 @@
 #include "dbench.h"
 #include "popt.h"
 #include <sys/sem.h>
+#include <stdbool.h>
 #include <zlib.h>
 
 struct options options = {
@@ -60,18 +61,25 @@ static double throughput;
 struct nb_operations *nb_ops;
 int global_random;
 
-static gzFile *open_loadfile(void)
+/*
+ * Note that if the file is not in the gzip format, gzopen and gzread will not
+ * produce an error but just read it without doing any uncompressing.
+ */
+static bool check_loadfile_ok(void)
 {
-	gzFile		*f;
+	gzFile f;
 
-	if ((f = gzopen(options.loadfile, "rt")) != NULL)
-		return f;
+	f = gzopen(options.loadfile, "rt");
+	if (f) {
+		gzclose(f);
+		return true;
+	}
 
 	fprintf(stderr,
 		"dbench: error opening '%s': %s\n", options.loadfile,
 		strerror(errno));
 
-	return NULL;
+	return false;
 }
 
 
@@ -253,14 +261,11 @@ static void create_procs(int nprocs, void (*fn)(struct child_struct *, const cha
 	int i, status;
 	int synccount;
 	struct timeval tv;
-	gzFile *load;
 	struct sembuf sbuf;
 	double t;
 
-	load = open_loadfile();
-	if (load == NULL) {
+	if (!check_loadfile_ok())
 		exit(1);
-	}
 
 	if (nprocs < 1) {
 		fprintf(stderr,
-- 
2.34.1




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux