11590Srgrimes/*-
21590Srgrimes * Copyright (c) 1992 Diomidis Spinellis.
31590Srgrimes * Copyright (c) 1992, 1993
41590Srgrimes *	The Regents of the University of California.  All rights reserved.
51590Srgrimes *
61590Srgrimes * This code is derived from software contributed to Berkeley by
71590Srgrimes * Diomidis Spinellis of Imperial College, University of London.
81590Srgrimes *
91590Srgrimes * Redistribution and use in source and binary forms, with or without
101590Srgrimes * modification, are permitted provided that the following conditions
111590Srgrimes * are met:
121590Srgrimes * 1. Redistributions of source code must retain the above copyright
131590Srgrimes *    notice, this list of conditions and the following disclaimer.
141590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151590Srgrimes *    notice, this list of conditions and the following disclaimer in the
161590Srgrimes *    documentation and/or other materials provided with the distribution.
171590Srgrimes * 4. Neither the name of the University nor the names of its contributors
181590Srgrimes *    may be used to endorse or promote products derived from this software
191590Srgrimes *    without specific prior written permission.
201590Srgrimes *
211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311590Srgrimes * SUCH DAMAGE.
321590Srgrimes */
331590Srgrimes
3487766Smarkm#include <sys/cdefs.h>
3587766Smarkm__FBSDID("$FreeBSD$");
3687766Smarkm
371590Srgrimes#ifndef lint
3887766Smarkmstatic const char sccsid[] = "@(#)misc.c	8.1 (Berkeley) 6/6/93";
3928066Scharnier#endif
401590Srgrimes
411590Srgrimes#include <sys/types.h>
421590Srgrimes
4328066Scharnier#include <err.h>
44200462Sdelphij#include <limits.h>
451590Srgrimes#include <regex.h>
46200462Sdelphij#include <stdio.h>
471590Srgrimes#include <stdlib.h>
48200462Sdelphij#include <string.h>
491590Srgrimes
50200462Sdelphij#include "defs.h"
51200462Sdelphij#include "extern.h"
52200462Sdelphij
531590Srgrimes/*
54108533Sschweikh * Return a string for a regular expression error passed.  This is overkill,
551590Srgrimes * because of the silly semantics of regerror (we can never know the size of
561590Srgrimes * the buffer).
571590Srgrimes */
581590Srgrimeschar *
59122044Sdesstrregerror(int errcode, regex_t *preg)
601590Srgrimes{
611590Srgrimes	static char *oe;
621590Srgrimes	size_t s;
631590Srgrimes
641590Srgrimes	if (oe != NULL)
651590Srgrimes		free(oe);
6699572Stjr	s = regerror(errcode, preg, NULL, 0);
6780286Sobrien	if ((oe = malloc(s)) == NULL)
6880286Sobrien		err(1, "malloc");
691590Srgrimes	(void)regerror(errcode, preg, oe, s);
701590Srgrimes	return (oe);
711590Srgrimes}
72