mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 07:05:57 -05:00
split well-used utility functions into util.c
This commit is contained in:
parent
7a3a5ce3af
commit
26e4259332
35
src/util.c
Normal file
35
src/util.c
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
24
src/util.h
Normal file
24
src/util.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* simple utility functions
|
||||
*/
|
||||
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* simple hashing functions */
|
||||
extern uint32_t util_djb_hash_block(unsigned char *data, uint32_t len);
|
||||
extern uint32_t util_djb_hash_str(char *str);
|
||||
|
||||
|
||||
#endif /* _UTIL_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user