added inline stdnstr() implementation for systems where it doesnt exists (e.g. linux)

This commit is contained in:
git@daemon.de
2014-03-10 16:58:48 +01:00
parent f383630e8e
commit 770d464dd1
4 changed files with 36 additions and 0 deletions

4
TODO
View File

@@ -25,6 +25,10 @@ Symmetric decrypt mode tries to open vault
pcp_find_primary_secret() makes a copy ???
sym encrypt mac => mac, mac => freebsd and freebsd => mac doesnt work
c++ destructor double free mess
Python binding, e.g.:
py % cdll.LoadLibrary("libsodium.so.8")
<CDLL 'libsodium.so.8', handle 800776c00 at 80192a3d0>

View File

@@ -76,6 +76,7 @@ AC_CHECK_FUNCS( \
memcpy \
perror \
strnlen \
strnstr \
strlen \
strtol \
sizeof \

View File

@@ -118,6 +118,9 @@
/* Define to 1 if you have the `strnlen' function. */
#undef HAVE_STRNLEN
/* Define to 1 if you have the `strnstr' function. */
#undef HAVE_STRNSTR
/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL

View File

@@ -157,5 +157,33 @@ strnlen(const char *msg, size_t maxlen)
}
#endif
#ifndef HAVE_STRNSTR
/* via FreeBSD libc */
#include <string.h>
static inline char *
strnstr(const char *s, const char *find, size_t slen)
{
char c, sc;
size_t len;
if ((c = *find++) != '\0') {
len = strlen(find);
do {
do {
if (slen-- < 1 || (sc = *s++) == '\0')
return (NULL);
} while (sc != c);
if (len > slen)
return (NULL);
} while (strncmp(s, find, len) != 0);
s--;
}
return ((char *)s);
}
#endif
#endif /* !_HAVE_PCP_PLATFORM_H */