diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2016-04-18 22:32:59 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-04-18 23:09:18 +0200 |
commit | d1ce35d2271ac8b79cb5e37677b1a989749e611c (patch) | |
tree | cafccb161304bf0f00320c4cc0e5966b8e8f6a39 /rts/RtsUtils.c | |
parent | 350ffc3e4c6b3aefd6ae621991564cc28f585d46 (diff) | |
download | haskell-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.c | 12 |
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. */ |