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

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

parent 9cb86e84
Branches
Tags
No related merge requests found
......@@ -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