main.c: remake cli tool, helper.c: add strcmp, use builtins in some paths

Co-authored-by: tema5002 <tema5002@tuta.io>
Reviewed-on: #4
Co-committed-by: tema5002 <tema5002@tuta.io>
This commit was merged in pull request #4.
This commit is contained in:
2026-05-26 18:37:00 +02:00
committed by Blendi
parent 4fbb006072
commit 8e8b01b7d9
5 changed files with 248 additions and 61 deletions

View File

@@ -2,6 +2,11 @@
#include "types.h"
int noom_startswith(const char* str, const char* compare) {
#ifdef __has_builtin
#if __has_builtin(__builtin_strncmp)
return __builtin_strncmp(compare, str, noom_strlen(compare)) == 0;
#endif
#endif
noom_uint_t i = 0;
while (1) {
if (compare[i] == '\0') return 1; // we did it
@@ -21,13 +26,27 @@ int noom_streql(const char* stra, noom_uint_t lena, const char* strb, noom_uint_
return 1;
}
noom_uint_t noom_strlen(const char *s)
{
noom_uint_t noom_strlen(const char *s) {
#ifdef __has_builtin
#if __has_builtin(__builtin_strlen)
return __builtin_strlen(s);
#endif
#endif
const char *a = s;
while (*s) s++;
return s - a;
}
int noom_strcmp(const char *a, const char *b) {
#ifdef __has_builtin
#if __has_builtin(__builtin_strcmp)
return __builtin_strcmp(a, b);
#endif
#endif
for (; *a && *a == *b; a++, b++);
return *(const unsigned char*)a - *(const unsigned char*)b;
}
void noom_safe_strcpy(char* buffer, noom_uint_t* pos, noom_uint_t buffer_size, const char* src) {
while (*src && *pos < buffer_size - 1) {
buffer[(*pos)++] = *src++;