You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.6 KiB

/*
* arngment - random music generator
*
* Written in 2020 by Lucas
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "err.h"
void
err(int eval, const char *fmt, ...)
{
va_list ap;
int saved_errno = errno;
fprintf(stderr, "%s: ", __progname);
if (fmt != NULL) {
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, ": ");
}
fprintf(stderr, "%s\n", strerror(saved_errno));
exit(eval);
}
void
errx(int eval, const char *fmt, ...)
{
va_list ap;
fprintf(stderr, "%s: ", __progname);
if (fmt != NULL) {
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
fprintf(stderr, "\n");
exit(eval);
}
void
warn(const char *fmt, ...)
{
va_list ap;
int saved_errno = errno;
fprintf(stderr, "%s: ", __progname);
if (fmt != NULL) {
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, ": ");
}
fprintf(stderr, "%s\n", strerror(saved_errno));
}
void
warnx(const char *fmt, ...)
{
va_list ap;
fprintf(stderr, "%s: ", __progname);
if (fmt != NULL) {
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
fprintf(stderr, "\n");
}