Date: 12 May 2001 16:59:41 +0200 From: Assar Westerlund <assar@FreeBSD.ORG> To: dan@BSDpro.com Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: adding a new function to libc Message-ID: <5ld79efw9u.fsf@assaris.sics.se> In-Reply-To: Daniel Hemmerich's message of "Sat, 12 May 2001 02:10:45 -0400" References: <01051202104500.95296@blackhole.BSDpro.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Daniel Hemmerich <dan@BSDpro.com> writes: > Any comments, suggestions, swears concerning adding a new function, > strndup(), to libc? See src/crypto/heimdal/lib/roken/strndup.c :-) > 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); > } Doesn't work for a non-terminated str and doesn't 0-terminate the return string when str is too long. /assar 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?5ld79efw9u.fsf>