> 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
 21:31:47 up 2 days, 16:37,  1 user,  load average: 0.71, 0.53, 0.36
This commit is contained in:
tracer-ics2023
2024-09-19 21:31:48 +08:00
committed by zzy
parent b73ab41e3a
commit 6cb56a5d40
3 changed files with 8 additions and 10 deletions

View File

@ -9,7 +9,7 @@
extern "C" { extern "C" {
#endif #endif
//#define __NATIVE_USE_KLIB__ // #define __NATIVE_USE_KLIB__
// string.h // string.h
void *memset (void *s, int c, size_t n); void *memset (void *s, int c, size_t n);

View File

@ -29,16 +29,15 @@ int num_to_ascii(int num, int power, int size, char *buf) {
return ret; return ret;
} }
static inline int print_fmt(char **out, int n, const char** fmt, void* _ap) { static inline int print_fmt(char **out, int n, const char** fmt, va_list (*ap)) {
va_list ap = *(va_list*)_ap;
int ret = 0; int ret = 0;
switch (**fmt) { switch (**fmt) {
case 'd': case 'd':
ret = num_to_ascii(va_arg(ap, int), 10, n, *out); ret = num_to_ascii(va_arg(*ap, int), 10, n, *out);
(*out) += ret; (*out) += ret;
break; break;
case 's': case 's':
const char* str = va_arg(ap, const char*); const char* str = va_arg(*ap, const char*);
if (ret > n) break; if (ret > n) break;
for (; *str; str ++, (*out) ++, ret ++ ) { for (; *str; str ++, (*out) ++, ret ++ ) {
if (ret >= n) { if (ret >= n) {
@ -48,20 +47,19 @@ static inline int print_fmt(char **out, int n, const char** fmt, void* _ap) {
} }
break; break;
case 'c': case 'c':
char ch = va_arg(ap, int); char ch = va_arg(*ap, int);
ret = 1; ret = 1;
**out = ch; **out = ch;
(*out) ++; (*out) ++;
break; break;
case 'x': case 'x':
ret = num_to_ascii(va_arg(ap, int), 16, n, *out); ret = num_to_ascii(va_arg(*ap, int), 16, n, *out);
(*out) += ret; (*out) += ret;
break; break;
default: default:
break; break;
} }
(*fmt) ++; (*fmt) ++;
*(va_list*)_ap = ap;
return ret; return ret;
} }
@ -71,7 +69,7 @@ int rvsnprintf(char* out, size_t n, const char* fmt, va_list ap) {
if (*fmt == '%') { if (*fmt == '%') {
// FIXME // FIXME
fmt++; fmt++;
print_fmt(&out, 123, &fmt, &ap); print_fmt(&out, 123, &fmt, (va_list*)&ap);
continue; continue;
} }
*out = *fmt; *out = *fmt;

View File

@ -40,7 +40,7 @@ void *malloc(size_t size) {
ptr += size; ptr += size;
return ptr - size; return ptr - size;
#endif #endif
return NULL; return ptr;
} }
void free(void *ptr) { void free(void *ptr) {