diff --git a/mongoose.c b/mongoose.c index 62cbd6f8..d47f94ea 100644 --- a/mongoose.c +++ b/mongoose.c @@ -971,6 +971,11 @@ struct mg_str mg_mk_str(const char *s) { return ret; } +struct mg_str mg_mk_str_n(const char *s, size_t len) { + struct mg_str ret = {s, len}; + return ret; +} + int mg_vcmp(const struct mg_str *str1, const char *str2) { size_t n2 = strlen(str2), n1 = str1->len; int r = memcmp(str1->p, str2, (n1 < n2) ? n1 : n2); diff --git a/mongoose.h b/mongoose.h index c22f79d7..e095f963 100644 --- a/mongoose.h +++ b/mongoose.h @@ -862,10 +862,11 @@ struct mg_str { }; /* - * A helper function for creating mg_str struct from plain C string. + * Helper functions for creating mg_str struct from plain C string. * `NULL` is allowed and becomes `{NULL, 0}`. */ struct mg_str mg_mk_str(const char *s); +struct mg_str mg_mk_str_n(const char *s, size_t len); /* Macro for initializing mg_str. */ #define MG_MK_STR(str_literal) \