jcs
/subtext
/amendments
/30
util: Add strlcat
jcs made amendment 30 over 2 years ago
--- util.c Sat Dec 11 10:40:22 2021
+++ util.c Tue Dec 14 14:54:42 2021
@@ -167,6 +167,33 @@ strlcpy(char *dst, const char *src, size_t dsize)
return (src - osrc - 1);
}
+size_t
+strlcat(char *dst, const char *src, size_t dsize)
+{
+ const char *odst = dst;
+ const char *osrc = src;
+ size_t n = dsize;
+ size_t dlen;
+
+ while (n-- != 0 && *dst != '\0')
+ dst++;
+ dlen = dst - odst;
+ n = dsize - dlen;
+
+ if (n-- == 0)
+ return (dlen + strlen(src));
+ while (*src != '\0') {
+ if (n != 0) {
+ *dst++ = *src;
+ n--;
+ }
+ src++;
+ }
+ *dst = '\0';
+
+ return (dlen + (src - osrc));
+}
+
const char *
ordinal(unsigned short n)
{
--- util.h Sat Dec 11 10:40:31 2021
+++ util.h Tue Dec 14 14:55:01 2021
@@ -63,6 +63,7 @@ char *xstrdup(const char *);
short getline(char *str, size_t len, char **ret);
size_t strlcpy(char *dst, const char *src, size_t dsize);
+size_t strlcat(char *dst, const char *src, size_t dsize);
const char *ordinal(unsigned short n);
#if 0
/* from strnatcmp.c */