summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 534013eb..cf2d6cf8 100644
--- a/lib.c
+++ b/lib.c
@@ -4293,6 +4293,21 @@ char *chk_strdup_utf8(const char *str)
return copy;
}
+char *chk_substrdup_utf8(const char *str, size_t off, size_t len)
+{
+ size_t size = strlen(str) + 1, nchar;
+ char *copy;
+ if (off >= size - 1)
+ return chk_strdup_utf8("");
+ if (off + len < off)
+ uw_throw(error_s, lit("string size overflow"));
+ nchar = min(size - off, len + 1);
+ copy = coerce(char *, chk_malloc(nchar));
+ memcpy(copy, str, nchar - 1);
+ copy[nchar - 1] = 0;
+ return copy;
+}
+
unsigned char *chk_strdup_8bit(const wchar_t *str)
{
size_t nchar = wcslen(str) + 1, i;