2 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 /* https://git.datadissipation.net */
21 #ifdef STRLCAT_INCLUDE_LIBC
24 #endif /* !STRLCAT_INCLUDE_LIBC */
27 #define HAVE_STRLCAT 1
28 #define strlcat i_strlcat_
29 #define strlcpy i_strlcpy_
30 size_t i_strlcat_(char *dst
, const char *src
, size_t siz
);
31 size_t i_strlcpy_(char *dst
, const char *src
, size_t siz
);
32 #endif /* !HAVE_STRLCAT */
34 #ifdef STRLCAT_IMPLEMENTATION
36 * Appends src to string dst of size siz (unlike strncat, siz is the
37 * full size of dst, not space left). At most siz-1 characters
38 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
39 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
40 * If retval >= siz, truncation occurred.
43 i_strlcat_(char *dst
, const char *src
, size_t siz
)
49 /* Find the end of dst and adjust bytes left but don't go past end */
50 while (n
-- != 0 && *d
!= '\0')
55 return (dlen
+ strlen(s
));
64 return (dlen
+ (s
- src
)); /* count does not include NUL */
68 * Copy src to string dst of size siz. At most siz-1 characters
69 * will be copied. Always NUL terminates (unless siz == 0).
70 * Returns strlen(src); if retval >= siz, truncation occurred.
73 i_strlcpy_(char *dst
, const char *src
, size_t siz
)
78 /* Copy as many bytes as will fit */
81 if ((*d
++ = *s
++) == '\0')
85 /* Not enough room in dst, add NUL and traverse rest of src */
88 *d
= '\0'; /* NUL-terminate dst */
92 return(s
- src
- 1); /* count does not include NUL */
94 #endif /* STRLCAT_IMPLEMENTATION */
95 #endif /* !STRLCAT_H_ */