From owner-p4-projects@FreeBSD.ORG Thu Oct 16 07:21:08 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4C6F916A4C0; Thu, 16 Oct 2003 07:21:08 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1B69916A4B3 for ; Thu, 16 Oct 2003 07:21:08 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 915BB43F93 for ; Thu, 16 Oct 2003 07:21:07 -0700 (PDT) (envelope-from areisse@nailabs.com) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.9/8.12.9) with ESMTP id h9GEL6XJ091000 for ; Thu, 16 Oct 2003 07:21:07 -0700 (PDT) (envelope-from areisse@nailabs.com) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.9/8.12.9/Submit) id h9GEL5ZV090981 for perforce@freebsd.org; Thu, 16 Oct 2003 07:21:05 -0700 (PDT) (envelope-from areisse@nailabs.com) Date: Thu, 16 Oct 2003 07:21:05 -0700 (PDT) Message-Id: <200310161421.h9GEL5ZV090981@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to areisse@nailabs.com using -f From: Andrew Reisse To: Perforce Change Reviews Subject: PERFORCE change 39788 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Oct 2003 14:21:08 -0000 http://perforce.freebsd.org/chv.cgi?CH=39788 Change 39788 by areisse@areisse_ibook on 2003/10/16 07:20:07 add strlcpy to darwin Affected files ... .. //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/device/subrs.c#2 edit .. //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/libsa/string.h#2 edit Differences ... ==== //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/device/subrs.c#2 (text+ko) ==== @@ -330,3 +330,34 @@ return (old); } +/* Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + char *d = dst; + const char *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} ==== //depot/projects/trustedbsd/sedarwin/apsl/xnu/osfmk/libsa/string.h#2 (text+ko) ==== @@ -84,6 +84,7 @@ extern int strncmp(const char *,const char *, size_t); extern char *strchr(const char *s, int c); extern size_t strspn(const char *, const char *); +extern size_t strlcpy(char *, const char *, size_t); #ifdef __cplusplus }