git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: wrapper function for bootstraping user program
[lunaix-os.git]
/
lunaix-os
/
libs
/
hash.c
diff --git
a/lunaix-os/libs/hash.c
b/lunaix-os/libs/hash.c
index 293ec67bc3bddb6d7a450e09e32009c5f827f4e3..41fa4b19dd9726610cc255927d3f8c673fcabf69 100644
(file)
--- a/
lunaix-os/libs/hash.c
+++ b/
lunaix-os/libs/hash.c
@@
-8,13
+8,16
@@
* @param str
* @return unsigned int
*/
* @param str
* @return unsigned int
*/
-u
int
32_t
-strhash_32(
unsigned char* str, uint
32_t truncate_to)
+u32_t
+strhash_32(
const char* str, u
32_t truncate_to)
{
{
- uint32_t hash = 5381;
+ if (!str)
+ return 0;
+
+ u32_t hash = 5381;
int c;
int c;
- while (
c = *str++
)
+ while (
(c = *str++)
)
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash >> (HASH_SIZE_BITS - truncate_to);
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash >> (HASH_SIZE_BITS - truncate_to);