84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Copyright (c) 1992 Diomidis Spinellis.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Copyright (c) 1992, 1993
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * The Regents of the University of California. All rights reserved.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore *
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * This code is derived from software contributed to Berkeley by
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Diomidis Spinellis of Imperial College, University of London.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore *
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Redistribution and use in source and binary forms, with or without
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * modification, are permitted provided that the following conditions
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * are met:
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * 1. Redistributions of source code must retain the above copyright
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * notice, this list of conditions and the following disclaimer.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * notice, this list of conditions and the following disclaimer in the
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * documentation and/or other materials provided with the distribution.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * 4. Neither the name of the University nor the names of its contributors
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * may be used to endorse or promote products derived from this software
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * without specific prior written permission.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore *
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * SUCH DAMAGE.
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <sys/types.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <err.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <limits.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <regex.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <stdio.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <stdlib.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <string.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include <stdarg.h>
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include "defs.h"
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore#include "extern.h"
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore/*
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * Return a string for a regular expression error passed. This is overkill,
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * because of the silly semantics of regerror (we can never know the size of
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore * the buffer).
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore */
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorechar *
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorestrregerror(int errcode, regex_t *preg)
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore{
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore static char *oe;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore size_t s;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore if (oe != NULL)
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore free(oe);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore s = regerror(errcode, preg, NULL, 0);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore if ((oe = malloc(s)) == NULL)
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore err(1, "malloc");
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore (void) regerror(errcode, preg, oe, s);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore return (oe);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore}
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorevoid
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amorefatal(const char *fmt, ...)
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore{
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore va_list ap;
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore (void) fprintf(stderr, "%s: %lu: ", fname, linenum);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore va_start(ap, fmt);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore (void) vfprintf(stderr, fmt, ap);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore va_end(ap);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore (void) fputc('\n', stderr);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore exit(1);
84441f85b19f6b8080883f30109e58e43c893709Garrett D'Amore}