From fc13fb2ba5993d06d9d6ae5e80bc337aebbdc119 Mon Sep 17 00:00:00 2001 From: aqua Date: Sun, 8 Oct 2023 19:50:00 +0300 Subject: Use meson build system --- lib/libk/endian.h | 15 --------------- lib/libk/include/endian.h | 15 +++++++++++++++ lib/libk/include/stdio.h | 41 +++++++++++++++++++++++++++++++++++++++++ lib/libk/include/stdlib.h | 23 +++++++++++++++++++++++ lib/libk/include/string.h | 14 ++++++++++++++ lib/libk/meson.build | 41 +++++++++++++++++++++++++++++++++++++++++ lib/libk/stdio.h | 41 ----------------------------------------- lib/libk/stdlib.h | 23 ----------------------- lib/libk/string.h | 14 -------------- 9 files changed, 134 insertions(+), 93 deletions(-) delete mode 100644 lib/libk/endian.h create mode 100644 lib/libk/include/endian.h create mode 100644 lib/libk/include/stdio.h create mode 100644 lib/libk/include/stdlib.h create mode 100644 lib/libk/include/string.h create mode 100644 lib/libk/meson.build delete mode 100644 lib/libk/stdio.h delete mode 100644 lib/libk/stdlib.h delete mode 100644 lib/libk/string.h (limited to 'lib/libk') diff --git a/lib/libk/endian.h b/lib/libk/endian.h deleted file mode 100644 index 6aa2669..0000000 --- a/lib/libk/endian.h +++ /dev/null @@ -1,15 +0,0 @@ -/* spdx-license-identifier: ISC */ - -#pragma once - -#include - -/* These functions convert the byte encoding of integer values from host byte order to and from little-endian and - * big-endian byte order */ -uint16_t htole16(uint16_t host_16b); -uint32_t htole32(uint32_t host_32b); -uint64_t htole64(uint64_t host_64b); - -uint16_t htobe16(uint16_t host_16b); -uint32_t htobe32(uint32_t host_32b); -uint64_t htobe64(uint64_t host_64b); diff --git a/lib/libk/include/endian.h b/lib/libk/include/endian.h new file mode 100644 index 0000000..6aa2669 --- /dev/null +++ b/lib/libk/include/endian.h @@ -0,0 +1,15 @@ +/* spdx-license-identifier: ISC */ + +#pragma once + +#include + +/* These functions convert the byte encoding of integer values from host byte order to and from little-endian and + * big-endian byte order */ +uint16_t htole16(uint16_t host_16b); +uint32_t htole32(uint32_t host_32b); +uint64_t htole64(uint64_t host_64b); + +uint16_t htobe16(uint16_t host_16b); +uint32_t htobe32(uint32_t host_32b); +uint64_t htobe64(uint64_t host_64b); diff --git a/lib/libk/include/stdio.h b/lib/libk/include/stdio.h new file mode 100644 index 0000000..7a6e663 --- /dev/null +++ b/lib/libk/include/stdio.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +/** An object type used for streams */ +typedef struct FILE { + int id; + + /** Function that prints a character to the stream */ + void (*putc)(const struct FILE *, char); + + /** Function that prints a string to the stream */ + int (*puts)(const struct FILE *, const char *, int); + + /** Flush write buffers */ + void (*flush)(const struct FILE *); +} FILE; + +/** A FILE value corresponding to stdin, the keyboard buffer */ +extern FILE *stdin; +/** A FILE value corresponding to stdout, the display */ +extern FILE *stdout; +/** A FILE value corresponding to stderr, the uart */ +extern FILE *stderr; + +/** + * Write the formatted string to stdout + * Supports ``%s`` (string), ``%d`` (decimal), ``%u`` (unsigned), ``%x`` (hexadecimal) + * @return number of bytes written + */ +int printf(const char *__restrict__ format, ...); + +/** + * Write the formatted string to stream; see printf + */ +int fprintf(FILE *__restrict__ stream, const char *__restrict__ format, ...); + +/** + * Write the formatted string to stream; see printf + */ +int vfprintf(FILE *__restrict__ stream, const char *__restrict__ format, va_list ap); diff --git a/lib/libk/include/stdlib.h b/lib/libk/include/stdlib.h new file mode 100644 index 0000000..143c931 --- /dev/null +++ b/lib/libk/include/stdlib.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +/** + * Allocate size bytes and return a pointer to the allocated memory + */ +void *malloc(size_t size); + +/** + * Free the memory space pointed to by ptr + */ +void free(void *ptr); + +/** + * Fill the first n bytes of the memory area pointed to by s with the constant byte c. + */ +void *memset(void *s, int c, long unsigned n); + +/** + * Copy n bytes from memory area src to memory area dest. The memory areas must not overlap. + */ +void *memcpy(void *__restrict__ dest, const void *__restrict__ src, long unsigned n); diff --git a/lib/libk/include/string.h b/lib/libk/include/string.h new file mode 100644 index 0000000..45b05a5 --- /dev/null +++ b/lib/libk/include/string.h @@ -0,0 +1,14 @@ +#pragma once + +#define OCTAL 8 +#define DECIMAL 10 +#define HEX 16 + +/** + * Convert int into a string + */ +char *itoa(char *p, int x, unsigned base); +/** + * Convert unsigned int into a string + */ +char *utoa(char *p, unsigned x, unsigned base); diff --git a/lib/libk/meson.build b/lib/libk/meson.build new file mode 100644 index 0000000..669780b --- /dev/null +++ b/lib/libk/meson.build @@ -0,0 +1,41 @@ + +libk_srcs = files( + 'endian/little.c', + 'stdio/printf.c', 'stdio/fprintf.c', 'stdio/vfprintf.c', + 'stdlib/memcpy.c', 'stdlib/memset.c', 'stdlib/linked_list_allocator.c', + 'string/itoa.c') +libk_incl = include_directories('include') + +libk = declare_dependency( + link_with: static_library('k', libk_srcs, include_directories: libk_incl), + include_directories: libk_incl, +) + +# tests +test('endian little', + executable('test_endian_little', 'endian/test_endian_little.cc', + dependencies: [ gtest ], + native: true), + suite: 'libk' +) + +test('linked list allocator', + executable('test_linked_list_allocator', 'stdlib/test_linked_list_allocator.cc', + dependencies: [ gtest ], + native: true), + suite: 'libk' +) + +test('mem', + executable('test_mem', 'stdlib/test_mem.cc', + dependencies: [ gtest ], + native: true), + suite: 'libk' +) + +test('string', + executable('test_string', 'string/test_string.cc', + dependencies: [ gtest ], + native: true), + suite: 'libk' +) diff --git a/lib/libk/stdio.h b/lib/libk/stdio.h deleted file mode 100644 index 7a6e663..0000000 --- a/lib/libk/stdio.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -/** An object type used for streams */ -typedef struct FILE { - int id; - - /** Function that prints a character to the stream */ - void (*putc)(const struct FILE *, char); - - /** Function that prints a string to the stream */ - int (*puts)(const struct FILE *, const char *, int); - - /** Flush write buffers */ - void (*flush)(const struct FILE *); -} FILE; - -/** A FILE value corresponding to stdin, the keyboard buffer */ -extern FILE *stdin; -/** A FILE value corresponding to stdout, the display */ -extern FILE *stdout; -/** A FILE value corresponding to stderr, the uart */ -extern FILE *stderr; - -/** - * Write the formatted string to stdout - * Supports ``%s`` (string), ``%d`` (decimal), ``%u`` (unsigned), ``%x`` (hexadecimal) - * @return number of bytes written - */ -int printf(const char *__restrict__ format, ...); - -/** - * Write the formatted string to stream; see printf - */ -int fprintf(FILE *__restrict__ stream, const char *__restrict__ format, ...); - -/** - * Write the formatted string to stream; see printf - */ -int vfprintf(FILE *__restrict__ stream, const char *__restrict__ format, va_list ap); diff --git a/lib/libk/stdlib.h b/lib/libk/stdlib.h deleted file mode 100644 index 143c931..0000000 --- a/lib/libk/stdlib.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include - -/** - * Allocate size bytes and return a pointer to the allocated memory - */ -void *malloc(size_t size); - -/** - * Free the memory space pointed to by ptr - */ -void free(void *ptr); - -/** - * Fill the first n bytes of the memory area pointed to by s with the constant byte c. - */ -void *memset(void *s, int c, long unsigned n); - -/** - * Copy n bytes from memory area src to memory area dest. The memory areas must not overlap. - */ -void *memcpy(void *__restrict__ dest, const void *__restrict__ src, long unsigned n); diff --git a/lib/libk/string.h b/lib/libk/string.h deleted file mode 100644 index 45b05a5..0000000 --- a/lib/libk/string.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#define OCTAL 8 -#define DECIMAL 10 -#define HEX 16 - -/** - * Convert int into a string - */ -char *itoa(char *p, int x, unsigned base); -/** - * Convert unsigned int into a string - */ -char *utoa(char *p, unsigned x, unsigned base); -- cgit v1.2.1