Skip to content
Snippets Groups Projects
Commit 36966909 authored by Stephen Hurd's avatar Stephen Hurd
Browse files

Add strndup() and strnlen() from FreeBSD (used by RIP support)

parent 678627db
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -38,5 +38,36 @@ char* ltoa(long val, char* str, int radix)
}
return(str);
}
#endif
#ifdef _WIN32
/* From FreeBSD */
size_t
strnlen(const char *s, size_t maxlen)
{
size_t len;
for (len = 0; len < maxlen; len++, s++) {
if (!*s)
break;
}
return (len);
}
/* From FreeBSD */
char *
strndup(const char *str, size_t maxlen)
{
char *copy;
size_t len;
len = strnlen(str, maxlen);
copy = malloc(len + 1);
if (copy != NULL) {
(void)memcpy(copy, str, len);
copy[len] = '\0';
}
return copy;
}
#endif
......@@ -18,4 +18,17 @@ char* ltoa(long val, char* str, int radix);
#endif
#ifdef _MSVC
#if defined(__cplusplus)
extern "C" {
#endif
char *strndup(const char *str, size_t maxlen);
size_t strnlen(const char *s, size_t maxlen);
#if defined(__cplusplus)
}
#endif
#endif
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment