Coverage Report

Created: 2026-09-14 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/r-source/src/extra/tre/regerror.c
Line
Count
Source
1
/*
2
  tre_regerror.c - POSIX tre_regerror() implementation for TRE.
3
4
  This software is released under a BSD-style license.
5
  See the file LICENSE for details and copyright.
6
7
*/
8
9
#ifdef HAVE_CONFIG_H
10
#include <config.h>
11
#endif /* HAVE_CONFIG_H */
12
13
#include <string.h>
14
#ifdef HAVE_WCHAR_H
15
#include <wchar.h>
16
#endif /* HAVE_WCHAR_H */
17
#ifdef HAVE_WCTYPE_H
18
#include <wctype.h>
19
#endif /* HAVE_WCTYPE_H */
20
21
#include "tre-internal.h"
22
#include "tre.h"
23
24
#ifdef HAVE_GETTEXT
25
#include <libintl.h>
26
#else
27
#define dgettext(p, s) s
28
#define gettext(s) s
29
#endif
30
31
#define _(String) dgettext(PACKAGE, String)
32
#define gettext_noop(String) String
33
34
/* Error message strings for error codes listed in `tre.h'.  This list
35
   needs to be in sync with the codes listed there, naturally. */
36
static const char *tre_error_messages[] =
37
  { gettext_noop("No error"),        /* REG_OK */
38
    gettext_noop("No match"),        /* REG_NOMATCH */
39
    gettext_noop("Invalid regexp"),      /* REG_BADPAT */
40
    gettext_noop("Unknown collating element"),     /* REG_ECOLLATE */
41
    gettext_noop("Unknown character class name"),  /* REG_ECTYPE */
42
    gettext_noop("Trailing backslash"),      /* REG_EESCAPE */
43
    gettext_noop("Invalid back reference"),    /* REG_ESUBREG */
44
    gettext_noop("Missing ']'"),       /* REG_EBRACK */
45
    gettext_noop("Missing ')'"),       /* REG_EPAREN */
46
    gettext_noop("Missing '}'"),       /* REG_EBRACE */
47
    gettext_noop("Invalid contents of {}"),    /* REG_BADBR */
48
    gettext_noop("Invalid character range"),     /* REG_ERANGE */
49
    gettext_noop("Out of memory"),       /* REG_ESPACE */
50
    gettext_noop("Invalid use of repetition operators")  /* REG_BADRPT */
51
  };
52
53
size_t
54
tre_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
55
0
{
56
0
  const char *err;
57
0
  size_t err_len;
58
59
  /*LINTED*/(void)&preg;
60
0
  if (errcode >= 0
61
0
      && errcode < (int)(sizeof(tre_error_messages)
62
0
       / sizeof(*tre_error_messages)))
63
0
    err = gettext(tre_error_messages[errcode]);
64
0
  else
65
0
    err = gettext("Unknown error");
66
67
0
  err_len = strlen(err) + 1;
68
0
  if (errbuf_size > 0 && errbuf != NULL)
69
0
    {
70
0
      if (err_len > errbuf_size)
71
0
  {
72
0
    strncpy(errbuf, err, errbuf_size - 1);
73
0
    errbuf[errbuf_size - 1] = '\0';
74
0
  }
75
0
      else
76
0
  {
77
0
    strcpy(errbuf, err);
78
0
  }
79
0
    }
80
0
  return err_len;
81
0
}
82
83
/* EOF */