+++ /dev/null
-/** @file\r
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
- Copyright (c) 1990, 1993\r
- The Regents of the University of California. All rights reserved.\r
-\r
- Redistribution and use in source and binary forms, with or without\r
- modification, are permitted provided that the following conditions\r
- are met:\r
- 1. Redistributions of source code must retain the above copyright\r
- notice, this list of conditions and the following disclaimer.\r
- 2. Redistributions in binary form must reproduce the above copyright\r
- notice, this list of conditions and the following disclaimer in the\r
- documentation and/or other materials provided with the distribution.\r
- 3. Neither the name of the University nor the names of its contributors\r
- may be used to endorse or promote products derived from this software\r
- without specific prior written permission.\r
-\r
- THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
- SUCH DAMAGE.\r
-\r
- Original version ID:\r
- @(#)strtoul.c 8.1 (Berkeley) 6/4/93\r
- Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstoul.c,v 1.2 2001/09/21 16:11:41 yamt Exp\r
- NetBSD: wcstoul.c,v 1.1 2001/09/27 16:30:37 yamt Exp\r
- NetBSD: _wcstoul.h,v 1.3 2005/11/29 03:11:59 christos Exp\r
- */\r
-\r
-#include <Library/BaseLib.h>\r
-\r
-/*\r
- * function template for wcstoul, wcstoull and wcstoumax.\r
- *\r
- * parameters:\r
- * _FUNCNAME : function name\r
- * __wUINT : return type\r
- * __wINT : signed version of __wUINT\r
- * __wUINT_MAX : upper limit of the return type\r
- */\r
-\r
-__wUINT\r
-_FUNCNAME(\r
- const wchar_t *nptr,\r
- wchar_t **endptr,\r
- int base\r
- )\r
-{\r
- const wchar_t *s;\r
- __wUINT acc, cutoff;\r
- wint_t wc;\r
- int i;\r
- int neg, any, cutlim;\r
-\r
- _DIAGASSERT(nptr != NULL);\r
- /* endptr may be NULL */\r
-\r
- if (base && (base < 2 || base > 36)) {\r
- errno = EINVAL;\r
- return 0;\r
- }\r
-\r
- /*\r
- * Skip white space and pick up leading +/- sign if any.\r
- * If base is 0, allow 0x for hex and 0 for octal, else\r
- * assume decimal; if base is already 16, allow 0x.\r
- */\r
- s = nptr;\r
- do {\r
- wc = (wchar_t) *s++;\r
- } while (iswspace(wc));\r
- if (wc == L'-') {\r
- neg = 1;\r
- wc = *s++;\r
- } else {\r
- neg = 0;\r
- if (wc == L'+')\r
- wc = *s++;\r
- }\r
- if ((base == 0 || base == 16) &&\r
- wc == L'0' && (*s == L'x' || *s == L'X')) {\r
- wc = s[1];\r
- s += 2;\r
- base = 16;\r
- }\r
- if (base == 0)\r
- base = wc == L'0' ? 8 : 10;\r
-\r
- /*\r
- * See strtoul for comments as to the logic used.\r
- */\r
- cutoff = (__wUINT)DivU64x32 ((UINT64) __wUINT_MAX, (UINT32) base);\r
- cutlim = (int) ModU64x32 ((UINT64) __wUINT_MAX, (UINT32) base);\r
- for (acc = 0, any = 0;; wc = (wint_t) *s++) {\r
- i = __wctoint((wchar_t)wc);\r
- if (i == -1) {\r
- break;\r
- }\r
- if (i >= base)\r
- break;\r
- if (any < 0)\r
- continue;\r
- if (acc > cutoff || (acc == cutoff && i > cutlim)) {\r
- any = -1;\r
- acc = __wUINT_MAX;\r
- errno = ERANGE;\r
- } else {\r
- any = 1;\r
- acc *= (__wUINT)base;\r
- acc += i;\r
- }\r
- }\r
- if (neg && any > 0)\r
- acc = (__wUINT)(-((__wINT)acc));\r
- if (endptr != 0)\r
- *endptr = __UNCONST(any ? s - 1 : nptr);\r
- return (acc);\r
-}\r