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

Main source code file. More...

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for err.c:

Go to the source code of this file.

Functions

void vwarn (const char *fmt, va_list ap)
 Prints a formatted warning message to stderr. More...
 
void vewarn (const char *fmt, va_list ap)
 Prints a formatted error message to stderr. More...
 
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. More...
 
void verr (const char *fmt, va_list ap)
 Prints a formatted error message to stderr and exits. More...
 
void warn (const char *fmt,...)
 Prints a formatted warning message to stderr. More...
 
void ewarn (const char *fmt,...)
 Prints a formatted error message to stderr. More...
 
void errc (const int code, const char *fmt,...)
 Prints a formatted error message to stderr and exits with the given exit code. More...
 
void err (const char *fmt,...)
 Prints a formatted error message to stderr and exits. More...
 

Variables

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

Detailed Description

Main source code file.

Version
2.0.0

This file contains definitions and declarations of globally available functions and variables.

Definition in file err.c.

Function Documentation

◆ err()

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

Prints a formatted error message to stderr and exits.

Variadic wrapper for verr().

Examples
files.c, and weekday.c.

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.

Variadic wrapper for verrc().

Examples
hello.c.

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.

Variadic wrapper for vewarn().

Examples
files.c.

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.

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.

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.

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.

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.

Variadic wrapper for vwarn().

Examples
hello.c.

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

Global value for the program's name.

This must be set before any err functions are called.

Examples
files.c, hello.c, and weekday.c.

Definition at line 29 of file err.c.