mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(libc): implement fputwc, fputws and fscanf
This commit is contained in:
@@ -66,21 +66,6 @@ int APS5_VABI _ZNKSt9exception6_RaiseEv_nid_postfix() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI fputwc_nid_postfix() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI fputws_nid_postfix() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI fscanf_nid_postfix() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
APS5_EXPORT("Pu0Ecyk-7FU", libcUnknown_Pu0Ecyk_M7FU);
|
||||
int APS5_VABI libcUnknown_Pu0Ecyk_M7FU() {
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
|
||||
@@ -49,6 +49,23 @@ int APS5_VABI fprintf_nid_postfix(FileStream* stream, const char* format, ...) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int APS5_VABI fscanf_nid_postfix(FileStream* stream, const char* format, ...) {
|
||||
auto* native = GetNativeStream(stream);
|
||||
#ifdef _WIN32
|
||||
__builtin_sysv_va_list args;
|
||||
__builtin_sysv_va_start(args, format);
|
||||
const int result = std::vfscanf(native, format, args);
|
||||
__builtin_sysv_va_end(args);
|
||||
#else
|
||||
std::va_list args;
|
||||
va_start(args, format);
|
||||
const int result = std::vfscanf(native, format, args);
|
||||
va_end(args);
|
||||
#endif
|
||||
stream->SyncStatus();
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
int APS5_VABI printf_nid_postfix(const char* format, ...) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
#include "prx/libc/include/VarArgsAbi.hpp"
|
||||
#include "prx/libc/include/FileStream.hpp"
|
||||
#include "prx/libc/include/WindowsFormatting.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -216,4 +217,33 @@ int APS5_VABI wprintf_nid_postfix(const char16_t* format, ...) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int APS5_VABI fputwc_nid_postfix(char16_t value, FileStream* stream) {
|
||||
if (stream == nullptr) { errno = 22; return -1; }
|
||||
try {
|
||||
const std::string bytes = ToUtf8(std::u16string(1, value));
|
||||
auto* native = GetNativeStream(stream);
|
||||
if (std::fwrite(bytes.data(), 1, bytes.size(), native) != bytes.size()) throw std::runtime_error("stream write failed");
|
||||
stream->SyncStatus();
|
||||
return value;
|
||||
} catch (const std::exception&) {
|
||||
errno = 22;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int APS5_VABI fputws_nid_postfix(const char16_t* str, FileStream* stream) {
|
||||
if (str == nullptr || stream == nullptr) { errno = 22; return -1; }
|
||||
try {
|
||||
const std::u16string text(str);
|
||||
const std::string bytes = ToUtf8(text);
|
||||
auto* native = GetNativeStream(stream);
|
||||
if (std::fwrite(bytes.data(), 1, bytes.size(), native) != bytes.size()) throw std::runtime_error("stream write failed");
|
||||
stream->SyncStatus();
|
||||
return static_cast<int>(text.size());
|
||||
} catch (const std::exception&) {
|
||||
errno = 22;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ int APS5_VABI vfprintf_nid_postfix(FileStream*, const char*, void*);
|
||||
int APS5_VABI vsprintf_nid_postfix(char*, const char*, void*);
|
||||
int APS5_VABI fgetc_nid_postfix(FileStream*);
|
||||
int APS5_VABI fputc_nid_postfix(int, FileStream*);
|
||||
int APS5_VABI fputwc_nid_postfix(char16_t, FileStream*);
|
||||
int APS5_VABI fputws_nid_postfix(const char16_t*, FileStream*);
|
||||
int APS5_VABI fscanf_nid_postfix(FileStream*, const char*, ...);
|
||||
int APS5_VABI __srget_nid_postfix(FileStream*);
|
||||
int APS5_VABI __swbuf_nid_postfix(int, FileStream*);
|
||||
int APS5_VABI ungetc_nid_postfix(int, FileStream*);
|
||||
@@ -105,6 +108,15 @@ int main() {
|
||||
stream.Close();
|
||||
Require(guest.flags == 0 && guest.descriptor == -1);
|
||||
|
||||
FileStream wide(std::tmpfile());
|
||||
Require(fputwc_nid_postfix(u'A', &wide) == u'A');
|
||||
Require(fputws_nid_postfix(u"B\x00E9", &wide) == 2);
|
||||
std::rewind(wide.GetHandle());
|
||||
char wideBytes[8]{};
|
||||
Require(std::fread(wideBytes, 1, 4, wide.GetHandle()) == 4);
|
||||
Require(std::memcmp(wideBytes, "AB\xC3\xA9", 4) == 0);
|
||||
wide.Close();
|
||||
|
||||
FileStream formatted(std::tmpfile());
|
||||
const char expected[] = "guest 4294967297 1.25 1 2 3 4 5 6 7 8\n";
|
||||
Require(fprintf_nid_postfix(&formatted, "%s %ld %.2f %d %d %d %d %d %d %d %d\n",
|
||||
@@ -118,6 +130,16 @@ int main() {
|
||||
Require(std::strcmp(output, " 3.50:end") == 0);
|
||||
formatted.Close();
|
||||
|
||||
FileStream scanned(std::tmpfile());
|
||||
Require(fprintf_nid_postfix(&scanned, "%d %s", 42, "answer") == 9);
|
||||
std::rewind(scanned.GetHandle());
|
||||
int scannedNumber = 0;
|
||||
char scannedWord[16]{};
|
||||
Require(fscanf_nid_postfix(&scanned, "%d %15s", &scannedNumber, scannedWord) == 2);
|
||||
Require(scannedNumber == 42 && std::strcmp(scannedWord, "answer") == 0);
|
||||
Require(fscanf_nid_postfix(&scanned, "%d", &scannedNumber) == EOF);
|
||||
scanned.Close();
|
||||
|
||||
FileStream positioned(std::tmpfile());
|
||||
constexpr std::int64_t largeOffset = INT64_C(4294967313);
|
||||
Require(fseeko_nid_postfix(&positioned, largeOffset, SEEK_SET) == 0);
|
||||
|
||||
Reference in New Issue
Block a user