aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/lib
diff options
context:
space:
mode:
authorMarvin Borner2020-05-06 19:04:05 +0200
committerMarvin Borner2020-05-06 19:04:05 +0200
commitd94ffac4a584dc7a4f6f2ec567b8caab05ce9253 (patch)
tree559cd596a0a407d4b40c1d12d3c6a0686494da16 /src/kernel/lib
parent1a8563a05608b5b5e27eada44cf4790926001c68 (diff)
New build parameters and shared includes
This changes many files but I've just applied some replace commands.. So - nothing special!
Diffstat (limited to 'src/kernel/lib')
-rw-r--r--src/kernel/lib/data.h6
-rw-r--r--src/kernel/lib/data/list.c12
-rw-r--r--src/kernel/lib/data/tree.c4
-rw-r--r--src/kernel/lib/lib.h10
-rw-r--r--src/kernel/lib/memory.c28
-rw-r--r--src/kernel/lib/stdio/debug.c14
-rw-r--r--src/kernel/lib/stdio/printf.c2
-rw-r--r--src/kernel/lib/stdio/putch.c2
-rw-r--r--src/kernel/lib/stdio/vprintf.c14
-rw-r--r--src/kernel/lib/stdlib.h4
-rw-r--r--src/kernel/lib/stdlib/atoi.c10
-rw-r--r--src/kernel/lib/stdlib/htoa.c6
-rw-r--r--src/kernel/lib/stdlib/htoi.c8
-rw-r--r--src/kernel/lib/stdlib/itoa.c14
-rw-r--r--src/kernel/lib/string.h3
-rw-r--r--src/kernel/lib/string/strcat.c8
-rw-r--r--src/kernel/lib/string/strcati.c6
-rw-r--r--src/kernel/lib/string/strcmp.c4
-rw-r--r--src/kernel/lib/string/strcpy.c6
-rw-r--r--src/kernel/lib/string/strdisp.c4
-rw-r--r--src/kernel/lib/string/strdup.c6
-rw-r--r--src/kernel/lib/string/strinv.c4
-rw-r--r--src/kernel/lib/string/strlen.c6
-rw-r--r--src/kernel/lib/string/strstr.c4
24 files changed, 93 insertions, 92 deletions
diff --git a/src/kernel/lib/data.h b/src/kernel/lib/data.h
index d0eaaf5..709ca6f 100644
--- a/src/kernel/lib/data.h
+++ b/src/kernel/lib/data.h
@@ -14,14 +14,14 @@ struct list_node {
struct list {
struct list_node *head;
struct list_node *tail;
- uint32_t size;
+ u32 size;
};
#define foreach(t, list) for (struct list_node *t = list->head; t != NULL; t = t->next)
struct list *list_create();
-uint32_t list_size(struct list *list);
+u32 list_size(struct list *list);
struct list_node *list_insert_front(struct list *list, void *val);
@@ -55,7 +55,7 @@ struct list_node *list_get_node_by_index(struct list *list, int index);
void *list_remove_by_index(struct list *list, int index);
-struct list *str_split(const char *str, const char *delim, uint32_t *numtokens);
+struct list *str_split(const char *str, const char *delim, u32 *numtokens);
char *list_to_str(struct list *list, const char *delim);
// Tree
diff --git a/src/kernel/lib/data/list.c b/src/kernel/lib/data/list.c
index 788b4ab..41f812f 100644
--- a/src/kernel/lib/data/list.c
+++ b/src/kernel/lib/data/list.c
@@ -1,9 +1,9 @@
#include <stdint.h>
#include <stddef.h>
-#include <kernel/lib/lib.h>
-#include <kernel/lib/stdlib.h>
-#include <kernel/lib/data.h>
-#include <kernel/memory/alloc.h>
+#include <lib/lib.h>
+#include <lib/stdlib.h>
+#include <lib/data.h>
+#include <memory/alloc.h>
struct list *list_create()
{
@@ -11,7 +11,7 @@ struct list *list_create()
return list;
}
-uint32_t list_size(struct list *list)
+u32 list_size(struct list *list)
{
if (!list)
return 0;
@@ -182,7 +182,7 @@ void listnode_destroy(struct list_node *node)
// Conversion
-struct list *str_split(const char *str, const char *delim, uint32_t *numtokens)
+struct list *str_split(const char *str, const char *delim, u32 *numtokens)
{
struct list *ret_list = list_create();
char *s = strdup(str);
diff --git a/src/kernel/lib/data/tree.c b/src/kernel/lib/data/tree.c
index 514e2cd..2726a11 100644
--- a/src/kernel/lib/data/tree.c
+++ b/src/kernel/lib/data/tree.c
@@ -1,6 +1,6 @@
#include <stdint.h>
-#include <kernel/lib/data.h>
-#include <kernel/memory/alloc.h>
+#include <lib/data.h>
+#include <memory/alloc.h>
struct tree *tree_create()
{
diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h
index b08904f..4308af4 100644
--- a/src/kernel/lib/lib.h
+++ b/src/kernel/lib/lib.h
@@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
-#include <kernel/multiboot.h>
+#include <multiboot.h>
/**
* Copy n data from src to dest
@@ -12,7 +12,7 @@
* @param count The number of bytes to be copied (src)
* @return The modified dest pointer
*/
-void *memcpy(void *dest, const void *src, size_t count);
+void *memcpy(void *dest, const void *src, u32 count);
/**
* Replace n bytes of dest by val
@@ -21,7 +21,7 @@ void *memcpy(void *dest, const void *src, size_t count);
* @param count The number of times val should replace dest entry
* @return The modified dest pointer
*/
-void *memset(void *dest, char val, size_t count);
+void *memset(void *dest, char val, u32 count);
/**
* Compare the first n bytes of a and b
@@ -30,7 +30,7 @@ void *memset(void *dest, char val, size_t count);
* @param size The number of bytes to be compared
* @return -1 if a < b, 0 if a = b and 1 if a > b
*/
-int memcmp(const void *a_ptr, const void *b_ptr, size_t size);
+int memcmp(const void *a_ptr, const void *b_ptr, u32 size);
void memory_info_init(struct multiboot_tag_basic_meminfo *tag);
@@ -38,6 +38,6 @@ void memory_mmap_init(struct multiboot_tag_mmap *tag);
void memory_print();
-uint32_t memory_get_all();
+u32 memory_get_all();
#endif \ No newline at end of file
diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c
index bda3c1b..d990e6b 100644
--- a/src/kernel/lib/memory.c
+++ b/src/kernel/lib/memory.c
@@ -1,11 +1,11 @@
#include <stddef.h>
#include <stdint.h>
-#include <kernel/system.h>
-#include <kernel/lib/stdio.h>
-#include <kernel/memory/paging.h>
-#include <kernel/multiboot.h>
+#include <system.h>
+#include <lib/stdio.h>
+#include <memory/paging.h>
+#include <multiboot.h>
-void *memcpy(void *dest, const void *src, size_t count)
+void *memcpy(void *dest, const void *src, u32 count)
{
const char *sp = (const char *)src;
char *dp = (char *)dest;
@@ -14,7 +14,7 @@ void *memcpy(void *dest, const void *src, size_t count)
return dest;
}
-void *memset(void *dest, char val, size_t count)
+void *memset(void *dest, char val, u32 count)
{
char *temp = (char *)dest;
for (; count != 0; count--)
@@ -22,11 +22,11 @@ void *memset(void *dest, char val, size_t count)
return dest;
}
-int memcmp(const void *a_ptr, const void *b_ptr, size_t size)
+int memcmp(const void *a_ptr, const void *b_ptr, u32 size)
{
const unsigned char *a = (const unsigned char *)a_ptr;
const unsigned char *b = (const unsigned char *)b_ptr;
- for (size_t i = 0; i < size; i++) {
+ for (u32 i = 0; i < size; i++) {
if (a[i] < b[i])
return -1;
else if (b[i] < a[i])
@@ -35,10 +35,10 @@ int memcmp(const void *a_ptr, const void *b_ptr, size_t size)
return 0;
}
-uint32_t total = 0;
+u32 total = 0;
struct multiboot_tag_basic_meminfo *meminfo = NULL;
-uint32_t memory_get_all()
+u32 memory_get_all()
{
if (total != 0) {
return total;
@@ -50,7 +50,7 @@ uint32_t memory_get_all()
}
}
-uint32_t memory_get_free()
+u32 memory_get_free()
{
return memory_get_all() /*- paging_get_used_pages() * 4*/;
}
@@ -73,12 +73,12 @@ void memory_info_init(struct multiboot_tag_basic_meminfo *tag)
void memory_mmap_init(struct multiboot_tag_mmap *tag)
{
- uint32_t sum = 0;
+ u32 sum = 0;
struct multiboot_mmap_entry *mmap;
for (mmap = ((struct multiboot_tag_mmap *)tag)->entries;
- (multiboot_uint8_t *)mmap < (multiboot_uint8_t *)tag + tag->size;
- mmap = (multiboot_memory_map_t *)((uint32_t)mmap +
+ (multiboot_u8 *)mmap < (multiboot_u8 *)tag + tag->size;
+ mmap = (multiboot_memory_map_t *)((u32)mmap +
((struct multiboot_tag_mmap *)tag)->entry_size)) {
if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) {
debug("Found free memory");
diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c
index 0942d49..a96d73a 100644
--- a/src/kernel/lib/stdio/debug.c
+++ b/src/kernel/lib/stdio/debug.c
@@ -1,19 +1,19 @@
#include <stdarg.h>
#include <stdint.h>
-#include <kernel/lib/string.h>
-#include <kernel/lib/stdlib.h>
-#include <kernel/io/io.h>
-#include <kernel/memory/alloc.h>
+#include <lib/string.h>
+#include <lib/stdlib.h>
+#include <io/io.h>
+#include <memory/alloc.h>
void serial_print(const char *data)
{
- for (size_t i = 0; i < strlen(data); i++)
+ for (u32 i = 0; i < strlen(data); i++)
serial_put(data[i]);
}
void serial_vprintf(const char *fmt, va_list args)
{
- uint8_t readyToFormat = 0;
+ u8 readyToFormat = 0;
char buff = 0;
@@ -31,7 +31,7 @@ void serial_vprintf(const char *fmt, va_list args)
serial_print(str);
readyToFormat = 0;
} else if (buff == 'x') {
- char *p = htoa((uint32_t)va_arg(args, int));
+ char *p = htoa((u32)va_arg(args, int));
serial_print(p);
kfree(p);
readyToFormat = 0;
diff --git a/src/kernel/lib/stdio/printf.c b/src/kernel/lib/stdio/printf.c
index 5c3eb8e..cc65463 100644
--- a/src/kernel/lib/stdio/printf.c
+++ b/src/kernel/lib/stdio/printf.c
@@ -1,5 +1,5 @@
#include <stdarg.h>
-#include <kernel/lib/stdio.h>
+#include <lib/stdio.h>
void printf(const char *fmt, ...)
{
diff --git a/src/kernel/lib/stdio/putch.c b/src/kernel/lib/stdio/putch.c
index f7e0248..2689ac7 100644
--- a/src/kernel/lib/stdio/putch.c
+++ b/src/kernel/lib/stdio/putch.c
@@ -1,4 +1,4 @@
-#include <kernel/graphics/vesa.h>
+#include <graphics/vesa.h>
void putch(char c)
{
diff --git a/src/kernel/lib/stdio/vprintf.c b/src/kernel/lib/stdio/vprintf.c
index 2431a48..15d210a 100644
--- a/src/kernel/lib/stdio/vprintf.c
+++ b/src/kernel/lib/stdio/vprintf.c
@@ -1,19 +1,19 @@
#include <stdarg.h>
#include <stdint.h>
-#include <kernel/lib/stdio.h>
-#include <kernel/lib/string.h>
-#include <kernel/lib/stdlib.h>
-#include <kernel/memory/alloc.h>
+#include <lib/stdio.h>
+#include <lib/string.h>
+#include <lib/stdlib.h>
+#include <memory/alloc.h>
void _puts(const char *data)
{
- for (size_t i = 0; i < strlen(data); i++)
+ for (u32 i = 0; i < strlen(data); i++)
putch(data[i]);
}
void vprintf(const char *fmt, va_list args)
{
- uint8_t readyToFormat = 0;
+ u8 readyToFormat = 0;
char buff = 0;
@@ -31,7 +31,7 @@ void vprintf(const char *fmt, va_list args)
_puts(str);
readyToFormat = 0;
} else if (buff == 'x') {
- char *p = htoa((uint32_t)va_arg(args, int));
+ char *p = htoa((u32)va_arg(args, int));
_puts(p);
kfree(p);
readyToFormat = 0;
diff --git a/src/kernel/lib/stdlib.h b/src/kernel/lib/stdlib.h
index 18d933d..62bd51c 100644
--- a/src/kernel/lib/stdlib.h
+++ b/src/kernel/lib/stdlib.h
@@ -5,7 +5,7 @@
#ifndef MELVIX_STRING_H
-#include <kernel/lib/string.h>
+#include <lib/string.h>
#endif
@@ -13,7 +13,7 @@ char *itoa(int n);
int atoi(char *str);
-char *htoa(uint32_t n);
+char *htoa(u32 n);
int htoi(char *str);
diff --git a/src/kernel/lib/stdlib/atoi.c b/src/kernel/lib/stdlib/atoi.c
index 2d58d84..cd855ab 100644
--- a/src/kernel/lib/stdlib/atoi.c
+++ b/src/kernel/lib/stdlib/atoi.c
@@ -1,19 +1,19 @@
-#include <kernel/lib/math.h>
+#include <lib/math.h>
#include <stddef.h>
#include <stdint.h>
-#include <kernel/lib/string.h>
+#include <lib/string.h>
int atoi(char *str)
{
- size_t s_str = strlen(str);
+ u32 s_str = strlen(str);
if (!s_str)
return 0;
- uint8_t negative = 0;
+ u8 negative = 0;
if (str[0] == '-')
negative = 1;
- size_t i = 0;
+ u32 i = 0;
if (negative)
i++;
diff --git a/src/kernel/lib/stdlib/htoa.c b/src/kernel/lib/stdlib/htoa.c
index ee639ec..7a535dd 100644
--- a/src/kernel/lib/stdlib/htoa.c
+++ b/src/kernel/lib/stdlib/htoa.c
@@ -1,10 +1,10 @@
#include <stdint.h>
-#include <kernel/lib/string.h>
-#include <kernel/memory/alloc.h>
+#include <lib/string.h>
+#include <memory/alloc.h>
static const char HTOA_TABLE[] = "0123456789ABCDEF";
-char *htoa(uint32_t n)
+char *htoa(u32 n)
{
char *ret = (char *)kmalloc(10);
diff --git a/src/kernel/lib/stdlib/htoi.c b/src/kernel/lib/stdlib/htoi.c
index dcc4b63..7d05239 100644
--- a/src/kernel/lib/stdlib/htoi.c
+++ b/src/kernel/lib/stdlib/htoi.c
@@ -1,12 +1,12 @@
-#include <kernel/lib/math.h>
+#include <lib/math.h>
#include <stddef.h>
-#include <kernel/lib/string.h>
+#include <lib/string.h>
int htoi(char *str)
{
- size_t s_str = strlen(str);
+ u32 s_str = strlen(str);
- size_t i = 0;
+ u32 i = 0;
int ret = 0;
for (; i < s_str; i++) {
char c = str[i];
diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c
index 5bb3359..165e260 100644
--- a/src/kernel/lib/stdlib/itoa.c
+++ b/src/kernel/lib/stdlib/itoa.c
@@ -1,8 +1,8 @@
-#include <kernel/lib/math.h>
+#include <lib/math.h>
#include <stdint.h>
-#include <kernel/lib/string.h>
-#include <kernel/memory/alloc.h>
-#include <kernel/memory/paging.h>
+#include <lib/string.h>
+#include <memory/alloc.h>
+#include <memory/paging.h>
static const char ITOA_TABLE[] = "0123456789";
@@ -14,7 +14,7 @@ char *itoa(int n)
ret[1] = 0;
return ret;
}
- uint8_t negative = (uint8_t)(n < 0);
+ u8 negative = (u8)(n < 0);
if (negative)
n *= -1;
@@ -22,7 +22,7 @@ char *itoa(int n)
for (sz = 0; n % pow(10, sz) != n; sz++) {
}
- char *ret = (char *)kmalloc((uint32_t)(sz + 1));
+ char *ret = (char *)kmalloc((u32)(sz + 1));
for (int i = 0; i < sz; i++) {
int digit = (n % pow(10, i + 1)) / pow(10, i);
@@ -31,7 +31,7 @@ char *itoa(int n)
ret[sz] = 0;
if (negative) {
- char *aux = (char *)kmalloc((uint32_t)(sz + 2));
+ char *aux = (char *)kmalloc((u32)(sz + 2));
strcpy(aux, ret);
aux[sz] = '-';
aux[sz + 1] = 0;
diff --git a/src/kernel/lib/string.h b/src/kernel/lib/string.h
index 3a8dc07..bd412d7 100644
--- a/src/kernel/lib/string.h
+++ b/src/kernel/lib/string.h
@@ -1,9 +1,10 @@
#ifndef MELVIX_STRING_H
#define MELVIX_STRING_H
+#include <stdint.h>
#include <stddef.h>
-size_t strlen(const char *str);
+u32 strlen(const char *str);
void strcpy(char *dest, const char *orig);
diff --git a/src/kernel/lib/string/strcat.c b/src/kernel/lib/string/strcat.c
index 4328f87..3ae8ea0 100644
--- a/src/kernel/lib/string/strcat.c
+++ b/src/kernel/lib/string/strcat.c
@@ -1,11 +1,11 @@
-#include <kernel/lib/string.h>
+#include <lib/string.h>
void strcat(char *dest, const char *orig)
{
- size_t s_dest = strlen(dest);
- size_t s_orig = strlen(orig);
+ u32 s_dest = strlen(dest);
+ u32 s_orig = strlen(orig);
- for (size_t i = 0; i < s_orig; i++)
+ for (u32 i = 0; i < s_orig; i++)
dest[s_dest + i] = orig[i];
dest[s_dest + s_orig] = 0;
} \ No newline at end of file
diff --git a/src/kernel/lib/string/strcati.c b/src/kernel/lib/string/strcati.c
index 5dab283..2fda46c 100644
--- a/src/kernel/lib/string/strcati.c
+++ b/src/kernel/lib/string/strcati.c
@@ -1,9 +1,9 @@
-#include <kernel/lib/string.h>
+#include <lib/string.h>
void strcati(char *dest, const char *orig)
{
- size_t s_orig = strlen(orig);
+ u32 s_orig = strlen(orig);
strdisp(dest, (int)s_orig);
- for (size_t i = 0; i < s_orig; i++)
+ for (u32 i = 0; i < s_orig; i++)
dest[i] = orig[i];
} \ No newline at end of file
diff --git a/src/kernel/lib/string/strcmp.c b/src/kernel/lib/string/strcmp.c
index 89f77a0..7a273ac 100644
--- a/src/kernel/lib/string/strcmp.c
+++ b/src/kernel/lib/string/strcmp.c
@@ -1,11 +1,11 @@
-#include <kernel/lib/string.h>
+#include <lib/string.h>
char strcmp(const char *a, const char *b)
{
if (strlen(a) != strlen(b))
return 1;
- for (size_t i = 0; i < strlen(a); i++)
+ for (u32 i = 0; i < strlen(a); i++)
if (a[i] != b[i])
return 1;
diff --git a/src/kernel/lib/string/strcpy.c b/src/kernel/lib/string/strcpy.c
index 6117e7c..5d7f194 100644
--- a/src/kernel/lib/string/strcpy.c
+++ b/src/kernel/lib/string/strcpy.c
@@ -1,10 +1,10 @@
-#include <kernel/lib/string.h>
+#include <lib/string.h>
void strcpy(char *dest, const char *orig)
{
- size_t s_orig = strlen(orig);
+ u32 s_orig = strlen(orig);
- for (size_t i = 0; i < s_orig; i++)
+ for (u32 i = 0; i < s_orig; i++)
dest[i] = orig[i];
dest[s_orig] = 0;
} \ No newline at end of file
diff --git a/src/kernel/lib/string/strdisp.c b/src/kernel/lib/string/strdisp.c
index e63f038..dada5d0 100644
--- a/src/kernel/lib/string/strdisp.c
+++ b/src/kernel/lib/string/strdisp.c
@@ -1,8 +1,8 @@
-#include <kernel/lib/string.h>
+#include <lib/string.h>
void strdisponce(char *str)
{
- for (size_t i = sizeof(str) + 2; i > 0; i--)
+ for (u32 i = sizeof(str) + 2; i > 0; i--)
str[i] = str[i - 1];
str[0] = 0;
}
diff --git a/src/kernel/lib/string/strdup.c b/src/kernel/lib/string/strdup.c
index 82d14ef..00bb863 100644
--- a/src/kernel/lib/string/strdup.c
+++ b/src/kernel/lib/string/strdup.c
@@ -1,9 +1,9 @@
-#include <kernel/lib/string.h>
-#include <kernel/memory/alloc.h>
+#include <lib/string.h>
+#include <memory/alloc.h>
char *strdup(const char *orig)
{
- size_t s_orig = strlen(orig);
+ u32 s_orig = strlen(orig);
char *ret = (char *)kmalloc(s_orig + 1);
strcpy(ret, orig);
return ret;
diff --git a/src/kernel/lib/string/strinv.c b/src/kernel/lib/string/strinv.c
index 071a99d..90cb581 100644
--- a/src/kernel/lib/string/strinv.c
+++ b/src/kernel/lib/string/strinv.c
@@ -1,8 +1,8 @@
-#include <kernel/lib/string.h>
+#include <lib/string.h>
void strinv(char *str)
{
- size_t s_str = strlen(str);
+ u32 s_str = strlen(str);
int iterations = (int)s_str / 2;
for (int i = 0; i < iterations; i++) {
diff --git a/src/kernel/lib/string/strlen.c b/src/kernel/lib/string/strlen.c
index 9e7e448..520ab92 100644
--- a/src/kernel/lib/string/strlen.c
+++ b/src/kernel/lib/string/strlen.c
@@ -1,8 +1,8 @@
-#include <kernel/lib/string.h>
+#include <lib/string.h>
-size_t strlen(const char *str)
+u32 strlen(const char *str)
{
- size_t len = 0;
+ u32 len = 0;
while (str[len])
len++;
return len;
diff --git a/src/kernel/lib/string/strstr.c b/src/kernel/lib/string/strstr.c
index d58b4d5..bcf1539 100644
--- a/src/kernel/lib/string/strstr.c
+++ b/src/kernel/lib/string/strstr.c
@@ -1,10 +1,10 @@
#include <stdint.h>
-#include <kernel/lib/stdlib.h>
+#include <lib/stdlib.h>
char *strstr(const char *in, const char *str)
{
char c;
- uint32_t len;
+ u32 len;
c = *str++;
if (!c)