]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Do not use strnlen
authorJürg Billeter <j@bitron.ch>
Wed, 16 Mar 2011 17:33:58 +0000 (18:33 +0100)
committerJürg Billeter <j@bitron.ch>
Wed, 16 Mar 2011 17:35:27 +0000 (18:35 +0100)
strnlen is not available on all systems.

Fixes bug 644550.

vapi/glib-2.0.vapi

index c9d7820fa7f8e061dfdc078e4e00a89bbf1db1f8..b953e68213a5010f876c535ce18cec947c0ada58 100644 (file)
@@ -1277,8 +1277,19 @@ public class string {
        [CCode (cname = "g_strndup")]
        public string ndup (size_t n);
 
-       [CCode (cname = "strnlen")]
-       static long strnlen (char* str, size_t maxlen);
+       [CCode (cname = "memchr")]
+       static char* memchr (char* s, int c, size_t n);
+
+       // strnlen is not available on all systems
+       static long strnlen (char* str, long maxlen) {
+               char* end = memchr (str, 0, maxlen);
+               if (end == null) {
+                       return maxlen;
+               } else {
+                       return (long) (end - str);
+               }
+       }
+
        [CCode (cname = "g_strndup")]
        static string strndup (char* str, size_t n);