|
@@ -1425,3 +1425,42 @@ int modbus_accept(modbus_t *ctx, int *socket)
|
|
|
{
|
|
|
return ctx->backend->accept(ctx, socket);
|
|
|
}
|
|
|
+
|
|
|
+#ifndef HAVE_STRLCPY
|
|
|
+/*
|
|
|
+/* Function strlcpy was originally developed by
|
|
|
+ * Todd C. Miller <Todd.Miller@courtesan.com> to simplify writing secure code.
|
|
|
+ * See ftp://ftp.openbsd.org/pub/OpenBSD/src/lib/libc/string/strlcpy.3
|
|
|
+ * for more information.
|
|
|
+ *
|
|
|
+ * Thank you Ulrich Drepper... not!
|
|
|
+ *
|
|
|
+ * Copy src to string dest of size dest_size. At most dest_size-1 characters
|
|
|
+ * will be copied. Always NUL terminates (unless dest_size == 0). Returns
|
|
|
+ * strlen(src); if retval >= dest_size, truncation occurred.
|
|
|
+ */
|
|
|
+size_t strlcpy(char *dest, const char *src, size_t dest_size)
|
|
|
+{
|
|
|
+ register char *d = dest;
|
|
|
+ register const char *s = src;
|
|
|
+ register size_t n = dest_size;
|
|
|
+
|
|
|
+ /* Copy as many bytes as will fit */
|
|
|
+ if (n != 0 && --n != 0) {
|
|
|
+ do {
|
|
|
+ if ((*d++ = *s++) == 0)
|
|
|
+ break;
|
|
|
+ } while (--n != 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Not enough room in dest, add NUL and traverse rest of src */
|
|
|
+ if (n == 0) {
|
|
|
+ if (dest_size != 0)
|
|
|
+ *d = '\0'; /* NUL-terminate dest */
|
|
|
+ while (*s++)
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ return (s - src - 1); /* count does not include NUL */
|
|
|
+}
|
|
|
+#endif
|