]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/RegularExpressionDxe/Oniguruma/regposerr.c
MdeModulePkg RegularExpressionDxe: Update Oniguruma to 6.9.0
[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
b602265d 5 * Copyright (c) 2002-2018 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
40#if 0\r
41#ifdef HAVE_STRING_H\r
42# include <string.h>\r
43#else\r
44# include <strings.h>\r
45#endif\r
46#endif\r
47\r
48#if defined(__GNUC__)\r
49# define ARG_UNUSED __attribute__ ((unused))\r
50#else\r
51# define ARG_UNUSED\r
52#endif\r
53\r
b602265d
DG
54#if defined(_WIN32) && !defined(__GNUC__)\r
55#define xsnprintf sprintf_s\r
56#define xstrncpy(dest,src,size) strncpy_s(dest,size,src,_TRUNCATE)\r
57#else\r
58#define xsnprintf snprintf\r
59#define xstrncpy strncpy\r
60#endif\r
61\r
14b0e578
CS
62static char* ESTRING[] = {\r
63 NULL,\r
64 "failed to match", /* REG_NOMATCH */\r
65 "Invalid regular expression", /* REG_BADPAT */\r
66 "invalid collating element referenced", /* REG_ECOLLATE */\r
67 "invalid character class type referenced", /* REG_ECTYPE */\r
68 "bad backslash-escape sequence", /* REG_EESCAPE */\r
69 "invalid back reference number", /* REG_ESUBREG */\r
70 "imbalanced [ and ]", /* REG_EBRACK */\r
71 "imbalanced ( and )", /* REG_EPAREN */\r
72 "imbalanced { and }", /* REG_EBRACE */\r
73 "invalid repeat range {n,m}", /* REG_BADBR */\r
74 "invalid range", /* REG_ERANGE */\r
75 "Out of memory", /* REG_ESPACE */\r
76 "? * + not preceded by valid regular expression", /* REG_BADRPT */\r
77\r
78 /* Extended errors */\r
79 "internal error", /* REG_EONIG_INTERNAL */\r
80 "invalid wide char value", /* REG_EONIG_BADWC */\r
b602265d 81 "invalid argument" /* REG_EONIG_BADARG */\r
14b0e578
CS
82};\r
83\r
84//#include <stdio.h>\r
85\r
86\r
87extern size_t\r
88regerror(int posix_ecode, const regex_t* reg ARG_UNUSED, char* buf,\r
89 size_t size)\r
90{\r
91 char* s;\r
92 char tbuf[35];\r
93 size_t len;\r
94\r
95 if (posix_ecode > 0\r
96 && posix_ecode < (int )(sizeof(ESTRING) / sizeof(ESTRING[0]))) {\r
97 s = ESTRING[posix_ecode];\r
98 }\r
99 else if (posix_ecode == 0) {\r
100 s = "";\r
101 }\r
102 else {\r
61e078dd 103 sprintf_s(tbuf, sizeof(tbuf), "undefined error code (%d)", posix_ecode);\r
14b0e578
CS
104 s = tbuf;\r
105 }\r
106\r
107 len = strlen_s(s, MAX_STRING_SIZE) + 1; /* use strlen() because s is ascii encoding. */\r
108\r
109 if (buf != NULL && size > 0) {\r
110 strncpy_s(buf, size, s, size - 1);\r
111 buf[size - 1] = '\0';\r
112 }\r
113 return len;\r
114}\r