completing GCC required string functions
This commit is contained in:
parent
7125823505
commit
d655441993
2 changed files with 39 additions and 6 deletions
|
|
@ -13,7 +13,7 @@ RISC-V Operating System.
|
|||
- [x] Splitting of large blocks.
|
||||
- [x] Doubly-linked list headers.
|
||||
- [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.
|
||||
|
||||
### Phase 2: Hardware Interfacing & Traps
|
||||
|
|
|
|||
|
|
@ -1,12 +1,45 @@
|
|||
#include <stddef.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;
|
||||
while (n--)
|
||||
unsigned char *d = dest;
|
||||
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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue