Handling some common errors
In this recipe, we will look at some common errors we can handle. Knowing what errors to look for is step one of mastering error handling. A police officer can't catch the bad guys if they don't know which crimes to look for.
We will look at both errors that can occur due to resource limitations on a computer, permission errors, and mathematical errors. It's important to remember, though, that most functions return a special value (often -1 or some predefined value) when errors occur. The actual data is returned when no errors occur.
We will also briefly touch on the subject of handling buffer overflows. Buffer overflows are a vast subject that deserves a book of its own, but some short examples can help.
Getting ready
In this recipe, we'll write shorter code samples and compile them with GCC and Make. We'll also read some man pages from the POSIX Programmer's Manual. If you are using Debian or Ubuntu, you have to...