From 39db5071532630f38bc617e3b7d36dc3005ce3e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 1 Oct 2025 14:56:15 -0400 Subject: kern: ptrbox: Add string duplication Signed-off-by: Ian Moffett --- src/sys/lib/ptrbox.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/sys/lib/ptrbox.c') diff --git a/src/sys/lib/ptrbox.c b/src/sys/lib/ptrbox.c index b8370e5..bc84145 100644 --- a/src/sys/lib/ptrbox.c +++ b/src/sys/lib/ptrbox.c @@ -116,3 +116,27 @@ ptrbox_init(struct ptrbox **box_res) *box_res = box; return 0; } + +/* + * String duplication + */ +char * +ptrbox_strdup(const char *s, struct ptrbox *box) +{ + size_t len; + char *s_new; + + if (s == NULL || box == NULL) { + return NULL; + } + + len = strlen(s); + s_new = ptrbox_alloc(len + 1, box); + if (s_new == NULL) { + return NULL; + } + + memcpy(s_new, s, len); + s_new[len] = '\0'; + return s_new; +} -- cgit v1.2.3