Skip to content

Commit 953a33f

Browse files
committed
perflib: add vwarn/err/warn
Signed-off-by: Eugene Syromiatnikov <[email protected]>
1 parent 393f457 commit 953a33f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

source/perflib/err.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* https://www.openssl.org/source/license.html
88
*/
99

10+
#include <errno.h>
1011
#include <stdarg.h>
1112
#include <stdio.h>
1213
#include <stdlib.h>
@@ -38,6 +39,20 @@ vwarnx(const char *fmt, va_list ap)
3839
putc('\n', stderr);
3940
}
4041

42+
void
43+
vwarn(const char *fmt, va_list ap)
44+
{
45+
int saved_errno = errno;
46+
47+
if (get_progname() != NULL)
48+
fprintf(stderr, "%s: ", get_progname());
49+
vfprintf(stderr, fmt, ap);
50+
fprintf(stderr, ": ");
51+
52+
errno = saved_errno;
53+
perror(NULL);
54+
}
55+
4156
void
4257
errx(int status, const char *fmt, ...)
4358
{
@@ -49,6 +64,17 @@ errx(int status, const char *fmt, ...)
4964
exit(status);
5065
}
5166

67+
void
68+
err(int status, const char *fmt, ...)
69+
{
70+
va_list ap;
71+
72+
va_start(ap, fmt);
73+
vwarn(fmt, ap);
74+
va_end(ap);
75+
exit(status);
76+
}
77+
5278
void
5379
warnx(const char *fmt, ...)
5480
{
@@ -58,3 +84,13 @@ warnx(const char *fmt, ...)
5884
vwarnx(fmt, ap);
5985
va_end(ap);
6086
}
87+
88+
void
89+
warn(const char *fmt, ...)
90+
{
91+
va_list ap;
92+
93+
va_start(ap, fmt);
94+
vwarn(fmt, ap);
95+
va_end(ap);
96+
}

source/perflib/err.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
extern const char *progname;
2323

2424
extern void vwarnx(const char *, va_list);
25+
extern void vwarn(const char *, va_list);
26+
2527
extern void errx(int, const char *, ...);
28+
extern void err(int, const char *, ...);
29+
2630
extern void warnx(const char *, ...);
31+
extern void warn(const char *, ...);
2732

2833
# endif /* !_WIN32 */
2934

0 commit comments

Comments
 (0)