Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert errno in UNIX to corresponding string?

Tags:

unix

errno

Is there any function in UNIX to the convert errno to its corresponding string for e.g. EIDRM to "EIDRM". Its very annoying to debug to check for errors with these integer errnos.

like image 874
avd Avatar asked Oct 10 '09 02:10

avd


People also ask

How do I print errno strings?

Your program can use the strerror() and perror() functions to print the value of errno. The strerror() function returns a pointer to an error message string that is associated with errno. The perror() function prints a message to stderr.

What is errno in Unix?

errno is defined by the ISO C standard to be a modifiable lvalue of type int, and must not be explicitly declared; errno may be a macro. errno is thread-local; setting it in one thread does not affect its value in any other thread. Error numbers and names Valid error numbers are all positive numbers.

How is errno used?

errno is a preprocessor macro used for error indication. It expands to a static (until C++11) thread-local (since C++11) modifiable lvalue of type int. Several standard library functions indicate errors by writing positive integers to errno .

What errno means?

It defines macros for reporting and retrieving error conditions using the symbol errno (short for "error number"). errno acts like an integer variable. A value (the error number) is stored in errno by certain library functions when they detect errors. At program startup, the value stored is zero.


2 Answers

strerror() should do it. http://linux.die.net/man/3/strerror

FYI, so that you can find these things more easily, yourself: If you type man errno (or whatever function you're investigating), and look at the very bottom of the man page, you'll see a list of related functions. If you man each of those (taking a guess about which one(s) to do first based on their names) you'll often find the answer to similar questions.

like image 89
atk Avatar answered Sep 29 '22 05:09

atk


Just another solution that solves exactly the problem you have, but in Python instead of C:

>>> import errno >>> errno.errorcode[errno.EIDRM] 'EIDRM' 
like image 30
Andrey Vlasovskikh Avatar answered Sep 29 '22 04:09

Andrey Vlasovskikh