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/include/endian.h | 15 +++++++++++++++ lib/libk/include/stdio.h | 41 +++++++++++++++++++++++++++++++++++++++++ lib/libk/include/stdlib.h | 23 +++++++++++++++++++++++ lib/libk/include/string.h | 14 ++++++++++++++ 4 files changed, 93 insertions(+) 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 (limited to 'lib/libk/include') 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); -- cgit v1.2.1