sys_errlist
is a handy array which allows getting static errno
descriptions. The alternative to it is the strerror_r
function, which is available in two confusing incompatible flavors. The GNU version of it returns char *
, which would be from that same aforementioned array as long as the error is known, or otherwise from the user-supplied buffer. The standards-compliant version of strerror_r
returns an int
instead, and always uses the user-supplied buffer. The problem is, those two functions share the same name despite having completely different semantics, so you basically have to perform a fairly complex #ifdef
check and write two completely different versions of your code depending on which version you get. In addition to that, both of those functions are worse than sys_errlist
, as both require for the caller to provide a "large enough" buffer to hold the description, even though the GNU version would rarely use it, and neither function allows to know just how large the buffer should really be. If instead you choose to use sys_errlist
instead, you can simply check whether value >= sys_nerr
and allocate the buffer only in that case, just to put the Unknown error %d
there via snprintf
, and be done.
Given that strerror_r
is a horrible, incomprehensible and inefficient mess, why did GNU developers mark sys_errlist
as deprecated, effectively forcing one to either use strerrror_r
or to observe the ugly warning each time the code is compiled?
sys_errlist
is a static array and is completely thread safe. – Yulan