Manually implement strndup

Mac and Windows don't appear to have that function, so just implement the
poor man's version by hand.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-05-07 09:28:26 -07:00
parent ba31a57857
commit a0a25554a7

View file

@ -75,6 +75,7 @@ static void show_utf8(struct membuffer *b, const char *text, const char *pre, co
if (!text)
return;
/* remove leading and trailing space */
while (isspace(*text))
text++;
len = strlen(text);
@ -82,7 +83,9 @@ static void show_utf8(struct membuffer *b, const char *text, const char *pre, co
return;
while (len && isspace(text[len - 1]))
len--;
cleaned = strndup(text, len);
/* strndup would be easier, but that doesn't appear to exist on Windows / Mac */
cleaned = strdup(text);
cleaned[len] = '\0';
put_string(b, pre);
quote(b, cleaned, is_attribute);
put_string(b, post);