summaryrefslogtreecommitdiff
path: root/rts/RtsUtils.c
diff options
context:
space:
mode:
Diffstat (limited to 'rts/RtsUtils.c')
-rw-r--r--rts/RtsUtils.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c
index a36532c40d..c83714337e 100644
--- a/rts/RtsUtils.c
+++ b/rts/RtsUtils.c
@@ -112,6 +112,18 @@ stgCallocBytes (int n, int m, char *msg)
return space;
}
+/* borrowed from the MUSL libc project */
+char *stgStrndup(const char *s, size_t n)
+{
+ size_t l = strnlen(s, n);
+ char *d = stgMallocBytes(l+1, "stgStrndup");
+ if (!d) return NULL;
+ memcpy(d, s, l);
+ d[l] = 0;
+ return d;
+}
+
+
/* To simplify changing the underlying allocator used
* by stgMallocBytes(), provide stgFree() as well.
*/