C Programming Language
C Programming Language
In C programming language, there is no direct support for error handling. You have to
detect the failure and handle the error. In C programming language, return values
represents success or failure. Inside a C program, when a function fails, you should
handle the errors accordingly, or at least record the errors in a log file.
When you are running some program on Linux environment, you might notice that it
gives some error number. For example, “Error no is : 17”, which doesn’t really say much.
You really need to know what error number 17 means.
This article shows all available error numbers along with it descriptions. This article
might be a handy reference for you, when you encounter an error number and you
would like to know what it means.
$ cat fileopen.c
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
main()
// Opening a file
fd = open("/root/sasikala/testing",O_CREAT|O_EXCL);
// If Open is failed
if ( fd < 0 ) {
// If Open is success
else
$ cc -o fileopen fileopen.c
$ ./fileopen
Error no is : 17
At first execution, open got executed successfully, and it created the file since the file
was not available. In next execution, it throws an error number 17, which is “File already
exist”.