From 40742d7d31a8c51f416b52a2a203c312bca8795e Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sun, 27 Apr 2025 21:45:25 -0400 Subject: move free_arr() into util.c --- Makefile | 2 +- compressor.c | 9 --------- util.c | 11 +++++++++++ util.h | 2 ++ 4 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 util.c diff --git a/Makefile b/Makefile index d30a8cd..6ba8c06 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CFLAGS = -std=c99 -I ./ -Wall -Wextra -pedantic -Wno-deprecated-declarations -D_XOPEN_SOURCE=700L LDFLAGS = -lSDL2 -lSDL2_ttf -lm -SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c compressor.c eprintf.c cwalk.c toml.c +SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c compressor.c eprintf.c cwalk.c toml.c util.c OBJ = ${SRC:.c=.o} HDR = microui.h renderer.h widget.h ui.h unit.h engine.h eprintf.h util.h cwalk.h toml.h diff --git a/compressor.c b/compressor.c index bca4210..358849b 100644 --- a/compressor.c +++ b/compressor.c @@ -26,7 +26,6 @@ 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); -static void free_arr(void **arr, int n); /* Load descriptions of all of the compressor maps. @@ -269,11 +268,3 @@ toml_filter(const struct dirent *de) { } return strcmp(".toml", extension) == 0; /* extension is ".toml". */ } - -static void -free_arr(void **arr, int n) { - while (n-- > 0) { - free(arr[n]); - } - free(arr); -} diff --git a/util.c b/util.c new file mode 100644 index 0000000..436a304 --- /dev/null +++ b/util.c @@ -0,0 +1,11 @@ +#include + +#include "util.h" + +void +free_arr(void **arr, int n) { + while (n-- > 0) { + free(arr[n]); + } + free(arr); +} diff --git a/util.h b/util.h index 0a48edd..8c7a28d 100644 --- a/util.h +++ b/util.h @@ -1,3 +1,5 @@ #define nelem(arr) (sizeof(arr)/sizeof(arr[0])) #define min(a, b) ((a < b) ? a : b) #define max(a, b) ((a > b) ? a : b) + +void free_arr(void **arr, int n); -- cgit v1.2.3