Add copy of strndup() for Lenny.

This commit is contained in:
Ed Schouten 2011-06-28 12:11:35 +02:00
parent c42612643a
commit d97d1b72d7
1 changed files with 17 additions and 1 deletions

View File

@ -287,6 +287,22 @@ encode(int in, int out)
#endif
static char *
do_strndup(const char *str, size_t n)
{
size_t len;
char *copy;
for (len = 0; len < n && str[len]; len++)
continue;
if ((copy = malloc(len + 1)) == NULL)
return (NULL);
memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
}
static char *
parsestring(const char *in)
{
@ -299,7 +315,7 @@ parsestring(const char *in)
len--;
if (len == 0)
return (NULL);
return (strndup(in, len));
return (do_strndup(in, len));
}
static uint32_t