C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A standard way to redirect all standard output

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 13 Mar 2023 11:49:15 -0700
On Monday, 13 March 2023 11:44:04 PDT Frederick Virchanza Gotham wrote:
> On Monday, March 13, 2023, Thiago Macieira via Std-Proposals <
>
> std-proposals_at_[hidden]> wrote:
> > Why can't you use freopen()?
>
> freopen needs a filename, it can only redirect to a file. The handle
> returned from fopencookie is a FILE* and you can't use 'fileno' to turn it
> into a file descriptor.

Oops. I saw your function declarations

> void stdout_redirect(char const *buf, size_t const len);
> void stderr_redirect(char const *buf, size_t const len);

And interpreted "char const*" as a file name, instead of what you meant.

Anyway, I think fopencookie, open_memstream and family are a good idea. You
should propose that to WG14. fmemopen and open_memstream are already part of
POSIX.1-2018. They're still missing a way to assign those new FILE* to
existing handles, so there's work to be done.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-03-13 18:49:17