From 160692f4b9f80c6eba7d18d3221fc1c3e3c3139e Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Wed, 1 May 2024 13:31:24 -0400 Subject: Added error checks to file opening, and generalized key types --- benchmarks/include/file_util.h | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'benchmarks/include') diff --git a/benchmarks/include/file_util.h b/benchmarks/include/file_util.h index 8dc1b5f..b5b3417 100644 --- a/benchmarks/include/file_util.h +++ b/benchmarks/include/file_util.h @@ -15,6 +15,12 @@ static std::vector read_lookup_queries(std::string fname, double selectivity std::vector queries; FILE *qf = fopen(fname.c_str(), "r"); + + if (!qf) { + fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); + exit(EXIT_FAILURE); + } + size_t start, stop; double sel; while (fscanf(qf, "%zu%zu%lf\n", &start, &stop, &sel) != EOF) { @@ -34,6 +40,12 @@ static std::vector read_range_queries(std::string &fname, double selectivity std::vector queries; FILE *qf = fopen(fname.c_str(), "r"); + + if (!qf) { + fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); + exit(EXIT_FAILURE); + } + size_t start, stop; double sel; while (fscanf(qf, "%zu%zu%lf\n", &start, &stop, &sel) != EOF) { @@ -58,6 +70,11 @@ static std::vector read_knn_queries(std::string fname, size_t k) { char *line = NULL; size_t len = 0; + if (!qf) { + fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); + exit(EXIT_FAILURE); + } + while (getline(&line, &len, qf) > 0) { char *token; QP query; @@ -83,10 +100,15 @@ static std::vector read_sosd_file(std::string &fname, size_t n) { std::fstream file; file.open(fname, std::ios::in | std::ios::binary); + if (!file.is_open()) { + fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); + exit(EXIT_FAILURE); + } + std::vector records(n); for (size_t i=0; i> read_sosd_file_pair(std::string &fname, size std::fstream file; file.open(fname, std::ios::in | std::ios::binary); + if (!file.is_open()) { + fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); + exit(EXIT_FAILURE); + } + std::vector> records(n); for (size_t i=0; i read_vector_file(std::string &fname, size_t n) { std::fstream file; file.open(fname, std::ios::in); + if (!file.is_open()) { + fprintf(stderr, "ERROR: Failed to open file %s\n", fname.c_str()); + exit(EXIT_FAILURE); + } + std::vector records; records.reserve(n); -- cgit v1.2.3