diff --git a/src/dat/nbt.c b/src/dat/nbt.c index 4021b37..6da6055 100644 --- a/src/dat/nbt.c +++ b/src/dat/nbt.c @@ -2,6 +2,7 @@ #include #include +#include #include "../util/types.h" @@ -10,6 +11,19 @@ static inline u16 nbt_strlen(u8 const *restrict buf) { return be16toh(*(u16 *)(buf)); } +/* compares the string in `buf` to `matstr`. + * returns `=0` if equal, `>0` if buf is greater, `<0` if matstr is greater. */ +static int nbt_cmpstr(char const *restrict matstr, u8 const *restrict buf) { + u16 len = nbt_strlen(buf); + + // allocate and copy bytes + char str[len + 1]; + memcpy(str, buf + 2, len); + str[len] = '\0'; + + return strncmp(str, matstr, len); +} + int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len) { // first byte should be a compound tag