This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

strerror_r -- GNU version


I note that for all known error numbers, the current implementation of GNU strerror_r() returns a pointer to a constant string (and not the supplied buffer).

So I can use GNU strerror_r() to distinguish known error numbers from unknown (or invalid) ones.

But to do so I am depending on an undocumented feature of the implementation (of a non-standard function) -- which is a worry :-(

I note that the POSIX (XSI) strerror_r() may return EINVAL for invalid error numbers. And invalid appears to include unknown numbers. But that cannot be relied on, either.

Is there a good standard/portable way to distinguish known error numbers ?

Inspection of the (recent) glibc implementation of POSIX (XSI) strerror_r() tells me that (a) it does return EINVAL for unknown errors, and (b) it uses GNU strerror_r() and checks the return address to detect known/unknown errors.

On a you-know-and-I-know-it-works basis I could depend on the same trick, if _GNU_SOURCE... But I guess I have to expect to be bitten in the backside at some time in the future ?

FWIW: I wish there was a portable way to map error numbers to their macro names (or at least a preferred macro name), which could double as a way to discover whether an error number is known or not.

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]