feature: kmalloc kfree and krealloc are good

This commit is contained in:
2024-09-21 12:17:27 +02:00
parent 0467c45bf0
commit 943f2beab9
15 changed files with 607 additions and 23 deletions

View File

@ -1,34 +1,38 @@
SRCDIR = src
OBJDIR = obj
BUILDDIR = build
SSRC := $(shell find src -name '*.s')
CSRC := $(shell find src -name '*.c')
OBJ := $(patsubst src/%.c,obj/%.o,$(CSRC))\
$(patsubst src/%.s,obj/%.o,$(SSRC))
SRC := $(shell find $(SRCDIR) -name '*.c')
OBJ := $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SRC))
CC := i386-elf-gcc
CFLAGS := -std=gnu99 -ffreestanding -O2 -Wall -Wextra -iquoteheaders -c
CC = i386-elf-gcc
CFLAGS = -std=gnu99 -ffreestanding -O2 -Wall -Wextra -iquoteheaders -c
AR = ar
ARFLAGS =
AS := i386-elf-as
ASFLAGS :=
AR := ar
ARFLAGS :=
NAME = libbozo.a
$(OBJDIR)/%.o: $(SRCDIR)/%.c
obj/%.o: src/%.s
mkdir -p $(dir $@)
$(AS) $(ASFLAGS) $< -o $@
obj/%.o: src/%.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $< -o $@
all : $(NAME)
clean :
rm -rf $(OBJDIR)
rm -rf obj
fclean : clean
rm -rf $(BUILDDIR)
rm -rf build
$(NAME) : $(OBJ)
mkdir -p $(BUILDDIR)
$(AR) -rc $(BUILDDIR)/$(NAME) $(OBJ)
mkdir -p build
$(AR) -rc build/$(NAME) $(OBJ)
re: fclean all
.PHONY: clean fclean test all re
.PHONY: clean fclean all re

View File

@ -7,6 +7,8 @@ int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
size_t strlen(const char *str);
char *strstr(const char *haystack, const char *needle);
char *strcpy(char *dest, const char *src);
void *memcpy(void *dest, const void *src, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
void *memset(void *str, int c, size_t n);
void *memmove(void *dest, const void *src, size_t n);

View File

@ -0,0 +1,21 @@
#include <stddef.h>
void *memmove(void *dest, const void *src, size_t n)
{
size_t i = 0;
const char *cast1 = (const char *)src;
char *cast2 = (char *)dest;
if (!cast1 && !cast2 && n > 0)
return (0);
if (&cast1[0] > &cast2[0]) {
while (i < n) {
cast2[i] = cast1[i];
i++;
}
} else {
while (n--)
cast2[n] = cast1[n];
}
return cast2;
}

View File

@ -0,0 +1,12 @@
#include <stddef.h>
char *strcpy(char *dest, const char *src)
{
size_t i = 0;
if (!src)
return NULL;
for (; src[i]; i++)
dest[i] = src[i];
dest[i] = '\0';
return dest;
}