-
Notifications
You must be signed in to change notification settings - Fork 3
/
rherr.c
133 lines (101 loc) · 3 KB
/
rherr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* rawhide - find files using pretty C expressions
* https://raf.org/rawhide
* https://github.com/raforg/rawhide
* https://codeberg.org/raforg/rawhide
*
* Copyright (C) 1990 Ken Stauffer, 2022-2023 raf <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*
* 20231013 raf <[email protected]>
*/
#define _FILE_OFFSET_BITS 64 /* For 64-bit off_t on 32-bit systems (Not AIX) */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "rh.h"
/*
int error(const char *format, ...);
Outputs an error message to stderr (prefixed by the program name).
The format parameter is a printf-like format string.
Subsequent arguments must satisfy its conversions.
Returns -1.
*/
int error(const char *format, ...)
{
va_list args;
va_start(args, format);
fprintf(stderr, "%s: ", prog_name);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
va_end(args);
return -1;
}
/*
int errorsys(const char *format, ...);
Outputs an error message to stderr (prefixed by the program name),
including a trailing errno string.
The format parameter is a printf-like format string.
Subsequent arguments must satisfy its conversions.
Returns -1.
*/
int errorsys(const char *format, ...)
{
va_list args;
va_start(args, format);
fprintf(stderr, "%s: ", prog_name);
vfprintf(stderr, format, args);
fprintf(stderr, ": %s\n", strerror(errno));
va_end(args);
return -1;
}
/*
void fatal(const char *format, ...);
Outputs an error message to stderr (prefixed by the program name),
then exits with a non-zero failure exit status.
The format parameter is a printf-like format string.
Subsequent arguments must satisfy its conversions.
*/
void fatal(const char *format, ...)
{
va_list args;
va_start(args, format);
fprintf(stderr, "%s: ", prog_name);
vfprintf(stderr, format, args);
fprintf(stderr, "\n");
va_end(args);
exit(EXIT_FAILURE);
}
/*
void fatalsys(const char *format, ...);
Outputs an error message to stderr (prefixed by the program name)
including a trailing errno string, then exits with a non-zero
failure exit status. The format parameter is a printf-like format string.
Subsequent arguments must satisfy its conversions.
*/
void fatalsys(const char *format, ...)
{
va_list args;
va_start(args, format);
fprintf(stderr, "%s: ", prog_name);
vfprintf(stderr, format, args);
fprintf(stderr, ": %s\n", strerror(errno));
va_end(args);
exit(EXIT_FAILURE);
}
/* vi:set ts=4 sw=4: */