2 * regerror - error-code expansion
4 * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved.
6 * Development of this software was funded, in part, by Cray Research Inc.,
7 * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
8 * Corporation, none of whom are responsible for the results. The author
11 * Redistribution and use in source and binary forms -- with or without
12 * modification -- are permitted for any purpose, provided that
13 * redistributions in source form retain this entire copyright notice and
14 * indicate the origin and nature of any modifications.
16 * I'd appreciate being given credit for this package in the documentation
17 * of software which uses it, but that is not a requirement.
19 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * src/backend/regex/regerror.c
36/* unknown-error explanation */
37 static const char unk[] =
"*** unknown regex error code 0x%x ***";
39/* struct to map among codes, code names, and explanations */
48 /* the actual table is built from regex.h */
52 },
/* explanation special-cased in code */
56 * pg_regerror - the interface to error numbers
59size_t /* actual space needed (including NUL) */
61 const regex_t *preg,
/* associated regex_t (unused at present) */
62 char *errbuf,
/* result buffer (unless errbuf_size==0) */
63 size_t errbuf_size)
/* available space in errbuf, can be 0 */
67 char convbuf[
sizeof(
unk) + 50];
/* 50 = plenty for int */
73 case REG_ATOI:
/* convert name to number */
75 if (strcmp(r->
name, errbuf) == 0)
77 sprintf(convbuf,
"%d", r->
code);
/* -1 for unknown */
80 case REG_ITOA:
/* convert number to name */
81 icode = atoi(errbuf);
/* not our problem if this fails */
88 {
/* unknown; tell him the number */
89 sprintf(convbuf,
"REG_%u", (
unsigned) icode);
93 default:
/* a real, normal error code */
100 {
/* unknown; say so */
107 len = strlen(msg) + 1;
/* space needed, including NUL */
110 if (errbuf_size >
len)
113 {
/* truncate to fit */
114 memcpy(errbuf, msg, errbuf_size - 1);
115 errbuf[errbuf_size - 1] =
'0円';
int errcode(int sqlerrcode)
static const struct rerr rerrs[]
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)