]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regposerr.c
MdeModulePkg RegularExpressionDxe: Update Oniguruma from v6.9.0 to v6.9.3
[mirror_edk2.git] / MdeModulePkg / Universal / RegularExpressionDxe / Oniguruma / regposerr.c
CommitLineData
14b0e578
CS
1/**********************************************************************\r
2 regposerr.c - Oniguruma (regular expression library)\r
3**********************************************************************/\r
4/*-\r
b26691c4 5 * Copyright (c) 2002-2019 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>\r
14b0e578
CS
6 * All rights reserved.\r
7 *\r
14b0e578
CS
8 * Redistribution and use in source and binary forms, with or without\r
9 * modification, are permitted provided that the following conditions\r
10 * are met:\r
11 * 1. Redistributions of source code must retain the above copyright\r
12 * notice, this list of conditions and the following disclaimer.\r
13 * 2. Redistributions in binary form must reproduce the above copyright\r
14 * notice, this list of conditions and the following disclaimer in the\r
15 * documentation and/or other materials provided with the distribution.\r
16 *\r
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
27 * SUCH DAMAGE.\r
28 */\r
29\r
b602265d
DG
30/* Can't include regint.h etc.. for conflict of regex_t.\r
31 Define ONIGURUMA_EXPORT here for onigposix.h.\r
32 */\r
33#ifndef ONIGURUMA_EXPORT\r
34#define ONIGURUMA_EXPORT\r
35#endif\r
36\r
37//#include "config.h"\r
14b0e578
CS
38#include "onigposix.h"\r
39\r
b26691c4 40//#include <string.h>\r
14b0e578
CS
41\r
42#if defined(__GNUC__)\r
43# define ARG_UNUSED __attribute__ ((unused))\r
44#else\r
45# define ARG_UNUSED\r
46#endif\r
47\r
b602265d
DG
48#if defined(_WIN32) && !defined(__GNUC__)\r
49#define xsnprintf sprintf_s\r
50#define xstrncpy(dest,src,size) strncpy_s(dest,size,src,_TRUNCATE)\r
51#else\r
52#define xsnprintf snprintf\r
53#define xstrncpy strncpy\r
54#endif\r
55\r
14b0e578
CS
56static char* ESTRING[] = {\r
57 NULL,\r
58 "failed to match", /* REG_NOMATCH */\r
59 "Invalid regular expression", /* REG_BADPAT */\r
60 "invalid collating element referenced", /* REG_ECOLLATE */\r
61 "invalid character class type referenced", /* REG_ECTYPE */\r
62 "bad backslash-escape sequence", /* REG_EESCAPE */\r
63 "invalid back reference number", /* REG_ESUBREG */\r
64 "imbalanced [ and ]", /* REG_EBRACK */\r
65 "imbalanced ( and )", /* REG_EPAREN */\r
66 "imbalanced { and }", /* REG_EBRACE */\r
67 "invalid repeat range {n,m}", /* REG_BADBR */\r
68 "invalid range", /* REG_ERANGE */\r
69 "Out of memory", /* REG_ESPACE */\r
70 "? * + not preceded by valid regular expression", /* REG_BADRPT */\r
71\r
72 /* Extended errors */\r
73 "internal error", /* REG_EONIG_INTERNAL */\r
74 "invalid wide char value", /* REG_EONIG_BADWC */\r
b602265d 75 "invalid argument" /* REG_EONIG_BADARG */\r
14b0e578
CS
76};\r
77\r
78//#include <stdio.h>\r
79\r
80\r
81extern size_t\r
82regerror(int posix_ecode, const regex_t* reg ARG_UNUSED, char* buf,\r
b26691c4 83 size_t size)\r
14b0e578
CS
84{\r
85 char* s;\r
86 char tbuf[35];\r
87 size_t len;\r
88\r
89 if (posix_ecode > 0\r
90 && posix_ecode < (int )(sizeof(ESTRING) / sizeof(ESTRING[0]))) {\r
91 s = ESTRING[posix_ecode];\r
92 }\r
93 else if (posix_ecode == 0) {\r
94 s = "";\r
95 }\r
96 else {\r
61e078dd 97 sprintf_s(tbuf, sizeof(tbuf), "undefined error code (%d)", posix_ecode);\r
14b0e578
CS
98 s = tbuf;\r
99 }\r
100\r
101 len = strlen_s(s, MAX_STRING_SIZE) + 1; /* use strlen() because s is ascii encoding. */\r
102\r
103 if (buf != NULL && size > 0) {\r
104 strncpy_s(buf, size, s, size - 1);\r
105 buf[size - 1] = '\0';\r
106 }\r
107 return len;\r
108}\r