xref: /illumos-gate/usr/src/lib/libc/port/i18n/wcstoimax.c (revision a07094369b21309434206d9b3601d162693466fc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include "synonyms.h"
31 #include <stddef.h>
32 #include <inttypes.h>
33 #include <wchar.h>
34 
35 /*
36  * In _LP64
37  *	intmax_t and uintmax_t are always equivalent to
38  *	int64_t and uint64_t, respectively.
39  *
40  * In _ILP32
41  *	intmax_t and uintmax_t are equivalent to int64_t and uint64_t,
42  *	respectively, when the following both conditions become
43  *	true:
44  *		- strict c89 mode is not used
45  *		- _NO_LONGLONG is not defined
46  *	Otherwise, intmax_t and uintmax_t are equivalent to
47  *	int32_t and uint32_t, respectively.
48  *
49  * libc is compiled neither in strict-c89 mode nor is _NO_LONGLONG
50  * defined.
51  */
52 
53 /* for int64_t instance */
54 intmax_t
55 wcstoimax(const wchar_t *nptr, wchar_t **endptr, int base)
56 {
57 	return ((intmax_t)wcstoll(nptr, endptr, base));
58 }
59 
60 /* for uint64_t instance */
61 uintmax_t
62 wcstoumax(const wchar_t *nptr, wchar_t **endptr, int base)
63 {
64 	return ((uintmax_t)wcstoull(nptr, endptr, base));
65 }
66 
67 #if	!defined(_LP64)
68 /* for int32_t instance */
69 int32_t
70 _wcstoimax_c89(const wchar_t *nptr, wchar_t **endptr, int base)
71 {
72 	return ((int32_t)wcstol(nptr, endptr, base));
73 }
74 
75 /* for int32_t instance */
76 uint32_t
77 _wcstoumax_c89(const wchar_t *nptr, wchar_t **endptr, int base)
78 {
79 	return ((uint32_t)wcstoul(nptr, endptr, base));
80 }
81 #endif
82