1 /* flac - Command-line FLAC encoder/decoder
11 #include "local_string_utils.h"
13 /* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $
15 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
17 * Permission to use, copy, modify, and distribute this software for any
18 * purpose with or without fee is hereby granted, provided that the above
19 * copyright notice and this permission notice appear in all copies.
21 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 * Copy src to string dst of size siz. At most siz-1 characters
31 * will be copied. Always NUL terminates (unless siz == 0).
32 * Returns strlen(src); if retval >= siz, truncation occurred.
35 flac__strlcpy(char *dst, const char *src, size_t siz)
37 register char *d = dst;
38 register const char *s = src;
39 register size_t n = siz;
41 /* Copy as many bytes as will fit */
42 if (n != 0 && --n != 0) {
44 if ((*d++ = *s++) == 0)
49 /* Not enough room in dst, add NUL and traverse rest of src */
52 *d = '\0'; /* NUL-terminate dst */
57 return(s - src - 1); /* count does not include NUL */
60 /* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $
62 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
64 * Permission to use, copy, modify, and distribute this software for any
65 * purpose with or without fee is hereby granted, provided that the above
66 * copyright notice and this permission notice appear in all copies.
68 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
69 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
70 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
71 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
72 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
73 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
74 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
77 * Appends src to string dst of size siz (unlike strncat, siz is the
78 * full size of dst, not space left). At most siz-1 characters
79 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
80 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
81 * If retval >= siz, truncation occurred.
84 flac__strlcat(char *dst, const char *src, size_t siz)
86 register char *d = dst;
87 register const char *s = src;
88 register size_t n = siz;
91 /* Find the end of dst and adjust bytes left but don't go past end */
92 while (n-- != 0 && *d != '\0')
98 return(dlen + strlen(s));
108 return(dlen + (s - src)); /* count does not include NUL */