add str util

This commit is contained in:
2024-05-12 13:00:49 +09:00
parent f3669e8b14
commit aef7b107e6
2 changed files with 21 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ target_sources(nf7util
malloc.h
refcnt.h
signal.h
str.h
)
target_tests(nf7util
array.test.c

20
util/str.h Normal file
View File

@@ -0,0 +1,20 @@
// No copyright
#pragma once
#include <stdint.h>
#include <string.h>
static inline bool nf7util_str_equal_str(
const uint8_t* a, uint64_t alen, const uint8_t* b, uint64_t blen) {
return
alen == blen &&
0 == strncmp((const char*) a, (const char*) b, alen);
}
static inline bool nf7util_str_equal_cstr(
const uint8_t* a, uint64_t alen, const uint8_t* b) {
return
alen == strlen((const char*) b) &&
0 == strncmp((const char*) a, (const char*) b, alen);
}