memcpy() + memset(); Makefile for libc

This commit is contained in:
Thomas Oltmann 2025-03-16 01:29:52 +01:00
parent b5c9c0de9a
commit 77a7742538
3 changed files with 72 additions and 0 deletions

53
libc/Makefile Normal file
View file

@ -0,0 +1,53 @@
include ../config.mk
AR=ar
ARFLAGS=rcs
LIBC_OBJECTS= \
string/ffs.o \
string/ffsl.o \
string/ffsll.o \
string/memccpy.o \
string/memchr.o \
string/memcmp.o \
string/memcpy.o \
string/memmove.o \
string/memrchr.o \
string/memset.o \
string/stpcpy.o \
string/stpncpy.o \
string/strcat.o \
string/strchr.o \
string/strchrnul.o \
string/strcmp.o \
string/strcoll.o \
string/strcpy.o \
string/strcspn.o \
string/stresep.o \
string/strlcat.o \
string/strlcpy.o \
string/strlen.o \
string/strncat.o \
string/strncmp.o \
string/strncpy.o \
string/strnlen.o \
string/strpbrk.o \
string/strrchr.o \
string/strsep.o \
string/strspn.o \
string/strstr.o \
string/strtok_r.o \
string/strxfrm.o \
# end of source list
libc.a: $(LIBC_OBJECTS)
$(AR) $(ARFLAGS) $@ $(LIBC_OBJECTS)
.c.o: string.h
$(CC) $(CFLAGS) -c -o $@ $(@:.o=.c) $(CPPFLAGS)
clean:
rm -f $(LIBC_OBJECTS)
rm -f libc.a
.PHONY: clean

10
libc/string/memcpy.c Normal file
View file

@ -0,0 +1,10 @@
#include <string.h>
void *memcpy(void *dest, const void *src, size_t n) {
unsigned char *d = dest;
const unsigned char *s = src;
for (size_t i = 0; i < n; i++) {
d[i] = s[i];
}
return dest;
}

9
libc/string/memset.c Normal file
View file

@ -0,0 +1,9 @@
#include <string.h>
void *memset(void *ptr, int value, size_t num) {
unsigned char *byte_ptr = ptr;
for (size_t i = 0; i < num; i++) {
byte_ptr[i] = (unsigned char)value;
}
return ptr;
}