bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: On recent windows fileno return -2 in case of closed stdin, stdout,


From: Bastien ROUCARIES
Subject: Re: On recent windows fileno return -2 in case of closed stdin, stdout, stderr
Date: Mon, 6 Apr 2020 21:42:19 +0200

On Mon, Apr 6, 2020 at 8:32 PM Bruno Haible <address@hidden> wrote:
>
> Hi Bastien,
>
> > according to 
> > https://docs.microsoft.com/fr-fr/cpp/c-runtime-library/reference/fileno?view=vs-2019
> >
> > If stdout or stderr is not associated with an output stream (for
> > example, in a Windows application without a console window), the file
> > descriptor returned is -2. In previous versions, the file descriptor
> > returned was -1. This change allows applications to distinguish this
> > condition from an error.
>
> Indeed, that's a deviation from POSIX [1].
>
> > This should be mentionned in the doc:
> > A work arround is to create a console at the beginning of the program
> > and close the window.
> >
> > if(AllocConsole())
> > {
> >     freopen ("CONOUT$", "w", stdout);
> >     freopen ("CONOUT$", "w", stderr);
> >     ShowWindow (FindWindowA ("ConsoleWindowClass", NULL), false);
> > }
>
> The programs for which gnulib is most often used (coreutils etc.) don't
> deal with consoles and windows directly; they just use stdout, stderr
> as they are.
>
> So the workaround would have to be in a 'fileno' module.

I can but I do not know how to do. does -2 is a valid fd on windows ?
>
> Would you like to contribute such a 'fileno' module?
>
> Bruno
>
> [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/fileno.html
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]