Why should I use fileno(stderr) instead of STDERR_FILENO - Mailing list pgsql-hackers

From Dima Rybakov (Tlt)
Subject Why should I use fileno(stderr) instead of STDERR_FILENO
Date
Msg-id CAH898o7kUvqRN64wgHXPJv3ZA3cX-o_FkZzNpmNzW3jJP9CAmA@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Dear pgsql hackers,

I found a mixture of fileno(stderr) and STDERR_FILENO in PostgreSQL source code which in most cases mean the same. But I have found recently that Microsoft's fileno() _fileno() can return -2 sometimes. After some experiments I found that applications running as windows service have problems with stderr. I.e. fileno(stderr) returns -2 (negative two) in windows service mode. That causes some issues with the logging collector. Meanwhile the value of STDERR_FILENO always equals 2 and does not depend on application mode because it is a macro.

I wonder if there are hidden advantages of using fileno(stderr) ?? Should I use  only "fileno(stderr)" or using STDERR_FILENO is acceptable too ?? Are there cases when I should not use STDERR_FILENO  ??

Sincerely,
Dmitry


Additional references
1. BUG #18400
Quote: "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. ..."

pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: Parallel CREATE INDEX for BRIN indexes
Next
From: Dmitry Koterov
Date:
Subject: Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine)