Skip to content
Snippets Groups Projects
Commit 422281e6 authored by Avi Kivity's avatar Avi Kivity
Browse files

libc: implement snprintf()

parent 91a0538e
No related branches found
No related tags found
No related merge requests found
...@@ -333,3 +333,15 @@ int sprintf(char* str, const char* format, ...) ...@@ -333,3 +333,15 @@ int sprintf(char* str, const char* format, ...)
std::copy(out.begin(), out.end(), str); std::copy(out.begin(), out.end(), str);
return out.length(); return out.length();
} }
int snprintf(char* str, size_t n, const char* format, ...)
{
va_list ap;
va_start(ap, format);
auto out = strprintf(format, ap);
va_end(ap);
std::string trunc = out.substr(0, n - 1);
std::copy(out.begin(), out.end(), str);
return out.length();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment