Any comments, suggestions, swears concerning adding a new function, 
strndup(), to libc?

So that instead of permitting it to attempt to allocate a large chunk of 
memory, it is possible to give it a max length.

char *
strndup(str, max_len)
        const char *str;
        size_t max_len;
{
        size_t len;
        char *copy;

        len = strlen(str) + 1;
        if (len > max_len)
                len = max_len;
        if ((copy = malloc(len)) == NULL)
                return (NULL);
        memcpy(copy, str, len);
        return (copy);
}

-- 
Daniel Hemmerich
[EMAIL PROTECTED]

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to