view err.c @ 17:b7309b030e8d

Port to AIX
author Guido Berhoerster <guido+sencrypt@berhoerster.name>
date Sat, 07 Jul 2018 17:55:59 +0200
parents 73af139d1a94
children
line wrap: on
line source

/*
 * Copyright (C) 2011 Guido Berhoerster <guido+sencrypt@berhoerster.name>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "err.h"

static char __progname[] = "unknown";

void
err(int eval, const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	vwarn(fmt, args);
	va_end(args);

	exit(eval);
}

void
errx(int eval, const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	vwarnx(fmt, args);
	va_end(args);

	exit(eval);
}

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

	va_start(args, fmt);
	vwarn(fmt, args);
	va_end(args);
}

void
warnx(const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	vwarnx(fmt, args);
	va_end(args);
}

void
verr(int eval, const char *fmt, va_list args)
{
	vwarn(fmt, args);

	exit(eval);
}

void
verrx(int eval, const char *fmt, va_list args)
{
	vwarnx(fmt, args);

	exit(eval);
}

void
vwarn(const char *fmt, va_list args)
{
	int old_errno = errno;

	fprintf(stderr, "%s: ", __progname);
	if (fmt != NULL) {
		vfprintf(stderr, fmt, args);
		fprintf(stderr, ": ");
	}
	fprintf(stderr, "%s\n", strerror(old_errno));
	errno = old_errno;
}

void
vwarnx(const char *fmt, va_list args)
{
	fprintf(stderr, "%s: ", __progname);
	if (fmt != NULL) {
		vfprintf(stderr, fmt, args);
	}
	fputc('\n', stderr);
}