From owner-freebsd-hackers Sat May 12 7:59:56 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from assaris.sics.se (h122n4fls32o892.telia.com [213.64.47.122]) by hub.freebsd.org (Postfix) with ESMTP id A72ED37B424 for ; Sat, 12 May 2001 07:59:50 -0700 (PDT) (envelope-from assar@assaris.sics.se) Received: (from assar@localhost) by assaris.sics.se (8.9.3/8.9.3) id QAA04783; Sat, 12 May 2001 16:59:41 +0200 (CEST) (envelope-from assar) To: dan@BSDpro.com Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: adding a new function to libc References: <01051202104500.95296@blackhole.BSDpro.com> From: Assar Westerlund Date: 12 May 2001 16:59:41 +0200 In-Reply-To: Daniel Hemmerich's message of "Sat, 12 May 2001 02:10:45 -0400" Message-ID: <5ld79efw9u.fsf@assaris.sics.se> Lines: 27 User-Agent: Gnus/5.070098 (Pterodactyl Gnus v0.98) Emacs/20.6 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Daniel Hemmerich 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