perror(3)
π perror(3) β the manual page, bestie edition π
okay so this is perror(3) from the Library Functions Manual and honestly? she's a little legend. she takes your cryptic error number and turns it into words a human can read. no cap. let's get into it π«Ά
β¨ NAME β¨
perror β print a system error message
likeβ¦ that's it. that's the whole job. and she does it flawlessly π
π LIBRARY π
Standard C library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <stdio.h>
void perror(const char *s);
#include <errno.h>
int errno; /* Not really declared this way; see errno(3) */
[[deprecated]] const char *const sys_errlist[];
[[deprecated]] int sys_nerr;
π§ Feature Test Macro Requirements for glibc (see feature_test_macros(7)) π§
for sys_errlist, sys_nerr:
- From glibc 2.19 to glibc 2.31:
_DEFAULT_SOURCE
- glibc 2.19 and earlier:
_BSD_SOURCE
β οΈ heads up bestie β those two are marked [[deprecated]] for a reason. keep reading, i'll spill. π
π¦ DESCRIPTION π¦
perror() writes a message to standard error describing the last error that happened during a call to a system or library function. it's basically the translator between "errno said 2" and "ohhh that's what went wrong."
first off β if s is not NULL and *s is not a null byte ('\0') β then your argument string s gets printed, followed by a colon and a blank. then comes the error message that matches the current value of errno, and then a new-line. cute little sandwich, isn't it π₯ͺβ¨
to be of most use, the argument string should include the name of the function that incurred the error. like, that's the whole vibe β tell people where it broke.
the global error list sys_errlist[], which can be indexed by errno, can be used to obtain the error message without the newline. the largest message number provided in the table is sys_nerr-1. be careful when directly accessing this list, because new error values may not have been added to sys_errlist[]. and the use of sys_errlist[] is nowadays deprecated β use strerror(3) instead. not me being the messenger for the deprecation notice π
when a system call fails, it usually returns -1 and sets the variable errno to a value describing what went wrong. (these values can be found in <errno.h>.) many library functions do likewise. perror() exists to translate that error code into human-readable form.
π REAL TALK WARNING:errnois undefined after a successful system call or library function call. this call may well change this variable, even though it succeeds β for example because it internally used some other library function that failed. so if a failing call is not immediately followed by a call toperror(), the value oferrnoshould be saved. save it, bestie. don't let it get away. π«Ά
π₯ ATTRIBUTES π₯
for an explanation of the terms used in this section, see attributes(7).
perror()β Thread safety βMT-Safe race:stderr
that's the whole table, we love a one-row moment π
π STANDARDS π
errnoperror()- C11, POSIX.1-2008.
sys_nerrsys_errlist- BSD.
π HISTORY π
errnoperror()- POSIX.1-2001, C89, 4.3BSD.
sys_nerrsys_errlist- Removed in glibc 2.32.
so yeah, sys_nerr and sys_errlist got β¨ yeeted β¨ in glibc 2.32. told you the deprecation was real π
π SEE ALSO π
err(3), errno(3), error(3), strerror(3)
and that's the whole page, bestie! this one's from Linux man-pages 6.20, dated 2026-02-08, and it's giving exactly what it needed to give πβ¨π go forth and perror() responsibly π¦
π¦ 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: GPL-2.0-or-later
- Copyright 1996, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms