Ah. That looks much more to the point :) I like this fcntl()
-based solution better than sgifford's solution (print nothing) because it more directly answers the question at hand. Which is not to say that sgifford's solution is bad; it has the advantage that it will catch some writability problems not related to how the handle was opened, plus it looks less complex to the human reader of your code.
Unfortunately, I'm doing this on Win32 :( Win32 doesn't implement the fcntl() function, so I'll go with the 'print nothing' solution for now.
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."