aboutsummaryrefslogtreecommitdiff
path: root/builtins/util.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-07-26 13:28:18 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-07-26 13:28:18 -0400
commitcfe46ee393aa3c9a2344a916bccfc4a69d4b8b77 (patch)
treea5953090e0cb9c9d66b622d91012111ab30a89ea /builtins/util.c
parent87785555eca3b7166d5f1af658a08f58a64340ed (diff)
Replace heap_strn() with GC_strndup()
Diffstat (limited to 'builtins/util.c')
-rw-r--r--builtins/util.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/builtins/util.c b/builtins/util.c
index f7fa9f92..598ab259 100644
--- a/builtins/util.c
+++ b/builtins/util.c
@@ -11,20 +11,10 @@
public bool USE_COLOR;
-public char *heap_strn(const char *str, size_t len)
-{
- if (!str) return NULL;
- if (len == 0) return "";
- char *heaped = GC_MALLOC_ATOMIC(len + 1);
- memcpy(heaped, str, len);
- heaped[len] = '\0';
- return heaped;
-}
-
public char *heap_str(const char *str)
{
if (!str) return NULL;
- return heap_strn(str, strlen(str));
+ return GC_strndup(str, strlen(str));
}
public char *heap_strf(const char *fmt, ...)
@@ -35,7 +25,7 @@ public char *heap_strf(const char *fmt, ...)
int len = vasprintf(&tmp, fmt, args);
if (len < 0) return NULL;
va_end(args);
- char *ret = heap_strn(tmp, (size_t)len);
+ char *ret = GC_strndup(tmp, (size_t)len);
free(tmp);
return ret;
}