| 1 |
'\" t |
| 2 |
.\" Copyright 2002, Andries E. Brouwer <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH assert_perror 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
assert_perror \- test errnum and abort |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
| 16 |
.B #include <assert.h> |
| 17 |
.P |
| 18 |
.BI "void assert_perror(int " errnum ); |
| 19 |
.fi |
| 20 |
.SH DESCRIPTION |
| 21 |
If the macro |
| 22 |
.B NDEBUG |
| 23 |
was defined at the moment |
| 24 |
.I <assert.h> |
| 25 |
was last included, the macro |
| 26 |
.BR assert_perror () |
| 27 |
generates no code, and hence does nothing at all. |
| 28 |
Otherwise, the macro |
| 29 |
.BR assert_perror () |
| 30 |
prints an error message to standard error and terminates the program |
| 31 |
by calling |
| 32 |
.BR abort (3) |
| 33 |
if |
| 34 |
.I errnum |
| 35 |
is nonzero. |
| 36 |
The message contains the filename, function name and |
| 37 |
line number of the macro call, and the output of |
| 38 |
.IR strerror(errnum) . |
| 39 |
.SH RETURN VALUE |
| 40 |
No value is returned. |
| 41 |
.SH ATTRIBUTES |
| 42 |
For an explanation of the terms used in this section, see |
| 43 |
.BR attributes (7). |
| 44 |
.TS |
| 45 |
allbox; |
| 46 |
lbx lb lb |
| 47 |
l l l. |
| 48 |
Interface Attribute Value |
| 49 |
T{ |
| 50 |
.na |
| 51 |
.nh |
| 52 |
.BR assert_perror () |
| 53 |
T} Thread safety MT-Safe |
| 54 |
.TE |
| 55 |
.SH STANDARDS |
| 56 |
GNU. |
| 57 |
.SH BUGS |
| 58 |
The purpose of the assert macros is to help programmers find bugs in |
| 59 |
their programs, things that cannot happen unless there was a coding mistake. |
| 60 |
However, with system or library calls the situation is rather different, |
| 61 |
and error returns can happen, and will happen, and should be tested for. |
| 62 |
Not by an assert, where the test goes away when |
| 63 |
.B NDEBUG |
| 64 |
is defined, |
| 65 |
but by proper error handling code. |
| 66 |
Never use this macro. |
| 67 |
.SH SEE ALSO |
| 68 |
.BR abort (3), |
| 69 |
.BR assert (3), |
| 70 |
.BR exit (3), |
| 71 |
.BR strerror (3) |