Skip to content
36 changes: 36 additions & 0 deletions source/perflib/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* https://www.openssl.org/source/license.html
*/

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -38,6 +39,20 @@ vwarnx(const char *fmt, va_list ap)
putc('\n', stderr);
}

void
vwarn(const char *fmt, va_list ap)
{
int saved_errno = errno;

if (get_progname() != NULL)
fprintf(stderr, "%s: ", get_progname());
vfprintf(stderr, fmt, ap);
fprintf(stderr, ": ");

errno = saved_errno;
perror(NULL);
}

void
errx(int status, const char *fmt, ...)
{
Expand All @@ -49,6 +64,17 @@ errx(int status, const char *fmt, ...)
exit(status);
}

void
err(int status, const char *fmt, ...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why to duplicate errx function? Same for warn and warnx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err/warn append the output of perror() to the message, while errx/warnx just print the provided string (along with the program name as a prefix).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err/warn append the output of perror() to the message, while errx/warnx just print the provided string (along with the program name as a prefix).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now; sorry for the noise

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow why we need to duplicate all this stuff for thread affinity.. This seems unrelated.

If we want this it should probably be done separately, or we should ask ourselves why we can't use the standard stuff.

{
va_list ap;

va_start(ap, fmt);
vwarn(fmt, ap);
va_end(ap);
exit(status);
}

void
warnx(const char *fmt, ...)
{
Expand All @@ -58,3 +84,13 @@ warnx(const char *fmt, ...)
vwarnx(fmt, ap);
va_end(ap);
}

void
warn(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
vwarn(fmt, ap);
va_end(ap);
}
5 changes: 5 additions & 0 deletions source/perflib/err.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
extern const char *progname;

extern void vwarnx(const char *, va_list);
extern void vwarn(const char *, va_list);

extern void errx(int, const char *, ...);
extern void err(int, const char *, ...);

extern void warnx(const char *, ...);
extern void warn(const char *, ...);

# endif /* !_WIN32 */

Expand Down