> 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
 10:38:19 up 23:02,  3 users,  load average: 0.13, 0.14, 0.09
This commit is contained in:
tracer-ics2023
2024-09-06 10:38:20 +08:00
committed by zzy
parent bd1eba9abe
commit d20b08af88

View File

@ -10,39 +10,39 @@
#if !defined(__ISA_NATIVE__) || defined(__NATIVE_USE_KLIB__)
int printf(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
char buf[1024] = { 0 };
int ret = vsnprintf(buf, sizeof(buf), fmt, ap);
putstr(buf);
va_end(ap);
return ret;
va_list ap;
va_start(ap, fmt);
char buf[1024] = { 0 };
int ret = vsnprintf(buf, sizeof(buf), fmt, ap);
putstr(buf);
va_end(ap);
return ret;
}
int vsprintf(char *out, const char *fmt, va_list ap) {
return vsnprintf(out, SIZE_MAX, fmt, ap);
return vsnprintf(out, SIZE_MAX, fmt, ap);
}
int sprintf(char *out, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int ret = vsprintf(out, fmt, ap);
va_end(ap);
return ret;
va_list ap;
va_start(ap, fmt);
int ret = vsprintf(out, fmt, ap);
va_end(ap);
return ret;
}
int snprintf(char *out, size_t n, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int ret = vsnprintf(out, n, fmt, ap);
va_end(ap);
return ret;
va_list ap;
va_start(ap, fmt);
int ret = vsnprintf(out, n, fmt, ap);
va_end(ap);
return ret;
}
static int rvsnprintf(char* out, size_t n, const char* fmt, va_list ap);
int vsnprintf(char *out, size_t n, const char *fmt, va_list ap) {
return rvsnprintf(out, n, fmt, ap);
return rvsnprintf(out, n, fmt, ap);
}
static inline int fmt_d(char* out, size_t n, const char* fmt, va_list ap) {
@ -57,9 +57,10 @@ static inline int fmt_d(char* out, size_t n, const char* fmt, va_list ap) {
int i;
for (i = 0; in; in /= 10, i ++) {
buf[i] = in % 10;
buf[i] += '0';
}
for (int j = i; j >= 0; j --) {
for (int j = i - 1; j >= 0; j --) {
*out = buf[j];
}
return i;
@ -89,24 +90,24 @@ static inline int fmt_match(char* out, size_t n, const char* fmt, va_list ap) {
}
static int rvsnprintf(char* out, size_t n, const char* fmt, va_list ap) {
for (; n; fmt ++, out ++, n --) {
switch (*fmt)
{
case '\0':
*out = *fmt;
goto END;
case '%':
int len = fmt_match(out, n, fmt, ap);
out += len;
fmt ++;
n -= len;
default:
*out = *fmt;
break;
for (; n; fmt ++, out ++, n --) {
switch (*fmt) {
case '\0':
*out = *fmt;
goto END;
case '%':
fmt ++;
int len = fmt_match(out, n, fmt, ap);
out += len - 1;
n -= len + 1;
break;
default:
*out = *fmt;
break;
}
}
}
END:
return 0;
return 0;
}
#endif