X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fregex%2Fregerror.c;h=0645b8e72cb3cd8711885948846b888bdb10685a;hp=39d70b2a0672f1a5c02a457fa7d9bbdd7bf6f7d6;hb=fcaec912ed406659832f452e71a6c965308362dd;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 diff --git a/src/regex/regerror.c b/src/regex/regerror.c index 39d70b2a..0645b8e7 100644 --- a/src/regex/regerror.c +++ b/src/regex/regerror.c @@ -1,26 +1,6 @@ -/* - regerror.c - POSIX regerror() implementation for TRE. - - Copyright (c) 2001-2006 Ville Laurikari . - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - #include #include +#include /* Error message strings for error codes listed in `regex.h'. This list needs to be in sync with the codes listed there, naturally. */ @@ -28,7 +8,7 @@ /* Converted to single string by Rich Felker to remove the need for * data relocations at runtime, 27 Feb 2006. */ -static const char tre_error_messages[] = { +static const char messages[] = { "No error\0" "No match\0" "Invalid regexp\0" @@ -42,34 +22,14 @@ static const char tre_error_messages[] = { "Invalid contents of {}\0" "Invalid character range\0" "Out of memory\0" - "XXX\0" + "Repetition not preceded by valid expression\0" + "\0Unknown error" }; -size_t -regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) +size_t regerror(int e, const regex_t *preg, char *buf, size_t size) { - const char *err; - size_t err_len; - - if (errcode >= 0 && errcode <= REG_BADRPT) - for (err=tre_error_messages; errcode; errcode--, err+=strlen(err)+1); - else - err = "Unknown error"; - - err_len = strlen(err) + 1; - if (errbuf_size > 0 && errbuf != NULL) - { - if (err_len > errbuf_size) - { - memcpy(errbuf, err, errbuf_size - 1); - errbuf[errbuf_size - 1] = '\0'; - } - else - { - strcpy(errbuf, err); - } - } - return err_len; + const char *s; + for (s=messages; e && *s; e--, s+=strlen(s)+1); + if (!*s) s++; + return 1+snprintf(buf, size, "%s", s); } - -/* EOF */