Use the correct macro _WIN32 for Windows.
[mesa.git] / src / gallium / auxiliary / util / u_string.h
index 08c89bbf7708f976422811a75bad7b593fc6cafa..15630ad0791bf0947903267e9639bebe08bad96d 100644 (file)
@@ -35,7 +35,7 @@
 #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, ...);
@@ -72,12 +87,9 @@ util_sprintf(char *str, 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*
@@ -130,7 +142,7 @@ 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) {