linux system call error codes ( errnos) to human readable error strings..



Q)   “I got an ‘errno’ returned from the system call and want to map to the exact error message or to the error string which is human readable..

How can I do that ??

This was answered quite few times, how-ever I forgot to share it here, but not this time.

Here is the complete listing of linux error code numbers with its explanation:


Why I pasted all these and From where I got it ?

1) ( Why )=> Ans: As a quick reference

2) ( From where) => ‘Errnos’ upto “35” is available in /usr/include/asm-generic/errno-base.h and >35 is available in /usr/include/asm-generic/errno.h


2 thoughts on “linux system call error codes ( errnos) to human readable error strings..”

  1. Hi Humble,

    Good piece of info. To add little more, to print the string related to errno from code itself, strerror() can be used. For eg:- Below code snippet prints the whole linux errors in human readable format.

    $ cat error_no.cpp

    using namespace std;

    int main()
    for (int i=1;i<=133;i++)
    cout< “<<i< “<<strerror(i)< 98 => Address already in use
    err no => 99 => Cannot assign requested address
    err no => 100 => Network is down
    err no => 101 => Network is unreachable

    An important point to note here is that, there is no standard call to map errno number to err code.

    1. Hi Nikhil,

      Thanks for this thought and comment!

      Yep, normally the error nos are mapped to strings with help of 2 functions.

      1) strerror()

      2) perror

      [1] something like this program o/p :

      [humble@lap ~]$ ./a.out 38

      Program to print err string
      Function not implemented
      [humble@lap ~]$ ./a.out 5

      Program to print err string
      Input/output error
      [humble@lap ~]$

      2) perror() should be used immediately or the ‘errno’ has to be saved for making a readable string.

      I wrote this blog when I was answering below query from my friend:

      1) ” How can I map the errno to the string.. I normally use ‘strerror()’, is there any source to map it” ? 🙂

      Also, sometimes debuggers/tracers gives ‘errno’s.

Leave a Reply

Your email address will not be published. Required fields are marked *