Skip to content
Merged
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
6 changes: 1 addition & 5 deletions core/libs/prx/libc/src/StandardStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,9 @@ int APS5_VABI ungetc_nid_postfix(int value, FileStream* stream) {
return result;
}
char* APS5_VABI fgets_nid_postfix(char* buffer, int size, FileStream* stream) {
if (size < 2) return nullptr;
if (stream && !stream->IsOpen()) { errno = 9; return nullptr; }
if (stream) stream->Orientation(-1);
if (size <= 0) {
stream->SetError();
errno = 22;
return nullptr;
}
auto* native = GetNativeStream(stream);
if (!stream->SwitchToReading()) return nullptr;
auto* result = std::fgets(buffer, size, native);
Expand Down
2 changes: 1 addition & 1 deletion core/libs/tests/GuestFwide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int main(int argc, char** argv) {
stream = open(argv[2], "w+b");
Require(stream != nullptr, "could not reopen guest stream");
Require(getLine(line, 0, stream) == nullptr, "fgets with size 0 should fail");
Require(wide(stream, 0) == -1, "fgets should orient the stream even for size 0");
Require(wide(stream, 0) == 0, "fgets with a size below 2 should leave the stream unoriented");
Require(close(stream) == 0, "could not close stream after fgets");
stream = open(argv[2], "w+b");
Require(stream != nullptr, "could not reopen guest stream");
Expand Down
14 changes: 8 additions & 6 deletions core/libs/tests/GuestStandardStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,8 @@ static void CheckFgetsSize() {
std::memset(buffer, '!', sizeof(buffer));
*__error_nid_postfix() = 0;
Require(fgets_nid_postfix(buffer, size, &stream) == nullptr);
Require(*__error_nid_postfix() == 22 && ferror_nid_postfix(&stream) != 0 && feof_nid_postfix(&stream) == 0);
Require(*__error_nid_postfix() == 0 && ferror_nid_postfix(&stream) == 0 && feof_nid_postfix(&stream) == 0);
Require(buffer[0] == '!' && ftello_nid_postfix(&stream) == 0);
Require(ferror_nid_postfix(&stream) != 0);
clearerr_nid_postfix(&stream);

Require(ferror_nid_postfix(&stream) == 0);
}
char line[8]{};
Require(fgets_nid_postfix(line, sizeof(line), &stream) == line && std::strcmp(line, "line\n") == 0);
Expand All @@ -322,9 +318,15 @@ static void CheckFgetsSizeOne() {
rewind_nid_postfix(&stream);
char buffer[8];
std::memset(buffer, '!', sizeof(buffer));
Require(fgets_nid_postfix(buffer, 1, &stream) == buffer && buffer[0] == '\0' && buffer[1] == '!');
*__error_nid_postfix() = 0;
Require(fgets_nid_postfix(buffer, 1, &stream) == nullptr && buffer[0] == '!' && *__error_nid_postfix() == 0);
Require(ftello_nid_postfix(&stream) == 0 && ferror_nid_postfix(&stream) == 0 && feof_nid_postfix(&stream) == 0);
Require(fgets_nid_postfix(buffer, sizeof(buffer), &stream) == buffer && std::strcmp(buffer, "line\n") == 0);
Require(fgets_nid_postfix(buffer, sizeof(buffer), &stream) == nullptr && feof_nid_postfix(&stream) != 0);
std::memset(buffer, '!', sizeof(buffer));
*__error_nid_postfix() = 0;
Require(fgets_nid_postfix(buffer, 1, &stream) == nullptr && buffer[0] == '!' && *__error_nid_postfix() == 0);
Require(ftello_nid_postfix(&stream) == 5 && ferror_nid_postfix(&stream) == 0 && feof_nid_postfix(&stream) != 0);
stream.Close();
}

Expand Down
2 changes: 1 addition & 1 deletion docs/dev/debt/libc.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

- [strtoq](../../../core/libs/prx/libc/src/Strings.cpp) (libc, NID `yUUOxgk8Dmc`) is the BSD "quad" alias of `strtoll` and forwards to it, as FreeBSD 11.4 [strtoq.c](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/stdlib/strtoq.c) does. The console export is not verified; the sibling `strtouq` is already here.

- [fwide](../../../core/libs/prx/libc/src/StandardStreams.cpp) (libc) - the `printf` and `wprintf` families, `perror` and `putw` orient a stream as C11 7.21.2p4 requires, where FreeBSD 11.4's `vfprintf.c`, `vfwprintf.c`, `perror.c` and `putw.c` have no `ORIENT`; nothing is measured on a console. Otherwise it follows [FreeBSD 11.4 fwide.c](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/stdio/fwide.c#L38-L51) and `ORIENT`: the first byte or wide read, write, unget or scan orients a stream, also when `fgets`, `fgetws` or `ungetwc` then fail on their arguments; a zero-length `fread` or `fwrite` does not, and a successful `freopen` clears it. Mixed byte and wide calls still run. The export is in the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c#L17666)
- [fwide](../../../core/libs/prx/libc/src/StandardStreams.cpp) (libc) - the `printf` and `wprintf` families, `perror` and `putw` orient a stream as C11 7.21.2p4 requires, where FreeBSD 11.4's `vfprintf.c`, `vfwprintf.c`, `perror.c` and `putw.c` have no `ORIENT`; nothing is measured on a console. Otherwise it follows [FreeBSD 11.4 fwide.c](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/stdio/fwide.c#L38-L51) and `ORIENT`: the first byte or wide read, write, unget or scan orients a stream, also when `fgetws` or `ungetwc` then fail on their arguments, but not `fgets` with a size below 2, which returns before it touches the stream as the console's `fgets` does; a zero-length `fread` or `fwrite` does not, and a successful `freopen` clears it. Mixed byte and wide calls still run. The export is in the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c#L17666)

### Functional

Expand Down
Loading