wraith-lang/src/util.c

30 lines
447 B
C

#include "util.h"
#include <stdlib.h>
char *strdup(const char *s)
{
size_t slen = strlen(s);
char *result = (char *)malloc(slen + 1);
if (result == NULL)
{
return NULL;
}
memcpy(result, s, slen + 1);
return result;
}
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;
}