Add strlcpy(), strlcat()
authorhpa <hpa>
Tue, 21 Dec 2004 04:57:40 +0000 (04:57 +0000)
committerhpa <hpa>
Tue, 21 Dec 2004 04:57:40 +0000 (04:57 +0000)
com32/lib/strlcat.c [new file with mode: 0644]
com32/lib/strlcpy.c [new file with mode: 0644]

diff --git a/com32/lib/strlcat.c b/com32/lib/strlcat.c
new file mode 100644 (file)
index 0000000..6111445
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * strlcat.c
+ */
+
+#include <string.h>
+#include <klibc/compiler.h>
+
+size_t strlcat(char *dst, const char *src, size_t size)
+{
+  size_t bytes = 0;
+  char *q = dst;
+  const char *p = src;
+  char ch;
+
+  while ( bytes < size && *q ) {
+    q++;
+    bytes++;
+  }
+
+  while ( (ch = *p++) ) {
+    if ( bytes < size )
+      *q++ = ch;
+
+    bytes++;
+  }
+
+  *q = '\0';
+  return bytes;
+}
+
+
diff --git a/com32/lib/strlcpy.c b/com32/lib/strlcpy.c
new file mode 100644 (file)
index 0000000..eb384c9
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * strlcpy.c
+ */
+
+#include <string.h>
+#include <klibc/compiler.h>
+
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+  size_t bytes = 0;
+  char *q = dst;
+  const char *p = src;
+  char ch;
+
+  while ( (ch = *p++) ) {
+    if ( bytes < size )
+      *q++ = ch;
+
+    bytes++;
+  }
+
+  *q = '\0';
+  return bytes;
+}
+
+