Skip to content
Snippets Groups Projects
  • Colin Walters's avatar
    e30a773f
    fdio: Add cleanup+flush API for FILE* · e30a773f
    Colin Walters authored
    Mostly in ostree/rpm-ostree, we work in either raw `int fd`, or
    `G{Input,Output}Stream`.  One exception is the rpm-ostree `/etc/passwd`
    handling, which uses `FILE*` since that's what glibc exposes.
    
    And in general, there are use cases for `FILE*`; the raw `GUnixOutputStream` for
    example isn't buffered, and doing so via e.g. `GBufferedOutputStream` means
    allocating *two* GObjects and even worse going through multiple vfuncs for every
    write.
    
    `FILE*` is used heavily in systemd, and provides buffering. It is a bit cheaper
    than gobjects, but has its own trap; by default every operation locks a mutex.
    For more information on that, see `unlocked_stdio(3)`. However, callers can
    avoid that by using e.g. `fwrite_unlocked`, which I plan to do for most users of
    `FILE*` that aren't writing to one of the standard streams like `stdout` etc.
    e30a773f
    History
    fdio: Add cleanup+flush API for FILE*
    Colin Walters authored
    Mostly in ostree/rpm-ostree, we work in either raw `int fd`, or
    `G{Input,Output}Stream`.  One exception is the rpm-ostree `/etc/passwd`
    handling, which uses `FILE*` since that's what glibc exposes.
    
    And in general, there are use cases for `FILE*`; the raw `GUnixOutputStream` for
    example isn't buffered, and doing so via e.g. `GBufferedOutputStream` means
    allocating *two* GObjects and even worse going through multiple vfuncs for every
    write.
    
    `FILE*` is used heavily in systemd, and provides buffering. It is a bit cheaper
    than gobjects, but has its own trap; by default every operation locks a mutex.
    For more information on that, see `unlocked_stdio(3)`. However, callers can
    avoid that by using e.g. `fwrite_unlocked`, which I plan to do for most users of
    `FILE*` that aren't writing to one of the standard streams like `stdout` etc.