aboutsummaryrefslogtreecommitdiff
path: root/str_vec.c
diff options
context:
space:
mode:
authortwells46 <173561638+twells46@users.noreply.github.com>2026-03-30 21:07:39 -0500
committertwells46 <173561638+twells46@users.noreply.github.com>2026-03-30 21:07:39 -0500
commitf874d6571a9c5763e5c4270c3389ef2502d2f5e3 (patch)
treedde651f3a2fb6ef4a70ee6da027497dbd734d7e0 /str_vec.c
ForkedHEADmain
Diffstat (limited to 'str_vec.c')
-rw-r--r--str_vec.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/str_vec.c b/str_vec.c
new file mode 100644
index 0000000..82b61a4
--- /dev/null
+++ b/str_vec.c
@@ -0,0 +1,35 @@
+#define _XOPEN_SOURCE 700
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "str_vec.h"
+
+void str_vec_init(struct str_vec *vec) {
+ vec->data = NULL;
+ vec->len = 0;
+}
+
+void str_vec_push(struct str_vec *vec, const char *new_str) {
+ ++vec->len;
+ vec->data = realloc(vec->data, vec->len * sizeof(char*));
+ if (!vec->data) {
+ perror("str_vec_push failed to allocate memory for str_vec");
+ exit(EXIT_FAILURE);
+ }
+ vec->data[vec->len - 1] = strdup(new_str);
+}
+
+void str_vec_free(struct str_vec *vec) {
+ if (vec == NULL) {
+ return;
+ }
+ for (size_t i = 0; i < vec->len; ++i) {
+ if (vec->data[i] != NULL) {
+ free(vec->data[i]);
+ }
+ }
+ free(vec->data);
+ vec->data = NULL;
+ vec->len = 0;
+}