From f57e2eabe0a10c9732c83532e01654a499fb8dcf Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 21 Jun 2021 17:47:13 -0400 Subject: many, many changes; settings is broken --- src/user/knob/block.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/user/knob/block.c') diff --git a/src/user/knob/block.c b/src/user/knob/block.c index 9f3f353..8b9971f 100644 --- a/src/user/knob/block.c +++ b/src/user/knob/block.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -28,13 +29,22 @@ uint32_t strcpy(char *to, const char *from) { } char *strdup(const char *from) { - const char *end = from; - while (*(end++)) - ; - char *buf = get_block(end - from); - if (!buf) - PANIC("get_block returned 0 in strdup"); - blockcpy(buf, from, end - from); + const uint32_t len = strlen(from) + 1; + char *buf = get_block(len); + blockcpy(buf, from, len); + return buf; +} + +char *strndup(const char *from, uint32_t n) { + uint32_t len = strlen(from) + 1; + if (n < len) { + char *buf = get_block(n + 1); + blockcpy(buf, from, n); + buf[n] = '\0'; + return buf; + } + char *buf = get_block(len); + blockcpy(buf, from, len); return buf; } -- cgit v1.2.3