Date: Thu, 16 Oct 2003 07:21:05 -0700 (PDT) From: Andrew Reisse <areisse@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 39788 for review Message-ID: <200310161421.h9GEL5ZV090981@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200310161421.h9GEL5ZV090981>