5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews/* Copyright (c) 2008 The NetBSD Foundation, Inc.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * All rights reserved.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews *
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * Redistribution and use in source and binary forms, with or without
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * modification, are permitted provided that the following conditions
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * are met:
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * 1. Redistributions of source code must retain the above copyright
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * notice, this list of conditions and the following disclaimer.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * 2. Redistributions in binary form must reproduce the above copyright
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * notice, this list of conditions and the following disclaimer in the
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * documentation and/or other materials provided with the distribution.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews *
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include "atf-c/detail/sanity.h"
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#if defined(HAVE_CONFIG_H)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include "config.h"
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#endif
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include <err.h>
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include <stdarg.h>
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include <stdio.h>
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include <stdlib.h>
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsstatic
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsvoid
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsfail(const char *fmt, ...)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews{
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews va_list ap;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews char buf[4096];
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews va_start(ap, fmt);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews vsnprintf(buf, sizeof(buf), fmt, ap);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews va_end(ap);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews warnx("%s", buf);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews warnx("%s", "");
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews warnx("This is probably a bug in this application or one of the "
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews "libraries it uses. If you believe this problem is caused "
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews "by, or is related to " PACKAGE_STRING ", please report it "
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews "to " PACKAGE_BUGREPORT " and provide as many details as "
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews "possible describing how you got to this condition.");
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews abort();
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews}
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsvoid
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsatf_sanity_inv(const char *file, int line, const char *cond)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews{
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews fail("Invariant check failed at %s:%d: %s", file, line, cond);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews}
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsvoid
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsatf_sanity_pre(const char *file, int line, const char *cond)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews{
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews fail("Precondition check failed at %s:%d: %s", file, line, cond);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews}
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsvoid
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsatf_sanity_post(const char *file, int line, const char *cond)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews{
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews fail("Postcondition check failed at %s:%d: %s", file, line, cond);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews}
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews