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.
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.
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.
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 .
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.
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.
Just another solution that solves exactly the problem you have, but in Python instead of C:
>>> import errno >>> errno.errorcode[errno.EIDRM] 'EIDRM'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With