+++ /dev/null
-/** @file\r
- Copyright (c) 2010 - 2011, 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.\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
- @(#)strtol.c 8.1 (Berkeley) 6/4/93\r
- NetBSD: wcstol.c,v 1.1 2001/09/27 16:30:36 yamt Exp\r
- Citrus: xpg4dl/FreeBSD/lib/libc/locale/wcstol.c,v 1.2 2001/09/21 16:11:41 yamt Exp\r
- NetBSD: _wcstol.h,v 1.3 2005/11/29 03:11:59 christos Exp\r
- */\r
-\r
-/*\r
- * function template for wcstol, wcstoll and wcstoimax.\r
- *\r
- * parameters:\r
- * _FUNCNAME : function name\r
- * __wINT : return type\r
- * __wINT_MIN : lower limit of the return type\r
- * __wINT_MAX : upper limit of the return type\r
- */\r
-\r
-__wINT\r
-_FUNCNAME(\r
- const wchar_t *nptr,\r
- wchar_t **endptr,\r
- int base\r
- )\r
-{\r
- const wchar_t *s;\r
- __wINT 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
-#ifdef __GNUC__\r
- (void)&acc; (void)&cutoff;\r
-#endif\r
-\r
- /* check base value */\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 strtol for comments as to the logic used.\r
- */\r
- cutoff = neg ? __wINT_MIN : __wINT_MAX;\r
- cutlim = (int)(cutoff % base);\r
- cutoff /= base;\r
- if (neg) {\r
- if (cutlim > 0) {\r
- cutlim -= base;\r
- cutoff += 1;\r
- }\r
- cutlim = -cutlim;\r
- }\r
- for (acc = 0, any = 0;; wc = (wchar_t) *s++) {\r
- i = __wctoint((wchar_t)wc);\r
- if (i == -1)\r
- break;\r
- if (i >= base)\r
- break;\r
- if (any < 0)\r
- continue;\r
- if (neg) {\r
- if (acc < cutoff || (acc == cutoff && i > cutlim)) {\r
- any = -1;\r
- acc = __wINT_MIN;\r
- errno = ERANGE;\r
- } else {\r
- any = 1;\r
- acc *= base;\r
- acc -= i;\r
- }\r
- } else {\r
- if (acc > cutoff || (acc == cutoff && i > cutlim)) {\r
- any = -1;\r
- acc = __wINT_MAX;\r
- errno = ERANGE;\r
- } else {\r
- any = 1;\r
- acc *= base;\r
- acc += i;\r
- }\r
- }\r
- }\r
- if (endptr != 0)\r
- *endptr = __UNCONST(any ? s - 1 : nptr);\r
- return (acc);\r
-}\r