#ifndef U_STRING_H_
#define U_STRING_H_
-#if !defined(WIN32) && !defined(XF86_LIBC_H)
+#if !defined(_WIN32) && !defined(XF86_LIBC_H)
#include <stdio.h>
#endif
#include <stddef.h>
extern "C" {
#endif
+#ifdef _GNU_SOURCE
-#ifdef WIN32
+#define util_strchrnul strchrnul
+
+#else
+
+static INLINE char *
+util_strchrnul(const char *s, char c)
+{
+ for (; *s && *s != c; ++s);
+
+ return (char *)s;
+}
+
+#endif
+
+#ifdef _WIN32
int util_vsnprintf(char *, size_t, const char *, va_list);
int util_snprintf(char *str, size_t size, const char *format, ...);
static INLINE char *
util_strchr(const char *s, char c)
{
- while(*s) {
- if(*s == c)
- return (char *)s;
- ++s;
- }
- return NULL;
+ char *p = util_strchrnul(s, c);
+
+ return *p ? p : NULL;
}
static INLINE char*
util_strstr(const char *haystack, const char *needle)
{
const char *p = haystack;
- int len = strlen(needle);
+ size_t len = strlen(needle);
for (; (p = util_strchr(p, *needle)) != 0; p++) {
if (util_strncmp(p, needle, len) == 0) {