Why should I use fileno(stderr) instead of STDERR_FILENO
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 2. https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fileno?view=msvc-170 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. ..."
how to read table options during smgropen()
Dear pgsql hackers, I am developing custom storage for pgsql tables. I am using md* functions and smgrsw[] structure to switch between different magnetic disk access methods. I want to add some custom options while table created psql# create table t(...) with (my_option='value'); And thus I want to set "reln->smgr_which" conditionally during smgropen(). If myoption='value' i would use another smgr_which I am really stuck at this point. smgr.c: SMgrRelation smgropen(RelFileNode rnode, BackendId backend){ ... if ( HasOption(rnode, "my_option","value")){ //<< how to implement this check ? reln->smgr_which = 1; //new access method }else{ reln->smgr_which = 0; //old access method } ... } The question is --- can I read table options while the table is identified by "RelFileNode rnode" ?? The only available information is typedef struct RelFileNode { Oid spcNode; /* tablespace */ Oid dbNode; /* database */ Oid relNode; /* relation */ } RelFileNode; But there are no table options available directly from this structure. What is the best way to implement HasOption(rnode, "my_option","value") Thank you in advance for any ideas. Sincerely, Dmitry R