X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fstrchrnul.c;h=f834d3434d7a761a051bd91a2add2f88c6808cc9;hb=8d8bbae775e3c77070161dafc81c0c2dbba0fef4;hp=a5cfcb8f1266f3088b99c7e43167ca9b97e73a14;hpb=d2a45d9a8b6d045041db52a37fc7e1226d12deec;p=gnulib.git diff --git a/lib/strchrnul.c b/lib/strchrnul.c index a5cfcb8f1..f834d3434 100644 --- a/lib/strchrnul.c +++ b/lib/strchrnul.c @@ -1,5 +1,5 @@ /* Searching in a string. - Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc. + Copyright (C) 2003, 2007, 2008, 2009, 2010 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++; }