How you detect an error obviously depends on the mechanism reporting it. In practical terms, this means:
You determine whether a function failed by looking at its return code. This failure test is bound tightly to the act of calling the function; by making the call, you are implicitly checking its success. Whether or not you do anything with that information is up to you.
After calling a function, you must inspect the error status
variable. If it follows C's
model of operation, you don't actually need to test for errors after
every single function call. First reset
errno, and then call any number of standard library
functions back-to-back. Afterward, inspect
errno. If it contains an error ...