md5, sha1, sha256, sha512: add gl_SET_CRYPTO_CHECK_DEFAULT
[gnulib.git] / lib / strchrnul.c
index a5cfcb8..f6b0722 100644 (file)
@@ -1,5 +1,5 @@
 /* Searching in a string.
-   Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -37,6 +37,8 @@ strchrnul (const char *s, int c_in)
   unsigned char c;
 
   c = (unsigned char) c_in;
+  if (!c)
+    return rawmemchr (s, 0);
 
   /* Handle the first few bytes by reading one byte at a time.
      Do this until CHAR_PTR is aligned on a longword boundary.  */
@@ -62,15 +64,15 @@ strchrnul (const char *s, int c_in)
       repeated_one |= repeated_one << 31 << 1;
       repeated_c |= repeated_c << 31 << 1;
       if (8 < sizeof (longword))
-       {
-         size_t i;
-
-         for (i = 64; i < sizeof (longword) * 8; i *= 2)
-           {
-             repeated_one |= repeated_one << i;
-             repeated_c |= repeated_c << i;
-           }
-       }
+        {
+          size_t i;
+
+          for (i = 64; i < sizeof (longword) * 8; i *= 2)
+            {
+              repeated_one |= repeated_one << i;
+              repeated_c |= repeated_c << i;
+            }
+        }
     }
 
   /* Instead of the traditional loop which tests each byte, we will
@@ -118,9 +120,9 @@ strchrnul (const char *s, int c_in)
       longword longword2 = *longword_ptr;
 
       if (((((longword1 - repeated_one) & ~longword1)
-           | ((longword2 - repeated_one) & ~longword2))
-          & (repeated_one << 7)) != 0)
-       break;
+            | ((longword2 - repeated_one) & ~longword2))
+           & (repeated_one << 7)) != 0)
+        break;
       longword_ptr++;
     }