C++ Logo

std-proposals

Advanced search

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

From: Peter C++ <peter.cpp_at_[hidden]>
Date: Fri, 2 Sep 2022 12:32:33 +0200
I think it is doable and desirable. i even was of the impression it would already work,but at least not as of what is in the std.

issues:
- too few people understand iostreams ( i am one of the few who contributed over the last few revisions)
- ownership-transfer of an int ( ope. file descriptor) could only by convention
- on linux there is a workaround
- should adoption also work from a FILE*?
- can there be destruction without close?


Sent from Peter Sommerlad's iPad
+41 79 432 23 32

> On 2 Sep 2022, at 11:37, Paul Fee via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> 
> 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
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-09-02 10:32:36