X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fmemchr.c;h=44a9dc5e077d7d064b833ea27b38e71a5b203b16;hb=180239d459deeb88e364969a142ad19403e7b1b1;hp=74951063629be982e38b555be63f9d951f1fada2;hpb=be12cc04b38ea7feb8c569a18e32c626cd3b98b0;p=gnulib.git diff --git a/lib/memchr.c b/lib/memchr.c index 749510636..44a9dc5e0 100644 --- a/lib/memchr.c +++ b/lib/memchr.c @@ -20,6 +20,16 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#if (SIZEOF_LONG != 4 && SIZEOF_LONG != 8) + error This function works only on systems for which sizeof(long) is 4 or 8. +/* The previous line would begin with `#error,' but some compilers can't + handle that even when the condition is false. */ +#endif + /* Search no more than N bytes of S for C. */ char * @@ -56,19 +66,18 @@ memchr (s, c, n) The 1-bits make sure that carries propagate to the next 0-bit. The 0-bits provide holes for carries to fall into. */ -#ifdef LONG_64_BITS - /* 64-bit version of the magic. */ +#if (SIZEOF_LONG == 8) magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff; #else magic_bits = 0x7efefeff; -#endif /* LONG_64_BITS */ +#endif /* SIZEOF_LONG == 8 */ /* Set up a longword, each of whose bytes is C. */ charmask = c | (c << 8); charmask |= charmask << 16; -#ifdef LONG_64_BITS +#if (SIZEOF_LONG == 8) charmask |= charmask << 32; -#endif /* LONG_64_BITS */ +#endif /* SIZEOF_LONG == 8 */ if (sizeof (longword) > 8) abort (); @@ -138,7 +147,7 @@ memchr (s, c, n) return (char *) &cp[2]; if (cp[3] == c) return (char *) &cp[3]; -#ifdef LONG_64_BITS +#if (SIZEOF_LONG == 8) if (cp[4] == c) return (char *) &cp[4]; if (cp[5] == c) @@ -147,7 +156,7 @@ memchr (s, c, n) return (char *) &cp[6]; if (cp[7] == c) return (char *) &cp[7]; -#endif /* LONG_64_BITS */ +#endif /* SIZEOF_LONG == 8 */ } n -= sizeof (longword);