Date: Sat, 12 May 2001 02:10:45 -0400 From: Daniel Hemmerich <dan@BSDpro.com> To: freebsd-hackers@freebsd.org Subject: adding a new function to libc Message-ID: <01051202104500.95296@blackhole.BSDpro.com>
next in thread | raw e-mail | index | archive | help
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
dan@BSDpro.com
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01051202104500.95296>
