Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


error(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |ATTRIBUTES |STANDARDS |SEE ALSO |COLOPHON

error(3)                 Library Functions Manualerror(3)

NAME        top

       error, error_at_line, error_message_count, error_one_per_line,       error_print_progname - glibc error reporting functions

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <error.h>void error(intstatus, interrnum, const char *format, ...);void error_at_line(intstatus, interrnum, const char *file,unsigned intline, const char *format, ...);extern unsigned interror_message_count;extern interror_one_per_line;extern typeof(void (void))  *error_print_progname;

DESCRIPTION        top

error() is a general error-reporting function.  It flushesstdout,       and then outputs tostderr the program name, a colon and a space,       the message specified by theprintf(3)-style format stringformat,       and, iferrnum is nonzero, a second colon and a space followed by       the string given bystrerror(errnum).  Any arguments required forformat should followformat in the argument list.  The output is       terminated by a newline character.       The program name printed byerror() is the value of the global       variableprogram_invocation_name(3).program_invocation_name       initially has the same value asmain()'sargv[0].  The value of       this variable can be modified to change the output oferror().       Ifstatus has a nonzero value, thenerror() callsexit(3) to       terminate the program using the given value as the exit status;       otherwise it returns after printing the error message.       Theerror_at_line() function is exactly the same aserror(),       except for the addition of the argumentsfile andline.  The       output produced is as forerror(), except that after the program       name are written: a colon, the value offile, a colon, and the       value ofline.  The preprocessor values__LINE__and__FILE__may       be useful when callingerror_at_line(), but other values can also       be used.  For example, these arguments could refer to a location       in an input file.       If the global variableerror_one_per_line is set nonzero, a       sequence oferror_at_line() calls with the same value offile andline will result in only one message (the first) being output.       The global variableerror_message_count counts the number of       messages that have been output byerror() anderror_at_line().       If the global variableerror_print_progname is assigned the       address of a function (i.e., is not NULL), then that function is       called instead of prefixing the message with the program name and       colon.  The function should print a suitable string tostderr.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7).       ┌─────────────────┬───────────────┬──────────────────────────────┐       │InterfaceAttributeValue│       ├─────────────────┼───────────────┼──────────────────────────────┤       │error()         │ Thread safety │ MT-Safe locale               │       ├─────────────────┼───────────────┼──────────────────────────────┤       │error_at_line() │ Thread safety │ MT-Unsafe race:              │       │                 │               │ error_at_line/               │       │                 │               │ error_one_per_line locale    │       └─────────────────┴───────────────┴──────────────────────────────┘       The internalerror_one_per_line variable is accessed (without any       form of synchronization, but since it's anint used once, it       should be safe enough) and, iferror_one_per_line is set nonzero,       the internal static variables (not exposed to users) used to hold       the last printed filename and line number are accessed and       modified without synchronization; the update is not atomic and it       occurs before disabling cancelation, so it can be interrupted only       after one of the two variables is modified.  After that,error_at_line() is very much likeerror().

STANDARDS        top

       GNU.

SEE ALSO        top

err(3),errno(3),exit(3),perror(3),program_invocation_name(3),strerror(3)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-06-05error(3)

Pages that refer to this page:err(3)errno(3)perror(3)strerror(3)sysexits.h(3head)


Copyright and license for this manual page


HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp