diff options
author | dzwdz | 2023-08-14 18:51:07 +0200 |
---|---|---|
committer | dzwdz | 2023-08-14 18:51:07 +0200 |
commit | 642b5fb0007b64c77d186fcb018d571152ee1d47 (patch) | |
tree | 1c466461f3602d306be309a053edae558ef2568e /src/libk/include/shared | |
parent | 8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff) |
reorganization: first steps
Diffstat (limited to 'src/libk/include/shared')
-rw-r--r-- | src/libk/include/shared/mem.h | 18 | ||||
-rw-r--r-- | src/libk/include/shared/printf.h | 6 | ||||
-rw-r--r-- | src/libk/include/shared/ring.h | 23 |
3 files changed, 47 insertions, 0 deletions
diff --git a/src/libk/include/shared/mem.h b/src/libk/include/shared/mem.h new file mode 100644 index 0000000..3597edf --- /dev/null +++ b/src/libk/include/shared/mem.h @@ -0,0 +1,18 @@ +#pragma once +#include <stdarg.h> +#include <stddef.h> + +/* note: (partially) tested in the userland tests */ + +void *memchr(const void *s, int c, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); + +void *memcpy(void *dest, const void *src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); + +int strcmp(const char *s1, const char *s2); +size_t strlen(const char *s); + +int snprintf(char *restrict str, size_t len, const char *restrict fmt, ...); +int vsnprintf(char *restrict str, size_t len, const char *restrict fmt, va_list ap); diff --git a/src/libk/include/shared/printf.h b/src/libk/include/shared/printf.h new file mode 100644 index 0000000..45fd358 --- /dev/null +++ b/src/libk/include/shared/printf.h @@ -0,0 +1,6 @@ +#pragma once +#include <stdarg.h> +#include <stddef.h> + +int __printf_internal(const char *fmt, va_list argp, + void (*back)(void*, const char*, size_t), void *back_arg); diff --git a/src/libk/include/shared/ring.h b/src/libk/include/shared/ring.h new file mode 100644 index 0000000..dbaf331 --- /dev/null +++ b/src/libk/include/shared/ring.h @@ -0,0 +1,23 @@ +#pragma once +#include <stddef.h> +#include <stdint.h> + +typedef struct { + char *buf; + size_t capacity; + size_t _head, _tail; +} ring_t; + +/** Returns amount of bytes stored in the buffer. */ +size_t ring_used(ring_t*); +/** Returns amount of space left in the buffer. */ +size_t ring_avail(ring_t*); + +void ring_put(ring_t*, const void*, size_t); +void ring_put1b(ring_t*, uint8_t); + +size_t ring_get(ring_t*, void*, size_t); + +/** Consumes up to `len` bytes, and returns a pointer to the buffer where it's stored. + * Not thread-safe. */ +void* ring_contig(ring_t*, size_t *len); |