PostgreSQL Source Code  git master
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 const char unk [] = "*** unknown regex error code 0x%x ***"
 
static const struct rerr rerrs []
 

Function Documentation

◆ pg_regerror()

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

Definition at line 60 of file regerror.c.

64 {
65  const struct rerr *r;
66  const char *msg;
67  char convbuf[sizeof(unk) + 50]; /* 50 = plenty for int */
68  size_t len;
69  int icode;
70 
71  switch (errcode)
72  {
73  case REG_ATOI: /* convert name to number */
74  for (r = rerrs; r->code >= 0; r++)
75  if (strcmp(r->name, errbuf) == 0)
76  break;
77  sprintf(convbuf, "%d", r->code); /* -1 for unknown */
78  msg = convbuf;
79  break;
80  case REG_ITOA: /* convert number to name */
81  icode = atoi(errbuf); /* not our problem if this fails */
82  for (r = rerrs; r->code >= 0; r++)
83  if (r->code == icode)
84  break;
85  if (r->code >= 0)
86  msg = r->name;
87  else
88  { /* unknown; tell him the number */
89  sprintf(convbuf, "REG_%u", (unsigned) icode);
90  msg = convbuf;
91  }
92  break;
93  default: /* a real, normal error code */
94  for (r = rerrs; r->code >= 0; r++)
95  if (r->code == errcode)
96  break;
97  if (r->code >= 0)
98  msg = r->explain;
99  else
100  { /* unknown; say so */
101  sprintf(convbuf, unk, errcode);
102  msg = convbuf;
103  }
104  break;
105  }
106 
107  len = strlen(msg) + 1; /* space needed, including NUL */
108  if (errbuf_size > 0)
109  {
110  if (errbuf_size > len)
111  strcpy(errbuf, msg);
112  else
113  { /* truncate to fit */
114  memcpy(errbuf, msg, errbuf_size - 1);
115  errbuf[errbuf_size - 1] = '\0';
116  }
117  }
118 
119  return len;
120 }
int errcode(int sqlerrcode)
Definition: elog.c:853
const void size_t len
#define sprintf
Definition: port.h:240
static const struct rerr rerrs[]
static const char unk[]
Definition: regerror.c:37
#define REG_ITOA
Definition: regex.h:237
#define REG_ATOI
Definition: regex.h:236
Definition: regerror.c:41
const char * explain
Definition: regerror.c:44
int code
Definition: regerror.c:42
const char * name
Definition: regerror.c:43

References rerr::code, errcode(), rerr::explain, len, rerr::name, REG_ATOI, REG_ITOA, rerrs, sprintf, and unk.

Referenced by check_ident_usermap(), NIAddAffix(), RE_compile(), RE_compile_and_cache(), RE_wchar_execute(), regcomp_auth_token(), regexp_fixed_prefix(), replace_text_regexp(), test_re_compile(), and test_re_execute().

Variable Documentation

◆ rerrs

const struct rerr rerrs[]
static
Initial value:
=
{
{
-1, "", "oops"
},
}

Referenced by pg_regerror().

◆ unk

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

Definition at line 37 of file regerror.c.

Referenced by pg_regerror().