From owner-freebsd-hackers Fri May 11 23:10:50 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from digitalinet.com (digitalinet.com [216.65.124.130]) by hub.freebsd.org (Postfix) with SMTP id 1C29137B43C for ; Fri, 11 May 2001 23:10:47 -0700 (PDT) (envelope-from dan@BSDpro.com) Received: (qmail 73695 invoked from network); 12 May 2001 06:10:49 -0000 Received: from unknown (HELO blackhole.BSDpro.com) (216.27.143.75) by host194.digitalinet.com with SMTP; 12 May 2001 06:10:49 -0000 Content-Type: text/plain; charset="iso-8859-1" From: Daniel Hemmerich Reply-To: dan@BSDpro.com Organization: www.BSDpro.com To: freebsd-hackers@freebsd.org Subject: adding a new function to libc Date: Sat, 12 May 2001 02:10:45 -0400 X-Mailer: KMail [version 1.2] MIME-Version: 1.0 Message-Id: <01051202104500.95296@blackhole.BSDpro.com> Content-Transfer-Encoding: 8bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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