Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/libs/prx/libc/src/FileAndHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,14 @@ size_t APS5_VABI fread_nid_postfix(void* buffer, size_t size, size_t count, File
stream->SyncStatus();
return count;
}
if (!stream->SwitchToReading()) return 0;
const int previousError = errno;
errno = 0;
if (!stream->SwitchToReading()) { errno = errno != 0 ? GuestErrnoFromHost_nid_no_patch(errno) : previousError; return 0; }
const auto result = std::fread(buffer, size, count, handle);
const int nativeError = errno;
stream->SyncStatus();
if (nativeError != 0) errno = GuestErrnoFromHost_nid_no_patch(nativeError);
else errno = previousError;
stream->KeepDirectoryReadError(result < count);
return result;
}
Expand Down
22 changes: 19 additions & 3 deletions core/libs/prx/libc/src/StandardStreams.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/FileStream.hpp"
#include "prx/libc/include/General.hpp"
#include "prx/libc/include/HostErrno.hpp"
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cerrno>
#include <cstddef>
Expand Down Expand Up @@ -95,9 +96,14 @@ int APS5_VABI fgetc_nid_postfix(FileStream* stream) {
if (stream && !stream->IsOpen()) { errno = 9; return -1; }
auto* native = GetNativeStream(stream);
stream->Orientation(-1);
if (!stream->SwitchToReading()) return -1;
const int previousError = errno;
errno = 0;
if (!stream->SwitchToReading()) { errno = errno != 0 ? GuestErrnoFromHost_nid_no_patch(errno) : previousError; return -1; }
const int result = std::fgetc(native);
const int nativeError = errno;
stream->SyncStatus();
if (nativeError != 0) errno = GuestErrnoFromHost_nid_no_patch(nativeError);
else errno = previousError;
stream->KeepDirectoryReadError(result == -1);
return result;
}
Expand Down Expand Up @@ -157,13 +163,18 @@ int APS5_VABI getc_unlocked_nid_postfix(FileStream* stream) {
if (stream && !stream->IsOpen()) { errno = 9; return -1; }
auto* native = GetNativeStream(stream);
stream->Orientation(-1);
if (!stream->SwitchToReadingUnlocked()) return -1;
const int previousError = errno;
errno = 0;
if (!stream->SwitchToReadingUnlocked()) { errno = errno != 0 ? GuestErrnoFromHost_nid_no_patch(errno) : previousError; return -1; }
#ifdef _WIN32
const int result = _fgetc_nolock(native);
#else
const int result = getc_unlocked(native);
#endif
const int nativeError = errno;
stream->SyncUnlockedStatus();
if (nativeError != 0) errno = GuestErrnoFromHost_nid_no_patch(nativeError);
else errno = previousError;
stream->KeepDirectoryReadError(result == -1);
return result;
}
Expand Down Expand Up @@ -242,9 +253,14 @@ char* APS5_VABI fgets_nid_postfix(char* buffer, int size, FileStream* stream) {
return nullptr;
}
auto* native = GetNativeStream(stream);
if (!stream->SwitchToReading()) return nullptr;
const int previousError = errno;
errno = 0;
if (!stream->SwitchToReading()) { errno = errno != 0 ? GuestErrnoFromHost_nid_no_patch(errno) : previousError; return nullptr; }
auto* result = std::fgets(buffer, size, native);
const int nativeError = errno;
stream->SyncStatus();
if (nativeError != 0) errno = GuestErrnoFromHost_nid_no_patch(nativeError);
else errno = previousError;
stream->KeepDirectoryReadError(result == nullptr);
return result;
}
Expand Down
Loading
Loading