err 2.0.0
Small error-printing library written in C
Loading...
Searching...
No Matches
Functions | Variables
err.h File Reference

Header file. More...

#include <stdarg.h>
Include dependency graph for err.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void vwarn (const char *, va_list)
 Prints a formatted warning message to stderr. More...
 
void vewarn (const char *, va_list)
 Prints a formatted error message to stderr. More...
 
void verr (const char *, va_list)
 Prints a formatted error message to stderr and exits. More...
 
void verrc (const int, const char *, va_list)
 Prints a formatted error message to stderr and exits with the given exit code. More...
 
void warn (const char *,...)
 Prints a formatted warning message to stderr. More...
 
void ewarn (const char *,...)
 Prints a formatted error message to stderr. More...
 
void err (const char *,...)
 Prints a formatted error message to stderr and exits. More...
 
void errc (const int, const char *,...)
 Prints a formatted error message to stderr and exits with the given exit code. More...
 

Variables

char * program_invocation_name
 Global value for the program's name. More...
 

Detailed Description

Header file.

Version
2.0.0

#include this to use err in your project.

Definition in file err.h.

Function Documentation

◆ err()

void err ( const char *  fmt,
  ... 
)

Prints a formatted error message to stderr and exits.

Precondition
program_invocation_name is set
Parameters
fmtformat string
...arguments for the format string

Variadic wrapper for verr().

Definition at line 123 of file err.c.

124{
125 va_list ap;
126
127 va_start(ap, fmt);
128 verr(fmt, ap);
129 va_end(ap);
130}
void verr(const char *fmt, va_list ap)
Prints a formatted error message to stderr and exits.
Definition: err.c:75
Here is the call graph for this function:

◆ errc()

void errc ( const int  code,
const char *  fmt,
  ... 
)

Prints a formatted error message to stderr and exits with the given exit code.

Precondition
program_invocation_name is set
Parameters
codeexit code
fmtformat string
...arguments for the format string

Variadic wrapper for verrc().

Definition at line 110 of file err.c.

111{
112 va_list ap;
113
114 va_start(ap, fmt);
115 verrc(code, fmt, ap);
116 va_end(ap);
117}
void verrc(const int code, const char *fmt, va_list ap)
Prints a formatted error message to stderr and exits with the given exit code.
Definition: err.c:64
Here is the call graph for this function:

◆ ewarn()

void ewarn ( const char *  fmt,
  ... 
)

Prints a formatted error message to stderr.

Precondition
program_invocation_name is set
Parameters
fmtformat string
...arguments for the format string

Variadic wrapper for vewarn().

Definition at line 97 of file err.c.

98{
99 va_list ap;
100
101 va_start(ap, fmt);
102 vewarn(fmt, ap);
103 va_end(ap);
104}
void vewarn(const char *fmt, va_list ap)
Prints a formatted error message to stderr.
Definition: err.c:46
Here is the call graph for this function:

◆ verr()

void verr ( const char *  fmt,
va_list  ap 
)

Prints a formatted error message to stderr and exits.

Precondition
program_invocation_name is set
Parameters
fmtformat string
apva_list of arguments for the format string

Calls verrc() with EXIT_FAILURE.

Definition at line 75 of file err.c.

76{
77 verrc(EXIT_FAILURE, fmt, ap);
78}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verrc()

void verrc ( const int  code,
const char *  fmt,
va_list  ap 
)

Prints a formatted error message to stderr and exits with the given exit code.

Precondition
program_invocation_name is set
Parameters
codeexit code
fmtformat string
apva_list of arguments for the format string

Calls vewarn() and exits the program with the provided code.

Definition at line 64 of file err.c.

65{
66 vewarn(fmt, ap);
67
68 exit(code);
69}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vewarn()

void vewarn ( const char *  fmt,
va_list  ap 
)

Prints a formatted error message to stderr.

Precondition
program_invocation_name is set
Parameters
fmtformat string
apva_list of arguments for the format string

Calls vwarn(), then prints ": ", strerror(errno), and a newline.

Definition at line 46 of file err.c.

47{
48 vwarn(fmt, ap);
49 if (errno != 0) {
50 /* To avoid two colons being printed, like
51 * "program_invocation_name: : No such file or directory" */
52 if (fmt != NULL && fmt[0] != '\0') {
53 fputs(": ", stderr);
54 }
55 fprintf(stderr, "%s", strerror(errno));
56 }
57 fputc('\n', stderr);
58}
void vwarn(const char *fmt, va_list ap)
Prints a formatted warning message to stderr.
Definition: err.c:36
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vwarn()

void vwarn ( const char *  fmt,
va_list  ap 
)

Prints a formatted warning message to stderr.

Precondition
program_invocation_name is set
Parameters
fmtformat string
apva_list of arguments for the format string

Prints program_invocation_name, ": ", and the printf(3)-like-formatted error message.

Definition at line 36 of file err.c.

37{
38 fprintf(stderr, "%s: ", program_invocation_name);
39 vfprintf(stderr, fmt, ap);
40}
char * program_invocation_name
Global value for the program's name.
Definition: err.c:29
Here is the caller graph for this function:

◆ warn()

void warn ( const char *  fmt,
  ... 
)

Prints a formatted warning message to stderr.

Precondition
program_invocation_name is set
Parameters
fmtformat string
...arguments for the format string

Variadic wrapper for vwarn().

Definition at line 84 of file err.c.

85{
86 va_list ap;
87
88 va_start(ap, fmt);
89 vwarn(fmt, ap);
90 va_end(ap);
91}
Here is the call graph for this function:

Variable Documentation

◆ program_invocation_name

char* program_invocation_name
extern

Global value for the program's name.

This must be set before any err functions are called.

Definition at line 29 of file err.c.