2 regerror.c - POSIX regerror() implementation for TRE.
4 Copyright (c) 2001-2006 Ville Laurikari <vl@iki.fi>.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 /* Error message strings for error codes listed in `regex.h'. This list
26 needs to be in sync with the codes listed there, naturally. */
28 /* Converted to single string by Rich Felker to remove the need for
29 * data relocations at runtime, 27 Feb 2006. */
31 static const char tre_error_messages[] = {
35 "Unknown collating element\0"
36 "Unknown character class name\0"
37 "Trailing backslash\0"
38 "Invalid back reference\0"
42 "Invalid contents of {}\0"
43 "Invalid character range\0"
49 regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
54 if (errcode >= 0 && errcode <= REG_BADRPT)
55 for (err=tre_error_messages; errcode; errcode--, err+=strlen(err)+1);
57 err = "Unknown error";
59 err_len = strlen(err) + 1;
60 if (errbuf_size > 0 && errbuf != NULL)
62 if (err_len > errbuf_size)
64 memcpy(errbuf, err, errbuf_size - 1);
65 errbuf[errbuf_size - 1] = '\0';