Why error handling is important in system programming
This recipe is a short introduction to what error handling is. We will also see an example of a common error: insufficient access rights. Knowing these basic skills will make you a better programmer in the long run.
Getting ready
For this recipe, you'll only need the GCC compiler, preferably installed via the meta-package or group install, as we covered in Chapter 1, Getting the Necessary Tools and Writing Our First Linux Programs. Make sure that the Makefile mentioned in the Technical requirements section is placed in the same directory as the source code for this recipe.
How to do it…
Follow these steps to explore a common error and how to handle it:
- First, we will write the program without any error handling (except the usual sanity checks for the arguments). Write the following program and save it as
simple-touch-v1.c
. The program will create an empty file that the user specifies as an argument...