mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-13 21:12:56 -04:00
36 lines
561 B
C
36 lines
561 B
C
|
/*
|
||
|
* simple utility functions
|
||
|
*/
|
||
|
|
||
|
#ifdef HAVE_CONFIG_H
|
||
|
# include "config.h"
|
||
|
#endif
|
||
|
|
||
|
#ifdef HAVE_STDINT_H
|
||
|
# include <stdint.h>
|
||
|
#endif
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <sys/types.h>
|
||
|
|
||
|
uint32_t util_djb_hash_block(unsigned char *data, uint32_t len) {
|
||
|
uint32_t hash = 5381;
|
||
|
unsigned char *pstr = data;
|
||
|
|
||
|
while(len--) {
|
||
|
hash = ((hash << 5) + hash) + *pstr;
|
||
|
pstr++;
|
||
|
}
|
||
|
return hash;
|
||
|
}
|
||
|
|
||
|
|
||
|
uint32_t util_djb_hash_str(char *str) {
|
||
|
uint32_t len;
|
||
|
|
||
|
len = strlen(str);
|
||
|
return util_djb_hash_block((unsigned char *)str,len);
|
||
|
}
|
||
|
|