create a custom definition for size_t and ssize_t, which is ssize and usize, for conveinience.

This commit is contained in:
2025-09-18 10:39:57 +02:00
parent 1e24a4ee92
commit 6eb7d126da
10 changed files with 42 additions and 35 deletions

View File

@@ -1,5 +1,6 @@
/* Copyright (c) 2025 Quinn
* Licensed under the MIT Licence. See LICENSE for details */
#include <stdint.h>
#include <stdio.h>
#include "test.h"
@@ -13,6 +14,7 @@ int main(void) {
assert_true(sizeof(u64) == 8);
assert_true(sizeof(f32) == 4);
assert_true(sizeof(f64) == 8);
assert_true(sizeof(size_t) == sizeof(intptr_t));
test_conf_procbuf("key=val", "key", "val", 0);
test_conf_procbuf("sometxt", "sometxt", "", CONF_ESYNTAX);
test_conf_procbuf("# comment", "", "", CONF_ENODAT);

View File

@@ -6,10 +6,11 @@
#include <string.h>
#include "../src/util/conf.h"
#include "../src/util/intdef.h"
#include "test.h"
void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return) {
size_t len = strlen(buf) + 1;
usize len = strlen(buf) + 1;
char k[len], v[len];
*k = '\0', *v = '\0';
(void)(assert_true(conf_procbuf(buf, k, v, len) == expect_return) &&
@@ -17,9 +18,9 @@ void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key
assert_true(!strcmp(v, expect_val)));
}
void test_conf_matchopt(struct conf_entry *opts, size_t optc, const char *restrict key, int expect_index) {
size_t idx = opts - conf_matchopt(opts, optc, key);
idx = (ssize_t)idx < 0 ? -idx : idx;
void test_conf_matchopt(struct conf_entry *opts, usize optc, const char *restrict key, int expect_index) {
usize idx = opts - conf_matchopt(opts, optc, key);
idx = (ssize)idx < 0 ? -idx : idx;
int i = idx < optc ? (int)idx : -1;
assert_true(i == expect_index);
}

View File

@@ -6,7 +6,7 @@
#include "../src/util/intdef.h"
void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return);
void test_conf_matchopt(struct conf_entry *restrict opts, size_t optc, const char *restrict key, int expect_index);
void test_conf_matchopt(struct conf_entry *restrict opts, usize optc, const char *restrict key, int expect_index);
void test_conf_procval_int(const char *val, u64 expect_value, int type);
void test_conf_procval_f32(const char *val, f32 expect_value);
void test_conf_procval_fstr(const char *val, u64 expect_value, int type);