Fix edge cases and consolidate implementations of file I/O
- Dominant language
- C++
- Stars
- 1.6k
- Forks
- 193
- Avg merge
- 1d 33m
- Merged PRs (30d)
- 23
Description
RGBDS comprises four programs, all of which have multiple kinds of input and/or output. There are a number of issues with how they implement that:
- [ ] Implementations are scattered, often duplicating functionality (such as handling of `-` for stdin/stdout, including printing it as "``"/"``").
- [ ] `read()`/`fread()` might read fewer bytes than you requested, e.g. if the file is a pipe. That's not an error, it just means you need to loop more calls until finished.
- [ ] Unlimited-length [pseudo-device](https://en.wikipedia.org/wiki/Device_file#Pseudo-devices) files like `/dev/zero` and `/dev/urandom` can behave oddly. For example, `INCBIN "/dev/zero"` hangs indefinitely.
- [ ] Potential [TOCTTOU](https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use) race conditions between finding a definite file path among the `-I`nclude directories with `fstk_FindFile`, and actually opening the file.
We would probably benefit from more high-level C++ STL file I/O, since we're manually doing things with `read()`, `fread()`, `std::filebuf`, etc, when `std::ifstream` exists.
Contributor guide
Assessment
This issue has not been assessed yet.