2 * This file is Copyright (c) 2010 by the GPSD project
3 * BSD terms apply: see the file COPYING in the distribution root for details.
8 #endif /* S_SPLINT_S */
11 #include "gpsd_config.h"
14 /* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
17 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
19 * Permission to use, copy, modify, and distribute this software for any
20 * purpose with or without fee is hereby granted, provided that the above
21 * copyright notice and this permission notice appear in all copies.
23 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
24 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
26 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
27 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
28 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
29 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33 * Appends src to string dst of size siz (unlike strncat, siz is the
34 * full size of dst, not space left). At most siz-1 characters
35 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
36 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
37 * If retval >= siz, truncation occurred.
39 /*@ -usedef -mustdefine @*/
40 size_t strlcat(char *dst, const char *src, size_t siz)
47 /* Find the end of dst and adjust bytes left but don't go past end */
48 while (n-- != 0 && *d != '\0')
50 dlen = (size_t) (d - dst);
54 return (dlen + strlen(s));
64 return (dlen + (s - src)); /* count does not include NUL */
67 /*@ +usedef +mustdefine @*/
68 #endif /* HAVE_STRLCAT */
71 /* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
74 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
76 * Permission to use, copy, modify, and distribute this software for any
77 * purpose with or without fee is hereby granted, provided that the above
78 * copyright notice and this permission notice appear in all copies.
80 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
81 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
82 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
83 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
84 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
85 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
86 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
90 * Copy src to string dst of size siz. At most siz-1 characters
91 * will be copied. Always NUL terminates (unless siz == 0).
92 * Returns strlen(src); if retval >= siz, truncation occurred.
94 size_t strlcpy(char *dst, const char *src, size_t siz)
100 /* Copy as many bytes as will fit */
103 if ((*d++ = *s++) == '\0')
108 /* Not enough room in dst, add NUL and traverse rest of src */
111 *d = '\0'; /* NUL-terminate dst */
116 return ((size_t) (s - src - 1)); /* count does not include NUL */
118 #endif /* HAVE_STRLCPY */