wraith-lang/src/util.c

30 lines
447 B
C
Raw Normal View History

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;
}
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;
}