initial commit

This commit is contained in:
pantonshire committed 2025-12-19 10:22:35 +00:00
commit 12f4496883
9 files changed
+300

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include <stdint.h>
struct client_conf {
uint16_t port;
};
int client(const struct client_conf *conf);
+3
View File
@@ -0,0 +1,3 @@
#pragma once
#define DEFAULT_PORT 11333
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include <stdint.h>
struct server_conf {
uint16_t port;
};
int server(const struct server_conf *conf);
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include <stdbool.h>
#include <string.h>
#define SV_LIT(S) (S "LITERAL_CHECK", (str_view_t) { S, sizeof(S) - 1 })
#define SV_NULL ((str_view_t) { NULL, 0 })
typedef struct {
const char *ptr;
size_t len;
} str_view_t;
static inline str_view_t sv_from_parts(const char *ptr, size_t len) {
return (str_view_t) { ptr, len };
}
static inline str_view_t sv_from_cstr(const char *ptr, size_t maxlen) {
size_t len = strnlen(ptr, maxlen);
return sv_from_parts(ptr, len);
}
static inline str_view_t sv_from_cstr_unbounded(const char *ptr) {
size_t len = strlen(ptr);
return sv_from_parts(ptr, len);
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <stdio.h>
#define LOG_ERR(FMT_STR, ...) do { \
fprintf(stderr, FMT_STR "\n" __VA_OPT__(,) __VA_ARGS__); \
} while (0)
#define FAIL_WITH(RET, FMT_STR, ...) do { \
LOG_ERR(FMT_STR, __VA_ARGS__); \
return (RET); \
} while (0)
#define FAIL(FMT_STR, ...) FAIL_WITH(-1, FMT_STR, __VA_ARGS__)