> 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
 22:35:40 up 2 days, 11:00,  3 users,  load average: 0.45, 0.29, 0.16
This commit is contained in:
tracer-ics2023
2024-09-07 22:35:41 +08:00
committed by zzy
parent 3c0db3c05a
commit 9c8fb91e28

View File

@ -75,6 +75,7 @@ static inline int fmt_s(char* out, size_t n, const char* fmt, va_list ap) {
static inline int fmt_match(char* out, size_t n, const char* fmt, va_list ap) {
int res;
assert(*(fmt - 1) == '%');
switch(*fmt) {
case 'd':
res = fmt_d(out, n, fmt, ap);
@ -90,23 +91,28 @@ 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) {
char* _out = out;
size_t _n = n;
const char* _fmt = fmt;
for (; n; _fmt ++, _out ++, _n --) {
switch (*_fmt) {
case '\0':
*out = *fmt;
*_out = *_fmt;
goto END;
case '%':
fmt ++;
int len = fmt_match(out, n, fmt, ap);
out += len - 1;
n -= len + 1;
_fmt ++;
int len = fmt_match(_out, _n, _fmt, ap);
_out += len - 1;
_n -= len + 1;
break;
default:
*out = *fmt;
*_out = *_fmt;
break;
}
}
END:
assert(strlen(out) + 1 == n - _n);
assert(*out == '\0');
return 0;
}