1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/third_party/libevent/strlcpy.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 1.4 +/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ 1.5 + 1.6 +/* 1.7 + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 1.8 + * All rights reserved. 1.9 + * 1.10 + * Redistribution and use in source and binary forms, with or without 1.11 + * modification, are permitted provided that the following conditions 1.12 + * are met: 1.13 + * 1. Redistributions of source code must retain the above copyright 1.14 + * notice, this list of conditions and the following disclaimer. 1.15 + * 2. Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 3. The name of the author may not be used to endorse or promote products 1.19 + * derived from this software without specific prior written permission. 1.20 + * 1.21 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 1.22 + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 1.23 + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 1.24 + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.25 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.26 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 1.27 + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 1.28 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 1.29 + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 1.30 + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.31 + */ 1.32 + 1.33 +#if defined(LIBC_SCCS) && !defined(lint) 1.34 +static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; 1.35 +#endif /* LIBC_SCCS and not lint */ 1.36 + 1.37 +#include <sys/types.h> 1.38 + 1.39 +#include "event2/event-config.h" 1.40 + 1.41 +#ifndef _EVENT_HAVE_STRLCPY 1.42 +#include "strlcpy-internal.h" 1.43 + 1.44 +/* 1.45 + * Copy src to string dst of size siz. At most siz-1 characters 1.46 + * will be copied. Always NUL terminates (unless siz == 0). 1.47 + * Returns strlen(src); if retval >= siz, truncation occurred. 1.48 + */ 1.49 +size_t 1.50 +_event_strlcpy(dst, src, siz) 1.51 + char *dst; 1.52 + const char *src; 1.53 + size_t siz; 1.54 +{ 1.55 + register char *d = dst; 1.56 + register const char *s = src; 1.57 + register size_t n = siz; 1.58 + 1.59 + /* Copy as many bytes as will fit */ 1.60 + if (n != 0 && --n != 0) { 1.61 + do { 1.62 + if ((*d++ = *s++) == 0) 1.63 + break; 1.64 + } while (--n != 0); 1.65 + } 1.66 + 1.67 + /* Not enough room in dst, add NUL and traverse rest of src */ 1.68 + if (n == 0) { 1.69 + if (siz != 0) 1.70 + *d = '\0'; /* NUL-terminate dst */ 1.71 + while (*s++) 1.72 + ; 1.73 + } 1.74 + 1.75 + return (s - src - 1); /* count does not include NUL */ 1.76 +} 1.77 +#endif