strerror(3)
๐ strerror, strerrorname_np, strerrordesc_np, strerror_r, strerror_l ๐
okay so welcome to strerror(3), lovingly ripped from the Library Functions Manual, and it's giving "the entire friend group that turns a chaotic little error number into actual words." bestie, they all do the same vibe, just with different โจpersonalitiesโจ.
๐ธ NAME ๐ธ
strerror,strerrorname_np,strerrordesc_np,strerror_r,strerror_lโ string error-string
๐ LIBRARY ๐
Standard C library (libc, -lc). that's the one, no cap ๐ซถ
โจ SYNOPSIS โจ
#include <string.h>
char *strerror(int errnum);
const char *strerrorname_np(int errnum);
const char *strerrordesc_np(int errnum);
int strerror_r(size_t size;
int errnum, char buf[size], size_t size);
/* XSI-compliant */
char *strerror_r(size_t size;
int errnum, char buf[size], size_t size);
/* GNU-specific */
char *strerror_l(int errnum, locale_t locale);
๐ง Feature Test Macro Requirements for glibc
(peep feature_test_macros(7) for the tea, bestie)
strerrorname_np(), strerrordesc_np():
_GNU_SOURCE
strerror_r():
The XSI-compliant version is provided if:
(_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
Otherwise, the GNU-specific version is provided.
๐ DESCRIPTION ๐
so strerror() hands you back a pointer to a string that describes whatever error code you passed in as errnum โ and yes, it might use the LC_MESSAGES part of your current locale to pick the right language. (like, if errnum is EINVAL, the description it gives you is "Invalid argument". iconic.) ๐
careful though: your app must not modify this string, and that returned pointer gets invalidated on a subsequent call tostrerror()orstrerror_l(), OR if the thread that grabbed the string justโฆ exits. ๐ no other library function โ includingperror(3)โ will touch this string.
Like strerror(), the strerrordesc_np() function returns a pointer to a string that describes the error code passed in the argument errnum, but with one glow-up difference: the returned string is not translated according to the current locale. so it's the no-makeup version, fr fr.
The strerrorname_np() function returns a pointer to a string containing the name of the error code passed in the argument errnum. for example, hand it EPERM and you get back a pointer to the string "EPERM". hand it 0 and โ plot twist ๐ โ you get back a pointer to the string "0".
๐ strerror_r()
strerror_r() is like strerror(), but it might use the buffer you supplied (buf) instead of allocating one internally. little miss independent โจ
and there are two versions of her:
- XSI-compliant version โ specified in POSIX.1-2001 (available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13)
- GNU-specific version โ available since glibc 2.0
you get the XSI-compliant one when the feature test macros are set up like in the SYNOPSIS; otherwise it's GNU-specific that shows up. and if no feature test macros are explicitly defined, then (since glibc 2.4) _POSIX_C_SOURCE is defined by default with the value 200112L, so the XSI-compliant version of strerror_r() is what you get by default. slay, defaults. ๐
The XSI-compliant strerror_r() is the one you want for portable applications โ periodt. it returns the error string in your user-supplied buffer buf of size size.
The GNU-specific strerror_r() returns a pointer to a string containing the error message. this may be either a pointer to a string the function stores in buf, or a pointer to some (immutable) static string โ in which case buf is just sitting there unused, ignored, unbothered ๐. if the function does store a string in buf, then at most size bytes are stored (and yeah, the string may get truncated if size is too small and errnum is unknown). the string always includes a terminating null byte ('\0'). always, bestie.
๐ strerror_l()
strerror_l() is like strerror(), but it maps errnum to a locale-dependent error message in the locale specified by locale.
โ ๏ธ undefined behaviour alert: the behavior ofstrerror_l()is undefined iflocaleis the special locale objectLC_GLOBAL_LOCALE, or if it isn't a valid locale object handle. don't do it. i'm begging. ๐ญ
๐ซถ RETURN VALUE ๐ซถ
strerror(), strerror_l(), and the GNU-specific strerror_r() return the appropriate error description string โ or, if the error number is unknown, an "Unknown error nnn" message. that's the fallback fit, and it ate. ๐
On success, strerrorname_np() and strerrordesc_np() return the appropriate error description string. but if errnum is an invalid error number, these functions return NULL. ๐
The XSI-compliant strerror_r() function returns 0 on success. on error, it returns a (positive) error number (since glibc 2.13) โ or, before glibc 2.13, it returned -1 and set errno to indicate the error.
POSIX.1-2001 and POSIX.1-2008 require that a successful call to strerror() or strerror_l() shall leave errno unchanged, and they note that โ since no function return value is reserved to indicate an error โ an application that wishes to check for errors should initialize errno to zero before the call, and then check errno after the call. that's the whole strategy. write it down. ๐
๐ ERRORS ๐
EINVALโ The value oferrnumis not a valid error number.ERANGEโ Insufficient storage was supplied to contain the error description string.
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, see attributes(7).
strerror()โ Thread safety:MT-Safestrerrorname_np(),strerrordesc_np()โ Thread safety:MT-Safestrerror_r(),strerror_l()โ Thread safety:MT-Safe
throwback: Before glibc 2.32, strerror() is not MT-Safe. so if you're on ancient glibc, tread lightly, queen. ๐
โญ STANDARDS โญ
strerror()
C11,POSIX.1-2008.
strerror_r(), strerror_l()
POSIX.1-2008.
strerrorname_np(), strerrordesc_np()
GNU.
also, the lore: POSIX.1-2001 permits strerror() to set errno if the call encounters an error, but it does not specify what value should be returned as the function result in the event of an error. on some systems, strerror() returns NULL if the error number is unknown. on other systems, strerror() returns a string something like "Error nnn occurred" and sets errno to EINVAL if the error number is unknown. C99 and POSIX.1-2008 require the return value to be non-NULL. soโฆ systems differ, bestie. iykyk. ๐
๐ฆ HISTORY ๐ฆ
strerror()
POSIX.1-2001,C89.
strerror_r()
POSIX.1-2001.
strerror_l()
- glibc 2.6.
POSIX.1-2008.
strerrorname_np(), strerrordesc_np()
- glibc 2.32.
๐ NOTES ๐
strerrorname_np() and strerrordesc_np() are thread-safe and async-signal-safe. multitasking queens, no notes. ๐
๐ฅ SEE ALSO ๐ฅ
err(3), errno(3), error(3), perror(3), strsignal(3), locale(7), signal-safety(7)
and that's the whole page, bestie ๐ซถ this lil masterpiece is from Linux man-pages 6.20, dated 2026-07-26, and it's the strerror(3) entry. go forth and turn your error numbers into words. mwah ๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- Copyright 2005-2020, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms