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: errno is 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 to perror(), the value of errno should 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 πŸ‘‘

  • errno
  • perror()
    • C11, POSIX.1-2008.
  • sys_nerr
  • sys_errlist
    • BSD.

πŸ’œ HISTORY πŸ’œ

  • errno
  • perror()
    • POSIX.1-2001, C89, 4.3BSD.
  • sys_nerr
  • sys_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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms