diff options
author | Andrew Waterman <waterman@s144.Millennium.Berkeley.EDU> | 2010-11-09 23:23:53 -0800 |
---|---|---|
committer | Andrew Waterman <waterman@s144.Millennium.Berkeley.EDU> | 2010-11-21 16:54:35 -0800 |
commit | 37ed1d3297fcb84c67040a9bcebbfc2274f62735 (patch) | |
tree | bc5284769c33ee0ce8069a3ed6d806735c4e7e86 /pk/strlen.c | |
parent | 63729473a588960ade22d42b94bcd1fa7fb11e71 (diff) | |
download | pk-37ed1d3297fcb84c67040a9bcebbfc2274f62735.zip pk-37ed1d3297fcb84c67040a9bcebbfc2274f62735.tar.gz pk-37ed1d3297fcb84c67040a9bcebbfc2274f62735.tar.bz2 |
[pk] fixed memset bug
Diffstat (limited to 'pk/strlen.c')
-rw-r--r-- | pk/strlen.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/pk/strlen.c b/pk/strlen.c index f600d47..12b3836 100644 --- a/pk/strlen.c +++ b/pk/strlen.c @@ -1,13 +1,18 @@ #include <string.h> -#include <stdlib.h> +#include <limits.h> + +#if ULONG_MAX != 18446744073709551615UL && ULONG_MAX != 4294967295UL +# error need sizeof(long) == 4 or sizeof(long) == 8 +#endif // from http://www-graphics.stanford.edu/~seander/bithacks.html static inline long hasZeroByte(long l) { - if(sizeof(long) == 4) - return (l - 0x01010101UL) & ~l & 0x80808080UL; - else if(sizeof(long) == 8) - return (l - 0x0101010101010101UL) & ~l & 0x8080808080808080UL; +#if ULONG_MAX == 4294967295UL + return (l - 0x01010101UL) & ~l & 0x80808080UL; +#else + return (l - 0x0101010101010101UL) & ~l & 0x8080808080808080UL; +#endif } size_t strlen(const char* s) |