2 tre_regerror.c - POSIX tre_regerror() implementation for TRE.
4 This software is released under a BSD-style license.
5 See the file LICENSE for details and copyright.
11 #endif /* HAVE_CONFIG_H */
16 #endif /* HAVE_WCHAR_H */
19 #endif /* HAVE_WCTYPE_H */
21 #include "tre-internal.h"
27 #define dgettext(p, s) s
31 #define _(String) dgettext(PACKAGE, String)
32 #define gettext_noop(String) String
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 gettext_noop("Empty (sub)expression"), /* REG_EMPTY */
52 gettext_noop("Invalid argument to regex routine"), /* REG_INVARG */
53 gettext_noop("Illegal byte sequence") /* REG_ILLSEQ */
57 tre_regerror(int errcode
, const regex_t
* __restrict preg
,
58 char * __restrict errbuf
, size_t errbuf_size
)
63 /*LINTED*/(void)&preg
;
65 && errcode
< (int)(sizeof(tre_error_messages
)
66 / sizeof(*tre_error_messages
)))
67 err
= gettext(tre_error_messages
[errcode
]);
69 err
= gettext("Unknown error");
71 err_len
= strlen(err
) + 1;
72 if (errbuf_size
> 0 && errbuf
!= NULL
)
74 if (err_len
> errbuf_size
)
76 strncpy(errbuf
, err
, errbuf_size
- 1);
77 errbuf
[errbuf_size
- 1] = '\0';