Main: include/kernaux/generic_array.h: Added

This commit is contained in:
Alex Kotov 2022-06-16 23:18:32 +03:00
parent e99d2bc2d1
commit c8247eff14
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
6 changed files with 65 additions and 3 deletions

View File

@ -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

View File

@ -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**)

View File

@ -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

View File

@ -3,9 +3,9 @@
contain architecture-specific assembly functions.
*/
#include <kernaux/version.h>
#include <kernaux/assert.h>
#include <kernaux/generic_array.h>
#include <kernaux/version.h>
@comment_line_cmdline@#include <kernaux/cmdline.h>
@comment_line_console@#include <kernaux/console.h>

View File

@ -0,0 +1,28 @@
#ifndef KERNAUX_INCLUDED_GENERIC_ARRAY
#define KERNAUX_INCLUDED_GENERIC_ARRAY
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
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

32
src/generic_array.c Normal file
View File

@ -0,0 +1,32 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/generic_array.h>
#include <stddef.h>
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;
}