summaryrefslogtreecommitdiff
path: root/rts/RtsUtils.c
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2016-04-18 22:32:59 +0200
committerBen Gamari <ben@smart-cactus.org>2016-04-18 23:09:18 +0200
commitd1ce35d2271ac8b79cb5e37677b1a989749e611c (patch)
treecafccb161304bf0f00320c4cc0e5966b8e8f6a39 /rts/RtsUtils.c
parent350ffc3e4c6b3aefd6ae621991564cc28f585d46 (diff)
downloadhaskell-d1ce35d2271ac8b79cb5e37677b1a989749e611c.tar.gz
rts: Don't use strndup
Reviewers: austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2125
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.
*/