aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-04-28 11:34:12 -0400
committerSam Anthony <sam@samanthony.xyz>2025-04-28 11:34:12 -0400
commit27f637904876fac0f8e69b6829591ea0a7689bb2 (patch)
tree13b44eb7ddb36b78c9cd68776b750880dbba7cfa
parent67787e9e2a6a580400cea0f925b7a5f3d9222ef7 (diff)
downloadvolute-27f637904876fac0f8e69b6829591ea0a7689bb2.zip
move lsearch() into util.c
-rw-r--r--compressor.c18
-rw-r--r--util.c17
-rw-r--r--util.h1
3 files changed, 18 insertions, 18 deletions
diff --git a/compressor.c b/compressor.c
index 358849b..b317c25 100644
--- a/compressor.c
+++ b/compressor.c
@@ -23,7 +23,6 @@ static int load_point(const toml_table_t *tbl, const char *key, const char *flow
static int parse_flow(double val, const char *unit, Flow *flow);
static int parse_mass_flow(double val, const char *unit, Flow *flow);
static int parse_volume_flow(double val, const char *unit, Flow *flow);
-static int lsearch(const void *key, const void *base, size_t n, size_t size, int (*cmp)(const void *keyval, const void *datum));
static int toml_filter(const struct dirent *de);
static int cmp_flow_unit(const void *key, const void *datum);
@@ -236,23 +235,6 @@ parse_volume_flow(double val, const char *unit, Flow *flow) {
return 1;
}
-/* lsearch linearly searches base[0]...base[n-1] for an item that matches *key.
- * The function cmp must return zero if its first argument (the search key)
- * equals its second (a table entry), non-zero if not equal.
- * Returns the index of the first occurrence of key in base, or -1 if not present. */
-static int
-lsearch(const void *key, const void *base, size_t n, size_t size, int (*cmp)(const void *keyval, const void *datum)) {
- size_t i;
-
- for (i = 0; i < n; i++) {
- if (cmp(key, base) == 0) {
- return i;
- }
- base = (char *) base + size;
- }
- return -1;
-}
-
static int
cmp_flow_unit(const void *key, const void *datum) {
return strcmp((char *) key, *(char **) datum);
diff --git a/util.c b/util.c
index 436a304..a820585 100644
--- a/util.c
+++ b/util.c
@@ -9,3 +9,20 @@ free_arr(void **arr, int n) {
}
free(arr);
}
+
+/* lsearch linearly searches base[0]...base[n-1] for an item that matches *key.
+ * The function cmp must return zero if its first argument (the search key)
+ * equals its second (a table entry), non-zero if not equal.
+ * Returns the index of the first occurrence of key in base, or -1 if not present. */
+int
+lsearch(const void *key, const void *base, size_t n, size_t size, int (*cmp)(const void *keyval, const void *datum)) {
+ size_t i;
+
+ for (i = 0; i < n; i++) {
+ if (cmp(key, base) == 0) {
+ return i;
+ }
+ base = (char *) base + size;
+ }
+ return -1;
+}
diff --git a/util.h b/util.h
index 8c7a28d..501d11e 100644
--- a/util.h
+++ b/util.h
@@ -3,3 +3,4 @@
#define max(a, b) ((a > b) ? a : b)
void free_arr(void **arr, int n);
+int lsearch(const void *key, const void *base, size_t n, size_t size, int (*cmp)(const void *keyval, const void *datum));