STRERROR(3POSIX)
π STRERROR(3POSIX) π
okay bestie, so this is the POSIX Programmer's Manual version of strerror(3POSIX), and it's literally the group chat for turning those cursed errno numbers into actual human words. iykyk. π¦
πΈ PROLOG πΈ
bestie real talk for one sec: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. orrrr the interface might just not be implemented on Linux at all. so like. vibe check your platform first. π
β¨ NAME β¨
strerror, strerror_l, strerror_r β get error message string. that's it. that's the whole job. and they ate. π
π SYNOPSIS π
#include <string.h>
char *strerror(int errnum);
char *strerror_l(int errnum, locale_t locale);
int strerror_r(int errnum, char *strerrbuf, size_t buflen);
π DESCRIPTION π
not me explaining strerror() first π
okay so the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional β like, not on purpose at all. This volume of POSIX.1β2017 defers to the ISO C standard. the ISO C standard is the main character here, fr.
The strerror() function shall map the error number in errnum to a locale-dependent error message string and shall return a pointer to it. Typically, the values for errnum come from errno, but strerror() shall map any value of type int to a message. literally any int. no gatekeeping. π
The application shall not modify the string returned. π«
The returned string pointer might be invalidated or the string content might be overwritten by a subsequent call to strerror(), or by a subsequent call to strerror_l() in the same thread. The returned pointer and the string content might also be invalidated if the calling thread is terminated. so like, don't hold onto it, bestie, it's giving temporary. π
The string may be overwritten by a subsequent call to strerror_l() in the same thread. yes, again. it's important.
The contents of the error message strings returned by strerror() should be determined by the setting of the LC_MESSAGES category in the current locale. π
The implementation shall behave as if no function defined in this volume of POSIX.1β2017 calls strerror().
The strerror() and strerror_l() functions shall not change the setting of errno if successful. periodt.
Since no return value is reserved to indicate an error of strerror(), an application wishing to check for error situations should set errno to 0, then call strerror(), then check errno. Similarly, since strerror_l() is required to return a string for some errors, an application wishing to check for all error situations should set errno to 0, then call strerror_l(), then check errno. it's giving detective work πβ¨
The strerror() function need not be thread-safe. π
strerror_l() era π§
The strerror_l() function shall map the error number in errnum to a locale-dependent error message string in the locale represented by locale and shall return a pointer to it.
strerror_r() girlies rise π«Ά
The strerror_r() function shall map the error number in errnum to a locale-dependent error message string and shall return the string in the buffer pointed to by strerrbuf, with length buflen. you bring your own buffer. it's giving BYOB (bring your own buffer). π
the message rules π
If the value of errnum is a valid error number, the message string shall indicate what error occurred; if the value of errnum is zero, the message string shall either be an empty string or indicate that no error occurred; otherwise, if these functions complete successfully, the message string shall indicate that an unknown error occurred. three whole vibes. iconic.
π¨ UNDEFINED BEHAVIOR ALERT π¨ The behavior is undefined if thelocaleargument tostrerror_l()is the special locale objectLC_GLOBAL_LOCALEor is not a valid locale object handle. do not do this. i am begging. π
β RETURN VALUE β
Upon completion, whether successful or not, strerror() shall return a pointer to the generated message string. On error errno may be set, but no return value is reserved to indicate an error. so you always get a pointer, you just don't get to know if it was a good time or not. π’
Upon successful completion, strerror_l() shall return a pointer to the generated message string. If errnum is not a valid error number, errno may be set to [EINVAL], but a pointer to a message string shall still be returned. If any other error occurs, errno shall be set to indicate the error and a null pointer shall be returned.
Upon successful completion, strerror_r() shall return 0. Otherwise, an error number shall be returned to indicate the error. simple. clean. slay. β¨
π₯ ERRORS π₯
These functions may fail if:
EINVALβ The value oferrnumis neither a valid error number nor zero.
The strerror_r() function may fail if:
ERANGEβ Insufficient storage was supplied viastrerrbufandbuflento contain the generated message string. your buffer was too small bestie, it's giving tight fit π
The following sections are informative. (yes, for real, everything from here on out is the informative zone π)
π EXAMPLES π
None.
...yeah that's it. nothing. the void. π
π¦ APPLICATION USAGE π¦
Historically in some implementations, calls to perror() would overwrite the string that the pointer returned by strerror() points to. Such implementations did not conform to the ISO C standard; however, application developers should be aware of this behavior if they wish their applications to be portable to such implementations. so like, ancient lore, but keep it in mind if you're traveling back in time with your code. β³
πΈ RATIONALE πΈ
The strerror_l() function is required to be thread-safe, thereby eliminating the need for an equivalent to the strerror_r() function. we love a two-birds-one-stone situation. π¦π¦
Earlier versions of this standard did not explicitly require that the error message strings returned by strerror() and strerror_r() provide any information about the error. This version of the standard requires a meaningful message for any successful completion. glow up. π
Since no return value is reserved to indicate a strerror() error, but all calls (whether successful or not) must return a pointer to a message string, on error strerror() can return a pointer to an empty string or a pointer to a meaningful string that can be printed.
Note that the [EINVAL] error condition is a may fail error. If an invalid error number is supplied as the value of errnum, applications should be prepared to handle any of the following:
- Error (with no meaningful message):
errnois set to[EINVAL], the return value is a pointer to an empty string. - Successful completion:
errnois unchanged and the return value points to a string like"unknownerror"or"errornumberxxx"(wherexxxis the value oferrnum). - Combination of #1 and #2:
errnois set to[EINVAL]and the return value points to a string like"unknownerror"or"errornumberxxx"(wherexxxis the value oferrnum).
Since applications frequently use the return value of strerror() as an argument to functions like fprintf() (without checking the return value) and since applications have no way to parse an error message string to determine whether errnum represents a valid error number, implementations are encouraged to implement #3. Similarly, implementations are encouraged to have strerror_r() return [EINVAL] and put a string like "unknownerror" or "errornumberxxx" in the buffer pointed to by strerrbuf when the value of errnum is not a valid error number. like, devs are BEGGING for #3, do it for them. π₯Ί
Some applications rely on being able to set errno to 0 before calling a function with no reserved value to indicate an error, then call strerror(errno) afterwards to detect whether an error occurred (because errno changed) or to indicate success (because errno remained zero). This usage pattern requires that strerror(0) succeed with useful results. Previous versions of the standard did not specify the behavior when errnum is zero. now they do. character development. π
π FUTURE DIRECTIONS π
None.
again. nothing. the future is quiet. π
π SEE ALSO π
perror()- The Base Definitions volume of POSIX.1β2017,
<string.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
okay that's the whole thing, bestie!! this was brought to you by IEEE/The Open Group, dated 2017, and it's filed under STRERROR(3POSIX) πβ¨ go forth and read your errno messages, you absolute icon ππ¦
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms