1cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* $NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $ */ 2cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 3cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/*- 4cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Copyright (c) 1992, 1993, 1994 5cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * The Regents of the University of California. All rights reserved. 6cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 7cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * This code is derived from software contributed to Berkeley by 8cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Henry Spencer. 9cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 10cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Redistribution and use in source and binary forms, with or without 11cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * modification, are permitted provided that the following conditions 12cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * are met: 13cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 1. Redistributions of source code must retain the above copyright 14cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * notice, this list of conditions and the following disclaimer. 15cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright 16cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * notice, this list of conditions and the following disclaimer in the 17cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * documentation and/or other materials provided with the distribution. 18cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 3. Neither the name of the University nor the names of its contributors 19cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * may be used to endorse or promote products derived from this software 20cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * without specific prior written permission. 21cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 22cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * SUCH DAMAGE. 33cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 34cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * @(#)regerror.c 8.4 (Berkeley) 3/20/94 35cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes */ 36cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 37cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/*- 38cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Copyright (c) 1992, 1993, 1994 Henry Spencer. 39cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 40cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * This code is derived from software contributed to Berkeley by 41cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Henry Spencer. 42cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 43cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * Redistribution and use in source and binary forms, with or without 44cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * modification, are permitted provided that the following conditions 45cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * are met: 46cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 1. Redistributions of source code must retain the above copyright 47cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * notice, this list of conditions and the following disclaimer. 48cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright 49cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * notice, this list of conditions and the following disclaimer in the 50cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * documentation and/or other materials provided with the distribution. 51cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 3. All advertising materials mentioning features or use of this software 52cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * must display the following acknowledgement: 53cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * This product includes software developed by the University of 54cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * California, Berkeley and its contributors. 55cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 4. Neither the name of the University nor the names of its contributors 56cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * may be used to endorse or promote products derived from this software 57cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * without specific prior written permission. 58cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 59cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * SUCH DAMAGE. 70cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * 71cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * @(#)regerror.c 8.4 (Berkeley) 3/20/94 72cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes */ 73cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 74cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <sys/cdefs.h> 75cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#if defined(LIBC_SCCS) && !defined(lint) 76cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#if 0 77cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughesstatic char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; 78cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#else 79cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes__RCSID("$NetBSD: regerror.c,v 1.23 2007/02/09 23:44:18 junyoung Exp $"); 80cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#endif 81cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#endif /* LIBC_SCCS and not lint */ 82cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 83cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include "namespace.h" 84cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <sys/types.h> 85cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 86cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <assert.h> 87cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <ctype.h> 88cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <limits.h> 89cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <stdio.h> 90cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <stdlib.h> 91cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <string.h> 92cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include <regex.h> 93cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 94cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#ifdef __weak_alias 95cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes__weak_alias(regerror,_regerror) 96cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#endif 97cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 98cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#include "utils.h" 99cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 100cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* ========= begin header generated by ./mkh ========= */ 101cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#ifdef __cplusplus 102cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughesextern "C" { 103cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#endif 104cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 105cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* === regerror.c === */ 106cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughesstatic const char *regatoi(const regex_t *preg, char *localbuf, size_t buflen); 107cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 108cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#ifdef __cplusplus 109cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes} 110cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes#endif 111cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* ========= end header generated by ./mkh ========= */ 112cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* 113cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_NOMATCH 1 114cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_BADPAT 2 115cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ECOLLATE 3 116cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ECTYPE 4 117cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_EESCAPE 5 118cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ESUBREG 6 119cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_EBRACK 7 120cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_EPAREN 8 121cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_EBRACE 9 122cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_BADBR 10 123cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ERANGE 11 124cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ESPACE 12 125cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_BADRPT 13 126cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_EMPTY 14 127cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ASSERT 15 128cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_INVARG 16 129cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ATOI 255 // convert name to number (!) 130cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes = #define REG_ITOA 0400 // convert number to name (!) 131cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes */ 132cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughesstatic const struct rerr { 133cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes int code; 134cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes const char *name; 135cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes const char *explain; 136cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes} rerrs[] = { 137cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" }, 138cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_BADPAT, "REG_BADPAT", "invalid regular expression" }, 139cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" }, 140cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_ECTYPE, "REG_ECTYPE", "invalid character class" }, 141cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" }, 142cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" }, 143cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" }, 144cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_EPAREN, "REG_EPAREN", "parentheses not balanced" }, 145cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_EBRACE, "REG_EBRACE", "braces not balanced" }, 146cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_BADBR, "REG_BADBR", "invalid repetition count(s)" }, 147cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_ERANGE, "REG_ERANGE", "invalid character range" }, 148cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_ESPACE, "REG_ESPACE", "out of memory" }, 149cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" }, 150cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_EMPTY, "REG_EMPTY", "empty (sub)expression" }, 151cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" }, 152cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { REG_INVARG, "REG_INVARG", "invalid argument to regex routine" }, 153cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes { 0, "", "*** unknown regexp error code ***" } 154cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes}; 155cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 156cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* 157cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * regerror - the interface to error numbers 158cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * extern size_t regerror(int, const regex_t *, char *, size_t); 159cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes */ 160cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* ARGSUSED */ 161cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughessize_t 162cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughesregerror( 163cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes int errcode, 164cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes const regex_t *preg, 165cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes char *errbuf, 166cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes size_t errbuf_size) 167cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes{ 168cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes const struct rerr *r; 169cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes size_t len; 170cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes int target = errcode &~ REG_ITOA; 171cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes const char *s; 172cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes char convbuf[50]; 173cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 174cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes _DIAGASSERT(errcode != REG_ATOI || preg != NULL); 175cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes _DIAGASSERT(errbuf != NULL); 176cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 177cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes if (errcode == REG_ATOI) 178cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes s = regatoi(preg, convbuf, sizeof convbuf); 179cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes else { 180cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes for (r = rerrs; r->code != 0; r++) 181cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes if (r->code == target) 182cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes break; 183cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 184cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes if (errcode & REG_ITOA) { 185cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes if (r->code != 0) { 186cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes (void)strlcpy(convbuf, r->name, sizeof convbuf); 187cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes } else 188cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes (void)snprintf(convbuf, sizeof convbuf, 189cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes "REG_0x%x", target); 190cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes s = convbuf; 191cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes } else 192cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes s = r->explain; 193cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes } 194cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 195cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes len = strlen(s) + 1; 196cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes if (errbuf_size > 0) 197cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes (void)strlcpy(errbuf, s, errbuf_size); 198cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 199cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes return(len); 200cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes} 201cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 202cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes/* 203cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * regatoi - internal routine to implement REG_ATOI 204cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * static const char *regatoi(const regex_t *preg, char *localbuf, 205cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes * size_t buflen); 206cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes */ 207cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughesstatic const char * 208cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughesregatoi( 209cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes const regex_t *preg, 210cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes char *localbuf, 211cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes size_t buflen) 212cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes{ 213cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes const struct rerr *r; 214cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 215cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes for (r = rerrs; r->code != 0; r++) 216cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes if (strcmp(r->name, preg->re_endp) == 0) 217cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes break; 218cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes if (r->code == 0) 219cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes return "0"; 220cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes 221cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes (void)snprintf(localbuf, buflen, "%d", r->code); 222cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes return localbuf; 223cc213f871bf4c5329eb5eb7a80a0ce9d4a880af8Elliott Hughes} 224