1ERROR(3)                   Linux Programmer's Manual                  ERROR(3)
2
3
4

NAME

6       error,    error_at_line,    error_message_count,    error_one_per_line,
7       error_print_progname - glibc error reporting functions
8

SYNOPSIS

10       #include <error.h>
11
12       void error(int status, int errnum, const char *format, ...);
13
14       void error_at_line(int status, int errnum, const char *filename,
15                          unsigned int linenum, const char *format, ...);
16
17       extern unsigned int error_message_count;
18
19       extern int error_one_per_line;
20
21       extern void (*error_print_progname) (void);
22

DESCRIPTION

24       error() is a general error-reporting function.  It flushes stdout,  and
25       then  outputs to stderr the program name, a colon and a space, the mes‐
26       sage specified by the printf(3)-style format  string  format,  and,  if
27       errnum  is  nonzero,  a second colon and a space followed by the string
28       given by strerror(errnum).  Any arguments required  for  format  should
29       follow format in the argument list.  The output is terminated by a new‐
30       line character.
31
32       The program name printed by error() is the value of the global variable
33       program_invocation_name(3).   program_invocation_name initially has the
34       same value as main()'s argv[0].  The value of this variable can be mod‐
35       ified to change the output of error().
36
37       If  status has a nonzero value, then error() calls exit(3) to terminate
38       the program using the given value as the exit status.
39
40       The error_at_line() function is exactly the same as error(), except for
41       the  addition  of  the arguments filename and linenum.  The output pro‐
42       duced is as for error(), except that after the program name  are  writ‐
43       ten: a colon, the value of filename, a colon, and the value of linenum.
44       The preprocessor values __LINE__ and __FILE__ may be useful when  call‐
45       ing  error_at_line(),  but other values can also be used.  For example,
46       these arguments could refer to a location in an input file.
47
48       If the global variable error_one_per_line is set nonzero, a sequence of
49       error_at_line()  calls with the same value of filename and linenum will
50       result in only one message (the first) being output.
51
52       The global variable error_message_count counts the number  of  messages
53       that have been output by error() and error_at_line().
54
55       If  the global variable error_print_progname is assigned the address of
56       a function (i.e., is not NULL), then that function is called instead of
57       prefixing  the  message  with the program name and colon.  The function
58       should print a suitable string to stderr.
59

ATTRIBUTES

61       For  an  explanation  of  the  terms  used   in   this   section,   see
62       attributes(7).
63
64       ┌────────────────┬───────────────┬───────────────────────────────────┐
65Interface       Attribute     Value                             
66       ├────────────────┼───────────────┼───────────────────────────────────┤
67error()         │ Thread safety │ MT-Safe locale                    │
68       ├────────────────┼───────────────┼───────────────────────────────────┤
69error_at_line() │ Thread safety │ MT-Unsafe race:                   │
70       │                │               │ error_at_line/error_one_per_line  │
71       │                │               │ locale                            │
72       └────────────────┴───────────────┴───────────────────────────────────┘
73       The  internal error_one_per_line variable is accessed (without any form
74       of synchronization, but since it's an int used once, it should be  safe
75       enough)  and, if error_one_per_line is set nonzero, the internal static
76       variables (not exposed to users) used to hold the last printed filename
77       and  line number are accessed and modified without synchronization; the
78       update is not atomic and it occurs before disabling cancellation, so it
79       can  be  interrupted  only  after one of the two variables is modified.
80       After that, error_at_line() is very much like error().
81

CONFORMING TO

83       These functions and variables are GNU extensions,  and  should  not  be
84       used in programs intended to be portable.
85

SEE ALSO

87       err(3),  errno(3), exit(3), perror(3), program_invocation_name(3), str‐
88       error(3)
89

COLOPHON

91       This page is part of release 4.15 of the Linux  man-pages  project.   A
92       description  of  the project, information about reporting bugs, and the
93       latest    version    of    this    page,    can     be     found     at
94       https://www.kernel.org/doc/man-pages/.
95
96
97
98GNU                               2017-09-15                          ERROR(3)
Impressum