C++ Logo

std-proposals

Advanced search

[std-proposals] Construct an iostream from a file descriptor

From: Paul Fee <paul.f.fee_at_[hidden]>
Date: Fri, 2 Sep 2022 10:36:56 +0100
Hello,

POSIX defines fdopen(), which takes ownership of a low level file
descriptor and returns a FILE* with which a user can perform buffered I/O.
There doesn't appear to be a similar feature in C++, though non-standard
workarounds exist, such as __gnu_cxx::stdio_filebuf.

https://stackoverflow.com/questions/2746168/how-to-construct-a-c-fstream-from-a-posix-file-descriptor

Are there issues that would block standardisation of such a facility?
Perhaps it's because fdopen() is part of POSIX rather than ISO C, hence
file descriptors themselves may not be universally portable. Does that in
turn mean that the standard library can't provide functionality that
depends on a POSIX feature? Would it be feasible to provide this feature
only on platforms where file descriptors exist?

Thanks,
Paul

Received on 2022-09-02 09:37:07