This recipe represents the second side of the coin in the topic of error handling: error handling at a source-code level. Linux exposes its kernel features through commands, as well as through a programming API. In this recipe, we'll see how to deal with error codes and errno through a C program, to open a file.
Handling Linux code error
How to do it...
In this section, we'll see how to get the error from a system call in a C program. To do this, we'll create a program to open a non-existent file and show the details of the error returned by Linux:
- Create a new file: open_file.c.
- Edit the following code in the newly created file:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include...