I have function in C that assumes stdin is open. I want to add an assertion in front of it to make sure stdin is not closed by anyone. How can I check that stdin isn’t closed by anyone?
assert(is_open(stdin));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t find out whether a
FILE*has been closed.fclosemightfreetheFILEobject it points to, so that object’s contents may be undefined afterfclose. This is true even ofstdin. The solution I proposed previously was wrong. Sorry about that.The best you can do on a POSIX platform is something like
though that really tells you something about the standard input FD, rather than the
stdinobject.