Why should I use fileno(stderr) instead of STDERR_FILENO

Поиск
Список
Период
Сортировка
От Dima Rybakov (Tlt)
Тема Why should I use fileno(stderr) instead of STDERR_FILENO
Дата
Msg-id CAH898o7kUvqRN64wgHXPJv3ZA3cX-o_FkZzNpmNzW3jJP9CAmA@mail.gmail.com
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: Parallel CREATE INDEX for BRIN indexes
Следующее
От: Dmitry Koterov
Дата:
Сообщение: Re: In MacOS, psql reacts on SIGINT in a strange fashion (Linux is fine)