I'm aware that the right use of freopen
is to omit the assignment, given this post:
freopen("/dev/tty","r", stdin);
My question is, should I still check the return value? I'm reopening stdin and closing whatever it was. For instance:
if(freopen("/dev/tty","r", stdin)==NULL) {
fprintf(stderr, "Unable to redirect stdin from file\n");
exit(1);
}
This documentation for freopen says:
So yes, you could check the return value against NULL to see if there's an error, or check errno.
Regarding your comment, the documentation says:
Based on "independently of whether that stream was successfuly closed or not", it seems possible that the original stream could be left open, or in an undefined state, if there's an error. In any case, this won't make any practical difference, since you wouldn't want to use the stream after freopen fails anyway.