Add vprintf, (v)sprintf and (v)snprintf to libc + move the non v-printfs to stdio.cpp, since they can now call their v-variants and thus don't depend on internal_printf
This commit is contained in:
parent
9420484c9b
commit
cb60e418b2
@ -29,6 +29,11 @@ extern "C"
|
|||||||
void setbuf(FILE*, char*);
|
void setbuf(FILE*, char*);
|
||||||
int vfprintf(FILE*, const char*, va_list);
|
int vfprintf(FILE*, const char*, va_list);
|
||||||
int printf(const char*, ...);
|
int printf(const char*, ...);
|
||||||
|
int vprintf(const char*, va_list);
|
||||||
|
int sprintf(char*, const char*, ...);
|
||||||
|
int snprintf(char*, size_t, const char*, ...);
|
||||||
|
int vsprintf(char*, const char*, va_list);
|
||||||
|
int vsnprintf(char*, size_t, const char*, va_list);
|
||||||
int puts(const char*);
|
int puts(const char*);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -247,13 +247,29 @@ static int internal_printf(const char* format, PutString put_string_callback, ss
|
|||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
int printf(const char* format, ...)
|
int vprintf(const char* format, va_list ap)
|
||||||
{
|
{
|
||||||
va_list ap;
|
return internal_printf(
|
||||||
va_start(ap, format);
|
|
||||||
int written = internal_printf(
|
|
||||||
format, [](const char* s) { syscall(SYS_write, s, strlen(s)); }, -1, ap);
|
format, [](const char* s) { syscall(SYS_write, s, strlen(s)); }, -1, ap);
|
||||||
va_end(ap);
|
}
|
||||||
return written;
|
|
||||||
|
int vsprintf(char* str, const char* format, va_list ap)
|
||||||
|
{
|
||||||
|
return internal_printf(
|
||||||
|
format,
|
||||||
|
[&](const char* s) {
|
||||||
|
if (str) strcat(str, s);
|
||||||
|
},
|
||||||
|
-1, ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
int vsnprintf(char* str, size_t max, const char* format, va_list ap)
|
||||||
|
{
|
||||||
|
return internal_printf(
|
||||||
|
format,
|
||||||
|
[&](const char* s) {
|
||||||
|
if (str) strcat(str, s);
|
||||||
|
},
|
||||||
|
max == 0 ? 0 : max - 1, ap);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -53,4 +53,28 @@ extern "C"
|
|||||||
nwritten += syscall(SYS_write, "\n", 1);
|
nwritten += syscall(SYS_write, "\n", 1);
|
||||||
return nwritten;
|
return nwritten;
|
||||||
}
|
}
|
||||||
|
int snprintf(char* str, size_t max, const char* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
int written = vsnprintf(str, max, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
int sprintf(char* str, const char* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
int written = vsprintf(str, format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
int printf(const char* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
int written = vprintf(format, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return written;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user