latest brlib version

This commit is contained in:
2023-06-21 10:54:38 +02:00
parent aaa9cb8690
commit e1570fa34a
30 changed files with 2890 additions and 449 deletions

29
libsrc/hash.c Normal file
View File

@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: GPL-2.0 */
/* inspired from kernel's <fs/namei.h>
*/
#include "hash.h"
/* Return the hash of a string of known length */
unsigned int hash_string(const void *salt, const char *name, unsigned int len)
{
unsigned long hash = init_name_hash(salt);
while (len--)
hash = partial_name_hash((unsigned char)*name++, hash);
return end_name_hash(hash);
}
/* Return the "hash_len" (hash and length) of a null-terminated string */
u64 hashlen_string(const void *salt, const char *name)
{
unsigned long hash = init_name_hash(salt);
unsigned long len = 0, c;
c = (unsigned char)*name;
while (c) {
len++;
hash = partial_name_hash(c, hash);
c = (unsigned char)name[len];
}
return hashlen_create(end_name_hash(hash), len);
}