in reply to Re^2: readline succeeds but sets $! = EBADF
in thread readline succeeds but sets $! = EBADF

Does this mean that a function can change errno even if it succeeds?

Unfortunately, the general answer is yes. Some systems seem to handle errno better on success (Solaris?), but they are probably the exception and even then I wouldn't trust them 100%. There is a long history behind errno, most of it caused by poor initial "design" (if you can call it that), and it's definitely not going to change soon. If you check errno, you are signing a contract saying you have read the docs on the _specific_ call you are making. If it doesn't mention preservation of errno on success, chances are good that it probably doesn't.

You are right -- if you want to _really_ check for errors, in general you must jump through hoops with additional ugly code.

  • Comment on Re^3: readline succeeds but sets $! = EBADF