lua-users home
lua-l archive

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


I think it can be done reliably under wIndows. But I guess this is
academic if it cant be done under unix.

BTB. I was answering the question of how to tell if stdin/stdout/stderr
has been closed (or never opened).

I think I preferred the Lua 5.0 behaviour.

db

On 4/19/07, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> For windows:
>
>   _get_osfhandle(_fileno(stdout))  > 0
>
> means valid.

Unix has fileno, but if stdio is recycling FILE* then it probably is also
recycling filenos. So opening a file right after closing stdin will probably
create a file whose fileno is 0. That's the whole problem. As far I can see,
there is no reliable way to tell whether a FILE* or fileno corresponds to
the original stdin that was open when the process started.
--lhf