> compile NEMU
221220000 张三 Linux zzy 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 19:49:57 up 6:13, 1 user, load average: 0.22, 0.11, 0.13
This commit is contained in:
@ -5,27 +5,47 @@
|
||||
#if !defined(__ISA_NATIVE__) || defined(__NATIVE_USE_KLIB__)
|
||||
|
||||
size_t strlen(const char *s) {
|
||||
panic("Not implemented");
|
||||
size_t len;
|
||||
for (len = 0; *s != '\0'; len++, s++);
|
||||
return len;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src) {
|
||||
panic("Not implemented");
|
||||
char* _dst = dst;
|
||||
for (; *src != '\0'; _dst++, src++) {
|
||||
*_dst = *src;
|
||||
}
|
||||
*_dst = '\0';
|
||||
return dst;
|
||||
}
|
||||
|
||||
char *strncpy(char *dst, const char *src, size_t n) {
|
||||
panic("Not implemented");
|
||||
char* _dst = dst;
|
||||
for (; n > 0; n--, _dst++, src++) {
|
||||
if (*src == '\0') {
|
||||
*_dst = '\0';
|
||||
src--;
|
||||
}
|
||||
*_dst = *src;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
char *strcat(char *dst, const char *src) {
|
||||
panic("Not implemented");
|
||||
return strcpy(dst + strlen(dst), src);
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
panic("Not implemented");
|
||||
return strncmp(s1, s2, SIZE_MAX);
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t n) {
|
||||
panic("Not implemented");
|
||||
for (; *s1 != '\0' && *s2 != '\0'; s1++, s2++, n--) {
|
||||
if (*s1 != *s2 || n == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return *(unsigned char*)s1 - *(unsigned char*)s2;
|
||||
}
|
||||
|
||||
void *memset(void *s, int c, size_t n) {
|
||||
@ -37,11 +57,23 @@ void *memmove(void *dst, const void *src, size_t n) {
|
||||
}
|
||||
|
||||
void *memcpy(void *out, const void *in, size_t n) {
|
||||
panic("Not implemented");
|
||||
unsigned char *_out = (unsigned char*)out;
|
||||
const unsigned char *_in = (const unsigned char*)in;
|
||||
for (; n > 0; n--, _out++, _in++) {
|
||||
*_out = *_in;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n) {
|
||||
panic("Not implemented");
|
||||
unsigned char *in1 = (unsigned char*)s1;
|
||||
const unsigned char *in2 = (const unsigned char*)s2;
|
||||
for (; n > 0; n--, in1++, in2++) {
|
||||
if (*in1 != *in2) {
|
||||
return *in1 - *in2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user