1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00

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 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 = libkernaux_la_LIBADD =
if ASM_I386 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*) * [Multiboot 2 (GRUB 2)](/include/kernaux/multiboot2.h) (*work in progress*)
* Stivale 2 (Limine) (*planned*) * Stivale 2 (Limine) (*planned*)
* Utilities * Utilities
* [Generic array](/include/kernaux/generic_array.h) (*work in progress*)
* [Measurement units utils](/include/kernaux/units.h) (*work in progress*) * [Measurement units utils](/include/kernaux/units.h) (*work in progress*)
* [Example: To human](/examples/units_human.c) * [Example: To human](/examples/units_human.c)
* [Memory map](/include/kernaux/memmap.h.in) (*non-breaking since* **0.4.0**) * [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/riscv64.h \
kernaux/arch/x86_64.h \ kernaux/arch/x86_64.h \
kernaux/assert.h \ kernaux/assert.h \
kernaux/generic_array.h \
kernaux/version.h kernaux/version.h
if ASM_I386 if ASM_I386

View file

@ -3,9 +3,9 @@
contain architecture-specific assembly functions. contain architecture-specific assembly functions.
*/ */
#include <kernaux/version.h>
#include <kernaux/assert.h> #include <kernaux/assert.h>
#include <kernaux/generic_array.h>
#include <kernaux/version.h>
@comment_line_cmdline@#include <kernaux/cmdline.h> @comment_line_cmdline@#include <kernaux/cmdline.h>
@comment_line_console@#include <kernaux/console.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;
}