mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 20:00:58 +01:00
added inline stdnstr() implementation for systems where it doesnt exists (e.g. linux)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user