Print this page
9083 replace regex implementation with tre

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libc/port/regex/regerror.c
          +++ new/usr/src/lib/libc/port/regex/regerror.c
   1    1  /*
   2      - * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
   3    2   * Copyright (c) 1992, 1993, 1994 Henry Spencer.
   4    3   * Copyright (c) 1992, 1993, 1994
   5    4   *      The Regents of the University of California.  All rights reserved.
   6    5   *
   7    6   * This code is derived from software contributed to Berkeley by
   8    7   * Henry Spencer.
   9    8   *
  10    9   * Redistribution and use in source and binary forms, with or without
  11   10   * modification, are permitted provided that the following conditions
  12   11   * are met:
↓ open down ↓ 12 lines elided ↑ open up ↑
  25   24   * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26   25   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27   26   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28   27   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29   28   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30   29   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31   30   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32   31   * SUCH DAMAGE.
  33   32   */
  34   33  
       34 +/*
       35 + * Copyright 2018 Nexenta Systems, Inc.
       36 + */
       37 +
  35   38  #include "lint.h"
  36      -#include "file64.h"
       39 +
  37   40  #include <sys/types.h>
  38      -#include <stdio.h>
  39      -#include <string.h>
       41 +
  40   42  #include <limits.h>
  41      -#include <stdlib.h>
  42   43  #include <regex.h>
       44 +#include <stdlib.h>
       45 +#include <string.h>
  43   46  
  44      -#include "utils.h"
  45   47  #include "../gen/_libc_gettext.h"
  46   48  
  47      -static const char *regatoi(const regex_t *preg, char *localbuf);
  48      -
  49   49  #define RERR(x, msg)    { x, #x, msg }
  50   50  
  51   51  static struct rerr {
  52   52          int code;
  53   53          const char *name;
  54   54          const char *explain;
  55   55  } rerrs[] = {
  56   56          RERR(REG_NOMATCH,       "regexec() failed to match"),
  57   57          RERR(REG_BADPAT,        "invalid regular expression"),
  58   58          RERR(REG_ECOLLATE,      "invalid collating element"),
  59   59          RERR(REG_ECTYPE,        "invalid character class"),
  60   60          RERR(REG_EESCAPE,       "trailing backslash (\\)"),
  61   61          RERR(REG_ESUBREG,       "invalid backreference number"),
  62   62          RERR(REG_EBRACK,        "brackets ([ ]) not balanced"),
  63   63          RERR(REG_EPAREN,        "parentheses not balanced"),
  64   64          RERR(REG_EBRACE,        "braces not balanced"),
  65   65          RERR(REG_BADBR,         "invalid repetition count(s)"),
  66   66          RERR(REG_ERANGE,        "invalid character range"),
  67   67          RERR(REG_ESPACE,        "out of memory"),
  68   68          RERR(REG_BADRPT,        "repetition-operator operand invalid"),
  69      -#ifdef  REG_EMPTY
  70   69          RERR(REG_EMPTY,         "empty (sub)expression"),
  71      -#endif
  72      -        RERR(REG_EFATAL,        "fatal internal error"),
  73      -#ifdef  REG_INVARG
  74   70          RERR(REG_INVARG,        "invalid argument to regex routine"),
  75      -#endif
  76      -        RERR(REG_ECHAR,         "illegal byte sequence"),
  77      -        RERR(REG_ENOSYS,        "function not supported"),
  78      -        RERR(REG_STACK,         "backtrack stack overflow"),
  79      -        RERR(REG_ENSUB,         "more than 9 \\( \\) pairs"),
  80      -        RERR(REG_ENEWLINE,      "\n found before end of pattern"),
       71 +        RERR(REG_ILLSEQ,        "illegal byte sequence"),
  81   72          {0,     "",             "*** unknown regexp error code ***"}
  82   73  };
  83   74  
  84   75  
  85   76  /*
  86      - * regerror - the interface to error numbers
       77 + * The interface to error numbers
  87   78   */
  88   79  /* ARGSUSED */
  89   80  size_t
  90   81  regerror(int errcode, const regex_t *_RESTRICT_KYWD preg,
  91   82      char *_RESTRICT_KYWD errbuf, size_t errbuf_size)
  92   83  {
  93   84          struct rerr *r;
  94   85          size_t len;
  95      -        int target = errcode &~ REG_ITOA;
  96   86          const char *s;
  97      -        char convbuf[50];
  98   87  
  99      -        if (errcode == REG_ATOI) {
 100      -                s = regatoi(preg, convbuf);
 101      -        } else {
 102      -                for (r = rerrs; r->code != 0; r++) {
 103      -                        if (r->code == target)
 104      -                                break;
 105      -                }
 106      -
 107      -                if (errcode&REG_ITOA) {
 108      -                        if (r->code != 0)
 109      -                                (void) strcpy(convbuf, r->name);
 110      -                        else
 111      -                                (void) sprintf(convbuf, "REG_0x%x", target);
 112      -                        assert(strlen(convbuf) < sizeof (convbuf));
 113      -                        s = convbuf;
 114      -                } else {
 115      -                        s = _libc_gettext(r->explain);
 116      -                }
       88 +        for (r = rerrs; r->code != 0; r++) {
       89 +                if (r->code == errcode)
       90 +                        break;
 117   91          }
 118   92  
       93 +        s = _libc_gettext(r->explain);
       94 +
 119   95          len = strlen(s) + 1;
 120      -        if (errbuf_size > 0) {
       96 +        if (errbuf != NULL && errbuf_size > 0) {
 121   97                  if (errbuf_size > len) {
 122   98                          (void) strcpy(errbuf, s);
 123   99                  } else {
 124      -                        (void) strncpy(errbuf, s, errbuf_size-1);
 125      -                        errbuf[errbuf_size-1] = '\0';
      100 +                        (void) strncpy(errbuf, s, errbuf_size - 1);
      101 +                        errbuf[errbuf_size - 1] = '\0';
 126  102                  }
 127  103          }
 128  104  
 129  105          return (len);
 130      -}
 131      -
 132      -/*
 133      - * regatoi - internal routine to implement REG_ATOI
 134      - */
 135      -static const char *
 136      -regatoi(const regex_t *preg, char *localbuf)
 137      -{
 138      -        struct rerr *r;
 139      -
 140      -        for (r = rerrs; r->code != 0; r++) {
 141      -                if (strcmp(r->name, preg->re_endp) == 0)
 142      -                        break;
 143      -        }
 144      -        if (r->code == 0)
 145      -                return ("0");
 146      -
 147      -        (void) sprintf(localbuf, "%d", r->code);
 148      -        return (localbuf);
 149  106  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX