Back to index

php5  5.3.10
Classes | Functions | Variables
regerror.c File Reference
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include "regex.h"
#include "utils.h"
#include "regerror.ih"
#include "php.h"

Go to the source code of this file.

Classes

struct  rerr

Functions

 regerror (int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
static char * regatoi (regex_t *preg, char *localbuf, int bufsize) const

Variables

static struct rerr rerrs []

Class Documentation

struct rerr

Definition at line 34 of file regerror.c.

Class Members
int code
const char * explain
const char * name

Function Documentation

static char* regatoi ( regex_t preg,
char *  localbuf,
int  bufsize 
) const [static]

Definition at line 115 of file regerror.c.

{
       register const struct rerr *r;

       for (r = rerrs; r->code >= 0; r++)
              if (strcmp(r->name, preg->re_endp) == 0)
                     break;
       if (r->code < 0)
              return("0");

       snprintf(localbuf, bufsize, "%d", r->code);
       return(localbuf);
}

Here is the caller graph for this function:

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

Definition at line 65 of file regerror.c.

{
       register const struct rerr *r;
       register size_t len;
       register int target = errcode &~ REG_ITOA;
       register const char *s;
       char convbuf[50];

       if (errcode == REG_ATOI)
              s = regatoi(preg, convbuf, sizeof(convbuf));
       else {
              for (r = rerrs; r->code >= 0; r++)
                     if (r->code == target)
                            break;
       
              if (errcode&REG_ITOA) {
                     if (r->code >= 0) {
                            (void) strncpy(convbuf, r->name, sizeof(convbuf) - 1);
                            convbuf[sizeof(convbuf) - 1] = '\0';
                     } else {
                            snprintf(convbuf, sizeof(convbuf), "REG_0x%x", target);
                     }
                     assert(strlen(convbuf) < sizeof(convbuf));
                     s = convbuf;
              } else
                     s = r->explain;
       }

       len = strlen(s) + 1;
       if (errbuf_size > 0) {
              if (errbuf_size > len)
                     (void) strcpy(errbuf, s);
              else {
                     (void) strncpy(errbuf, s, errbuf_size-1);
                     errbuf[errbuf_size-1] = '\0';
              }
       }

       return(len);
}

Here is the caller graph for this function:


Variable Documentation

struct rerr rerrs[] [static]