Compare commits

..

2 Commits

Author SHA1 Message Date
b1950e282a remove nbt_arrlen function 2025-07-24 14:53:57 +02:00
875f7666cc move nbt_strlen to nbt.h, and rename to nbt_namelen 2025-07-24 14:53:39 +02:00
3 changed files with 22 additions and 6 deletions

View File

@@ -43,7 +43,11 @@ jobs:
git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT" git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT"
"$VCPKG_ROOT/bootstrap-vcpkg.sh" "$VCPKG_ROOT/bootstrap-vcpkg.sh"
"$VCPKG_ROOT/vcpkg" install $DEPS_VCPKG "$VCPKG_ROOT/vcpkg" install $DEPS_VCPKG
- name: compilation (using bulk compilation) # compilation (using bulk compilation)
run: make all CALL=compile -j - run: make all CALL=compile -j || echo "JOB_FAILED=1" >>"$GITHUB_ENV"
- name: unit tests (using bulk flags) # executing unit tests (using bulk flags)
run: make all CALL=run DEBUG=test -j - run: make all CALL=run DEBUG=test -j || echo "JOB_FAILED=1" >>"$GITHUB_ENV"
# exit if any errors occurred
- name: exit on errors
run: |
[ "$JOB_FAILED" != "1" ]

View File

@@ -13,6 +13,19 @@ const u8 *nbt_nexttag(const u8 *restrict buf, u16 naml) {
return buf + naml + len + 3; return buf + naml + len + 3;
} }
/* 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(const char *restrict matstr, const u8 *restrict buf) {
u16 len = be16toh(*(u16 *)buf);
// allocate and copy bytes
char str[len + 1];
memcpy(str, buf + 2, len);
str[len] = '\0';
return strncmp(str, matstr, len);
}
// TODO: not actually doing anything // TODO: not actually doing anything
/* readies the output data for export, returns the new buffer position, or `NULL` upon an error (may be out of bounds) */ /* readies the output data for export, returns the new buffer position, or `NULL` upon an error (may be out of bounds) */
static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) { static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) {

View File

@@ -7,7 +7,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "../util/atrb.h" #include "../util/atrb.h"
#include "../util/compat/endian.h"
#include "../util/types.h" #include "../util/types.h"
/* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload. /* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload.
@@ -49,7 +48,7 @@ atrb_pure atrb_nonnull(1) static inline u16 nbt_namelen(const u8 *restrict buf)
/* returns the (expected) pointer of the tag following this one. /* returns the (expected) pointer of the tag following this one.
* `NULL` is returned if anything went wrong. */ * `NULL` is returned if anything went wrong. */
atrb_pure atrb_nonnull(1) const u8 *nbt_nexttag(const u8 *restrict buf, u16 naml); atrb_pure atrb((nonnull(1))) const u8 *nbt_nexttag(const u8 *restrict buf, u16 naml);
/* checks whether the tag is a primitive data tag. (not recommended for filtering tags, use a `switch`) /* checks whether the tag is a primitive data tag. (not recommended for filtering tags, use a `switch`)
* returns a boolean value. */ * returns a boolean value. */