I do not agree with you in
perror et alii are members of the C standard library and as such are technically outdated (*).
Well, even on cplusplus.com, if not an official source of documentation, I see for errno:
C ++ 11 extends the basic set of values needed to be defined in this header ... In C ++, errno is always declared as a macro, but in C it can also be implemented as an int object with external connection.
My understanding of these suggestions is that errno is still being considered in C ++ 11!
I even see later
Libraries supporting multithreading must implement errno on each line: each thread has its own local errno. This is a requirement in libraries complying with C11 and C ++ 11 standards.
this means that even if strerror() not thread safe, errno is in any C ++ 11 compatible implementation.
Now you need to use std::strerror in a synchronized function (e.g. protected with a mutex) to build std::string if you want. But in any case, even if every documentation in strerror claims to use a static buffer that can be overwritten (why Posix 1 defines strerror_r), I could not find any warning in perror , which is not a safe stream.
(*) My opinion is that whenever OO and templates can provide a more convenient interface (iostream vs stdio.h or string vs. string.h), elements of the C library are replaced by others in the C ++ library. But when there is nothing to add (cerrno, cmath, csignal, etc.), Functions from the C standard library are simply included in C ++.
Serge Ballesta
source share