std::strerror(3)
π std::strerror π
Okay bestie, this is the std::strerror page from the C++ Standard Libary manual β yes, the manual-name situation is folded up here near the top so we can get straight to the good stuff. β¨
β¨ NAME β¨
std::strerror β std::strerror. Thatβs the name, no cap, itβs giving βfunction named exactly after itselfβ energy. π
π¦ Synopsis π¦
Defined in header <cstring>:
char* strerror( int errnum );
Returns a pointer to the textual description of the system error code errnum, identical to the description that would be printed by std::perror().
errnum is usually acquired from the errno variable, however the function accepts any value of type int. The contents of the string are locale-specific.
The returned string must not be modified by the program, but may be overwritten by a subsequent call to the strerror function. strerror is not required to be thread-safe. Implementations may be returning different pointers to static read-only string literals or may be returning the same pointer over and over, pointing at a static buffer in which strerror places the string.
π Parameters π
errnumβ integer value referring to an error code.
π Return value π
Pointer to a null-terminated byte string corresponding to the errno error code errnum. Slay. β¨
π§ Notes π§
POSIX allows subsequent calls to strerror to invalidate the pointer value returned by an earlier call. It also specifies that it is the LC_MESSAGES locale facet that controls the contents of these messages.
POSIX has a thread-safe version called strerror_r defined. Glibc defines an incompatible version. Incompatible is the key word there, bestie. π
πΈ Example πΈ
// Run this code
#include <cerrno>
#include <clocale>
#include <cmath>
#include <cstring>
#include <iostream>
int main()
{
const double not_a_number = std::log(-1.0);
std::cout << not_a_number << '\n';
if (errno == EDOM)
{
std::cout << "log(-1) failed: " << std::strerror(errno) << '\n';
std::setlocale(LC_MESSAGES, "de_DE.utf8");
std::cout << "Or, in German, " << std::strerror(errno) << '\n';
}
}
Possible output:
nan
log(-1) failed: Numerical argument out of domain
Or, in German, Das numerische Argument ist ausserhalb des Definitionsbereiches
π See also π
perrorβ displays a character string corresponding of the current error to stderr (function).E2BIG,EACCES, ...,EXDEVβ macros for standard POSIX-compatible error conditions (macro constant).- C documentation for
strerrorβ the C side of the lore. π«Ά
And thatβs the whole page, bestie! Source/version/date tea: http://cppreference.com, 2024.06.10, and this manual page is std::strerror(3). Mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms