completing GCC required string functions

This commit is contained in:
Liam Kerr 2026-02-09 20:26:36 +00:00
parent 7125823505
commit d655441993
2 changed files with 39 additions and 6 deletions

View file

@ -13,7 +13,7 @@ RISC-V Operating System.
- [x] Splitting of large blocks. - [x] Splitting of large blocks.
- [x] Doubly-linked list headers. - [x] Doubly-linked list headers.
- [x] Bidirectional coalescing (Iterative). - [x] Bidirectional coalescing (Iterative).
- [ ] **String Library**: Complete `lib/string.c` (`memset`, `memcpy`, `strcmp`, `strlen`). - x ] **String Library**: Complete `lib/string.c` (`memset`, `memcpy`, `strcmp`, `strlen`).
- [x] **Formatted Printing**: Robust `kprintf` implementation for hex and decimal. - [x] **Formatted Printing**: Robust `kprintf` implementation for hex and decimal.
### Phase 2: Hardware Interfacing & Traps ### Phase 2: Hardware Interfacing & Traps

View file

@ -1,12 +1,45 @@
#include <stddef.h> #include <stddef.h>
#include "string.h" #include "string.h"
void *memset(void *s, int c, size_t n) void *memset(void *dest, int val, size_t size)
{ {
unsigned char *p = s; unsigned char *d = dest;
while (n--) while (size--)
{ {
*p++ = (unsigned char)c; *d++ = (unsigned char)val;
} }
return s; return dest;
}
void *memcpy(void* dest, const void* src, size_t size)
{
unsigned char *d = dest;
const unsigned char *s = src;
while(--size)
{
*d++ = *s++;
}
return dest;
}
int strcmp(const char * str1, const char * str2)
{ while(*str1 == *str2)
{
if (*str1 == '\0')
{
return 0;
}
str1++;
str2++;
}
return *str1 - *str2;
}
size_t strlen(const char* str)
{
size_t c = 0;
while(*str++ != '\0'){
c++;
}
return c;
} }