2021-05-07 00:15:17 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2021-05-16 07:42:37 +00:00
|
|
|
#include <stdlib.h>
|
2021-05-07 00:15:17 +00:00
|
|
|
|
2021-05-16 07:42:37 +00:00
|
|
|
char *strdup(const char *s)
|
2021-05-07 00:15:17 +00:00
|
|
|
{
|
2021-05-16 07:42:37 +00:00
|
|
|
size_t slen = strlen(s);
|
|
|
|
char *result = (char *)malloc(slen + 1);
|
|
|
|
if (result == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-05-07 00:15:17 +00:00
|
|
|
|
2021-05-16 07:42:37 +00:00
|
|
|
memcpy(result, s, slen + 1);
|
|
|
|
return result;
|
|
|
|
}
|
2021-05-20 20:18:57 +00:00
|
|
|
|
|
|
|
uint64_t str_hash(char *str)
|
|
|
|
{
|
|
|
|
uint64_t hash = 5381;
|
|
|
|
size_t c;
|
|
|
|
|
|
|
|
while (c = *str++)
|
|
|
|
{
|
|
|
|
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|