From a48ad647aeaee6223eb5578f60234f35497fff99 Mon Sep 17 00:00:00 2001 From: Kamila Szewczyk Date: Sun, 8 Oct 2023 14:54:13 +0200 Subject: [PATCH] memset --- Makefile | 2 +- lib83/memset.c | 12 ++++++++++++ lib83/string.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 lib83/memset.c diff --git a/Makefile b/Makefile index 7a2e856..fba1954 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CC=sdcc CFLAGS=-Ilib83 -c -mz80 --std-sdcc2x --no-std-crt0 --reserve-regs-iy --opt-code-size OBJS=_crt0.rel clrscr.rel putchar.rel puts.rel exit.rel gotoxy.rel __assert_fail.rel \ - getchar.rel put_int.rel ctype.rel \ + getchar.rel put_int.rel ctype.rel memcpy.rel memset.rel memmove.rel \ main.rel .PHONY: all clean try diff --git a/lib83/memset.c b/lib83/memset.c new file mode 100644 index 0000000..133538f --- /dev/null +++ b/lib83/memset.c @@ -0,0 +1,12 @@ + +#include + +void * memset(void * buf, unsigned char ch, size_t count) { + unsigned char * ret = buf; + + while (count--) + *ret++ = ch; + + return buf; +} + diff --git a/lib83/string.h b/lib83/string.h index c14c339..0268d4c 100644 --- a/lib83/string.h +++ b/lib83/string.h @@ -5,7 +5,7 @@ #include extern void *memcpy(void *dest, const void *src, size_t n); -extern void *memset(void *s, int c, size_t n); +extern void *memset(void *s, unsigned char c, size_t n); extern void *memmove(void *dest, const void *src, size_t n); extern int memcmp(const void *s1, const void *s2, size_t n);