summaryrefslogtreecommitdiff
path: root/head
diff options
context:
space:
mode:
Diffstat (limited to 'head')
-rw-r--r--head/defconf/ptrbox.h58
-rw-r--r--head/defconf/state.h3
2 files changed, 61 insertions, 0 deletions
diff --git a/head/defconf/ptrbox.h b/head/defconf/ptrbox.h
new file mode 100644
index 0000000..3358595
--- /dev/null
+++ b/head/defconf/ptrbox.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef DEFCONF_PTRBOX_H
+#define DEFCONF_PTRBOX_H 1
+
+#include <sys/queue.h>
+#include <stdint.h>
+#include <stddef.h>
+
+/*
+ * Represents a pointer box entry
+ *
+ * @data: Allocated data
+ * @link: TAILQ link
+ */
+struct ptrbox_entry {
+ void *data;
+ TAILQ_ENTRY(ptrbox_entry) link;
+};
+
+/*
+ * A pointer box stores references to memory to be freed later on
+ *
+ * @entries: Entries within pointer box
+ * @entry_count: Number of pointer box entries
+ */
+struct ptrbox {
+ TAILQ_HEAD(, ptrbox_entry) entries;
+ size_t entry_count;
+};
+
+/*
+ * Wrapper over strdup() but saved in a pointer box
+ *
+ * @ptrbox: Pointer box to allocate into
+ * @s: String to dup
+ *
+ * Returns the base of the dup'd string on success, otherwise
+ * NULL on failure.
+ */
+char *ptrbox_strdup(struct ptrbox *ptrbox, const char *s);
+
+/*
+ * Initialize a pointer box
+ */
+int ptrbox_init(struct ptrbox *ptrbox);
+
+/*
+ * Destroy a pointer box and all of its entries
+ *
+ * @ptrbox: Pointer box to destroy
+ */
+void ptrbox_destroy(struct ptrbox *ptrbox);
+
+#endif /* !DEFCONF_PTRBOX_H */
diff --git a/head/defconf/state.h b/head/defconf/state.h
index 524af3b..aa99105 100644
--- a/head/defconf/state.h
+++ b/head/defconf/state.h
@@ -9,16 +9,19 @@
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
+#include "defconf/ptrbox.h"
/*
* DEFCONF state machine
*
* @in_fp: Input file pointer
* @lex_cache: Putback cache
+ * @ptrbox: Global pointer box
*/
struct defconf_state {
FILE *in_fp;
int lex_cache;
+ struct ptrbox ptrbox;
};
/*