diff --git a/Makefile.am b/Makefile.am index 1df1659..1abb1e2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,7 @@ libc/libc.la: lib_LTLIBRARIES = libkernaux.la -libkernaux_la_SOURCES = src/libc.h src/assert.c +libkernaux_la_SOURCES = src/libc.h src/assert.c src/generic_array.c libkernaux_la_LIBADD = if ASM_I386 diff --git a/README.md b/README.md index 057c61e..772630c 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ zero). Work-in-progress APIs can change at any time. * [Multiboot 2 (GRUB 2)](/include/kernaux/multiboot2.h) (*work in progress*) * Stivale 2 (Limine) (*planned*) * Utilities + * [Generic array](/include/kernaux/generic_array.h) (*work in progress*) * [Measurement units utils](/include/kernaux/units.h) (*work in progress*) * [Example: To human](/examples/units_human.c) * [Memory map](/include/kernaux/memmap.h.in) (*non-breaking since* **0.4.0**) diff --git a/include/Makefile.am b/include/Makefile.am index ca79577..b8285b9 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -4,6 +4,7 @@ nobase_include_HEADERS = \ kernaux/arch/riscv64.h \ kernaux/arch/x86_64.h \ kernaux/assert.h \ + kernaux/generic_array.h \ kernaux/version.h if ASM_I386 diff --git a/include/kernaux.h.in b/include/kernaux.h.in index 456d8f0..44050ad 100644 --- a/include/kernaux.h.in +++ b/include/kernaux.h.in @@ -3,9 +3,9 @@ contain architecture-specific assembly functions. */ -#include - #include +#include +#include @comment_line_cmdline@#include @comment_line_console@#include diff --git a/include/kernaux/generic_array.h b/include/kernaux/generic_array.h new file mode 100644 index 0000000..1aa40ac --- /dev/null +++ b/include/kernaux/generic_array.h @@ -0,0 +1,28 @@ +#ifndef KERNAUX_INCLUDED_GENERIC_ARRAY +#define KERNAUX_INCLUDED_GENERIC_ARRAY + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef struct KernAux_GenericArray { + size_t memory_size; + void *ptr; +} *KernAux_GenericArray; + +struct KernAux_GenericArray +KernAux_GenericArray_create(size_t memory_size, void *ptr); + +void KernAux_GenericArray_init( + KernAux_GenericArray generic_array, + size_t memory_size, + void *ptr +); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/generic_array.c b/src/generic_array.c new file mode 100644 index 0000000..eb49f27 --- /dev/null +++ b/src/generic_array.c @@ -0,0 +1,32 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +struct KernAux_GenericArray +KernAux_GenericArray_create(const size_t memory_size, void *const ptr) +{ + KERNAUX_ASSERT(memory_size); + KERNAUX_ASSERT(ptr); + + struct KernAux_GenericArray generic_array; + KernAux_GenericArray_init(&generic_array, memory_size, ptr); + return generic_array; +} + +void KernAux_GenericArray_init( + const KernAux_GenericArray generic_array, + const size_t memory_size, + void *const ptr +) { + KERNAUX_ASSERT(generic_array); + KERNAUX_ASSERT(memory_size); + KERNAUX_ASSERT(ptr); + + generic_array->memory_size = memory_size; + generic_array->ptr = ptr; +}