diff --git a/util/string-util.c b/util/string-util.c index 3e7066cd..a90501ee 100644 --- a/util/string-util.c +++ b/util/string-util.c @@ -37,6 +37,14 @@ strtok_len (char *s, const char *delim, size_t *len) return *len ? s : NULL; } +const char * +strtok_len_c (const char *s, const char *delim, size_t *len) +{ + /* strtok_len is already const-safe, but we can't express both + * versions in the C type system. */ + return strtok_len ((char*)s, delim, len); +} + char * sanitize_string (const void *ctx, const char *str) { diff --git a/util/string-util.h b/util/string-util.h index ccad17f1..e409cb3d 100644 --- a/util/string-util.h +++ b/util/string-util.h @@ -23,6 +23,9 @@ extern "C" { char *strtok_len (char *s, const char *delim, size_t *len); +/* Const version of strtok_len. */ +const char *strtok_len_c (const char *s, const char *delim, size_t *len); + /* Return a talloced string with str sanitized. * * Whitespace characters (tabs and newlines) are replaced with spaces,