Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

error / error_at_line / error_message_count - glibc

Split from the chapter glibc: stdio and Formatted I/O into the per-function layout; see the method page and the glibc ledger for coverage status.

FieldValue
IDGLIBC-error (group)
Headererror.h
ProvenanceGNU
Statusdocumented

Signature – void error(int status, int errnum, const char *format, ...); void error_at_line(int status, int errnum, const char *fname, unsigned int lineno, const char *format, ...); plus globals unsigned int error_message_count;, int error_one_per_line;, void (*error_print_progname)(void);

Semantics – the GNU Coding Standard printer. error flushes stdout, then writes to stderr: program name (program_invocation_name by default, or via the error_print_progname hook), ": ", the formatted message, and – if errnum is nonzero – ": " plus strerror(errnum), newline-terminated (error(3), manual, Error Messages). Passing the error number explicitly fixes the classic perror defect that errno may have been clobbered between failure and report. If status is nonzero the process exits with that status; otherwise error_message_count increments. error_at_line inserts fname:lineno after the program name for input-file diagnostics; setting error_one_per_line nonzero suppresses consecutive duplicates for the same file and line (only immediately adjacent repeats, manual). The header decorates both with format(printf, ...) so GCC checks arguments.

Thread safety – error is MT-Safe; error_at_line’s one-per-line state is unsynchronized (manual safety annotations).