compiler: basic code in place + all: rename streql to memeq

Reviewed-on: #5
Co-authored-by: tema5002 <tema5002@tuta.io>
Co-committed-by: tema5002 <tema5002@tuta.io>
This commit was merged in pull request #5.
This commit is contained in:
2026-06-08 22:13:05 +02:00
committed by Blendi
parent be75ccd6f8
commit 5ff0594791
10 changed files with 473 additions and 154 deletions

View File

@@ -1,4 +1,5 @@
#include "helper.h"
#include "types.h"
int noom_startswith(const char* str, const char* compare) {
@@ -16,7 +17,7 @@ int noom_startswith(const char* str, const char* compare) {
return 0; // unreachable but whatevs
}
int noom_streql(const char* stra, noom_uint_t lena, const char* strb, noom_uint_t lenb) {
int noom_memeq(const char* stra, noom_uint_t lena, const char* strb, noom_uint_t lenb) {
if (lena != lenb) return 0;
for (noom_uint_t i = 0; i < lena; i++) {
@@ -53,6 +54,29 @@ void noom_safe_strcpy(char* buffer, noom_uint_t* pos, noom_uint_t buffer_size, c
}
}
char *noom_strndup(const char *s, const noom_uint_t len) {
char *whar = noom_alloc(len + 1);
if (whar == 0) return 0;
noom_memcpy(whar, s, len);
whar[len] = '\0';
return whar;
}
void noom_memcpy(void* dst, const void* src, noom_uint_t n) {
#ifdef __has_builtin
#if __has_builtin(__builtin_memcpy)
__builtin_memcpy(dst, src, n);
return;
#endif
#endif
unsigned char *d = dst;
const unsigned char *s = src;
while (n--) {
*d++ = *s++;
}
}
#include <stdlib.h> // TODO: remove
void* noom_alloc(noom_uint_t size) {