aboutsummaryrefslogtreecommitdiff
path: root/lib/libk/include
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libk/include')
-rw-r--r--lib/libk/include/endian.h15
-rw-r--r--lib/libk/include/stdio.h41
-rw-r--r--lib/libk/include/stdlib.h23
-rw-r--r--lib/libk/include/string.h14
4 files changed, 93 insertions, 0 deletions
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 <stdint.h>
+
+/* 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 <stdarg.h>
+
+/** 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 <stddef.h>
+
+/**
+ * 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);