2020-05-01 11:46:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-02-14 13:28:18 +01:00
|
|
|
#include <stdint.h>
|
2020-05-03 12:24:34 +02:00
|
|
|
#include <threads.h>
|
|
|
|
|
|
2020-05-01 11:46:24 +02:00
|
|
|
#define ALEN(v) (sizeof(v) / sizeof((v)[0]))
|
|
|
|
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
|
|
|
|
#define max(x, y) ((x) > (y) ? (x) : (y))
|
2020-05-03 12:24:34 +02:00
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
|
thrd_err_as_string(int thrd_err)
|
|
|
|
|
{
|
|
|
|
|
switch (thrd_err) {
|
2020-05-03 12:40:40 +02:00
|
|
|
case thrd_success: return "success";
|
2020-05-03 12:24:34 +02:00
|
|
|
case thrd_busy: return "busy";
|
|
|
|
|
case thrd_nomem: return "no memory";
|
|
|
|
|
case thrd_timedout: return "timedout";
|
|
|
|
|
|
|
|
|
|
case thrd_error:
|
|
|
|
|
default: return "unknown error";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "unknown error";
|
|
|
|
|
}
|
2021-02-14 13:28:18 +01:00
|
|
|
|
|
|
|
|
static inline uint64_t
|
|
|
|
|
sdbm_hash(const char *s)
|
|
|
|
|
{
|
|
|
|
|
uint64_t hash = 0;
|
|
|
|
|
|
|
|
|
|
for (; *s != '\0'; s++) {
|
|
|
|
|
int c = *s;
|
|
|
|
|
hash = c + (hash << 6) + (hash << 16) - hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
|
}
|