vsnprintf implementation

This commit is contained in:
georgemoralis 2023-10-16 08:55:07 +03:00
parent 2d4d39c54b
commit 675193fec3
4 changed files with 12 additions and 1 deletions

View file

@ -107,6 +107,7 @@ void PS4_SYSV_ABI qsort(void* ptr, size_t count,size_t size, int(PS4_SYSV_ABI* c
std::qsort(ptr, count, size, qsort_compair);
}
void LibC_Register(SymbolsResolver* sym) {
LIB_FUNCTION("bzQExy189ZI", "libc", 1, "libc", 1, 1, init_env);
LIB_FUNCTION("3GPpjQdAMTw", "libc", 1, "libc", 1, 1, __cxa_guard_acquire);
@ -119,6 +120,7 @@ void LibC_Register(SymbolsResolver* sym) {
LIB_FUNCTION("8G2LB+A3rzg", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::atexit);
LIB_FUNCTION("-QgqOT5u2Vk", "libc", 1, "libc", 1, 1, _Assert);
LIB_FUNCTION("hcuQgD53UxM", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::printf);
LIB_FUNCTION("Q2V+iqvjgC0", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::vsnprintf);
LIB_FUNCTION("YQ0navp+YIc", "libc", 1, "libc", 1, 1, puts);
LIB_FUNCTION("cpCOXWMgha0", "libc", 1, "libc", 1, 1, rand);
LIB_FUNCTION("ZtjspkJQ+vw", "libc", 1, "libc", 1, 1, _Fsin);

View file

@ -12,6 +12,8 @@ PS4_SYSV_ABI int printf(VA_ARGS) {
return printf_ctx(&ctx);
}
int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg) { return vsnprintf_ctx(s, n, format, arg); }
PS4_SYSV_ABI void exit(int code) { std::exit(code); }
PS4_SYSV_ABI int atexit(void (*func)()) {

View file

@ -8,6 +8,7 @@ namespace Emulator::HLE::Libraries::LibC {
// HLE functions
PS4_SYSV_ABI int printf(VA_ARGS);
int PS4_SYSV_ABI vsnprintf(char* s, size_t n, const char* format, VaList* arg);
PS4_SYSV_ABI void exit(int code);
PS4_SYSV_ABI int atexit(void (*func)());
int PS4_SYSV_ABI memcmp(const void* s1, const void* s2, size_t n);

View file

@ -56,7 +56,7 @@
#include <cstdbool>
#include <cstddef>
#include <cstdint>
#include <string>
#include "va_ctx.h"
namespace Emulator::HLE::Libraries::LibC {
@ -693,4 +693,10 @@ static int printf_ctx(VaCtx* ctx) {
return result;
}
static int vsnprintf_ctx(char* s, size_t n, const char* format, VaList* arg) {
char buffer[n];
int result = _vsnprintf(_out_buffer, buffer, format, arg);
std::strcpy(s, buffer);
return result;
}
} // namespace Emulator::HLE::Libraries::LibC