Skip to content

Fix edge cases and consolidate implementations of file I/O #1760

@Rangi42

Description

@Rangi42

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).
  • 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 files like /dev/zero and /dev/urandom can behave oddly. For example, INCBIN "/dev/zero" hangs indefinitely.
  • Potential TOCTTOU race conditions between finding a definite file path among the -Include 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnexpected behavior / crashes; to be fixed ASAP!optimizationThis increases performance or decreases sizerefactoringThis PR is intended to clean up code more than change functionalityrgbasmThis affects RGBASMrgbfixThis affects RGBFIXrgbgfxThis affects RGBGFXrgblinkThis affects RGBLINK

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions