Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Functions | Variables

regerror.c File Reference

#include "regex/regguts.h"
#include "regex/regerrs.h"
Include dependency graph for regerror.c:

Go to the source code of this file.

Data Structures

struct  rerr

Functions

size_t pg_regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)

Variables

static char unk [] = "*** unknown regex error code 0x%x ***"
static struct rerr rerrs []

Function Documentation

size_t pg_regerror ( int  errcode,
const regex_t preg,
char *  errbuf,
size_t  errbuf_size 
)

Definition at line 60 of file regerror.c.

References rerr::code, rerr::explain, rerr::name, REG_ATOI, REG_ITOA, rerrs, and unk.

Referenced by check_ident_usermap(), NIAddAffix(), parse_ident_line(), RE_compile(), RE_compile_and_cache(), RE_wchar_execute(), regexp_fixed_prefix(), and replace_text_regexp().

{
    struct rerr *r;
    const char *msg;
    char        convbuf[sizeof(unk) + 50];      /* 50 = plenty for int */
    size_t      len;
    int         icode;

    switch (errcode)
    {
        case REG_ATOI:          /* convert name to number */
            for (r = rerrs; r->code >= 0; r++)
                if (strcmp(r->name, errbuf) == 0)
                    break;
            sprintf(convbuf, "%d", r->code);    /* -1 for unknown */
            msg = convbuf;
            break;
        case REG_ITOA:          /* convert number to name */
            icode = atoi(errbuf);       /* not our problem if this fails */
            for (r = rerrs; r->code >= 0; r++)
                if (r->code == icode)
                    break;
            if (r->code >= 0)
                msg = r->name;
            else
            {                   /* unknown; tell him the number */
                sprintf(convbuf, "REG_%u", (unsigned) icode);
                msg = convbuf;
            }
            break;
        default:                /* a real, normal error code */
            for (r = rerrs; r->code >= 0; r++)
                if (r->code == errcode)
                    break;
            if (r->code >= 0)
                msg = r->explain;
            else
            {                   /* unknown; say so */
                sprintf(convbuf, unk, errcode);
                msg = convbuf;
            }
            break;
    }

    len = strlen(msg) + 1;      /* space needed, including NUL */
    if (errbuf_size > 0)
    {
        if (errbuf_size > len)
            strcpy(errbuf, msg);
        else
        {                       /* truncate to fit */
            strncpy(errbuf, msg, errbuf_size - 1);
            errbuf[errbuf_size - 1] = '\0';
        }
    }

    return len;
}


Variable Documentation

struct rerr rerrs[] [static]

Referenced by pg_regerror().

char unk[] = "*** unknown regex error code 0x%x ***" [static]

Definition at line 37 of file regerror.c.

Referenced by pg_regerror().