1 | /*
|
---|
2 | * Copyright (c) 2011 Jiri Zarevucky
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libposix
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file Locale-specific definitions.
|
---|
33 | */
|
---|
34 |
|
---|
35 | #define LIBPOSIX_INTERNAL
|
---|
36 |
|
---|
37 | #include "internal/common.h"
|
---|
38 | #include "locale.h"
|
---|
39 |
|
---|
40 | #include "errno.h"
|
---|
41 | #include "limits.h"
|
---|
42 | #include "string.h"
|
---|
43 |
|
---|
44 | // TODO: documentation
|
---|
45 |
|
---|
46 | struct __posix_locale {
|
---|
47 | int _dummy;
|
---|
48 | };
|
---|
49 |
|
---|
50 | const struct posix_lconv C_LOCALE = {
|
---|
51 | .currency_symbol = (char *) "",
|
---|
52 | .decimal_point = (char *) ".",
|
---|
53 | .frac_digits = CHAR_MAX,
|
---|
54 | .grouping = (char *) "",
|
---|
55 | .int_curr_symbol = (char *) "",
|
---|
56 | .int_frac_digits = CHAR_MAX,
|
---|
57 | .int_n_cs_precedes = CHAR_MAX,
|
---|
58 | .int_n_sep_by_space = CHAR_MAX,
|
---|
59 | .int_n_sign_posn = CHAR_MAX,
|
---|
60 | .int_p_cs_precedes = CHAR_MAX,
|
---|
61 | .int_p_sep_by_space = CHAR_MAX,
|
---|
62 | .int_p_sign_posn = CHAR_MAX,
|
---|
63 | .mon_decimal_point = (char *) "",
|
---|
64 | .mon_grouping = (char *) "",
|
---|
65 | .mon_thousands_sep = (char *) "",
|
---|
66 | .negative_sign = (char *) "",
|
---|
67 | .n_cs_precedes = CHAR_MAX,
|
---|
68 | .n_sep_by_space = CHAR_MAX,
|
---|
69 | .n_sign_posn = CHAR_MAX,
|
---|
70 | .positive_sign = (char *) "",
|
---|
71 | .p_cs_precedes = CHAR_MAX,
|
---|
72 | .p_sep_by_space = CHAR_MAX,
|
---|
73 | .p_sign_posn = CHAR_MAX,
|
---|
74 | .thousands_sep = (char *) ""
|
---|
75 | };
|
---|
76 |
|
---|
77 | /**
|
---|
78 | *
|
---|
79 | * @param category
|
---|
80 | * @param locale
|
---|
81 | * @return
|
---|
82 | */
|
---|
83 | char *posix_setlocale(int category, const char *locale)
|
---|
84 | {
|
---|
85 | // TODO
|
---|
86 | if (locale == NULL || *locale == '\0' ||
|
---|
87 | posix_strcmp(locale, "C") == 0) {
|
---|
88 | return (char *) "C";
|
---|
89 | }
|
---|
90 | return NULL;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | *
|
---|
95 | * @return
|
---|
96 | */
|
---|
97 | struct posix_lconv *posix_localeconv(void)
|
---|
98 | {
|
---|
99 | // TODO
|
---|
100 | return (struct posix_lconv *) &C_LOCALE;
|
---|
101 | }
|
---|
102 |
|
---|
103 | /**
|
---|
104 | *
|
---|
105 | * @param locobj
|
---|
106 | * @return
|
---|
107 | */
|
---|
108 | posix_locale_t posix_duplocale(posix_locale_t locobj)
|
---|
109 | {
|
---|
110 | if (locobj == NULL) {
|
---|
111 | errno = EINVAL;
|
---|
112 | return NULL;
|
---|
113 | }
|
---|
114 | posix_locale_t copy = malloc(sizeof(struct __posix_locale));
|
---|
115 | if (copy == NULL) {
|
---|
116 | errno = ENOMEM;
|
---|
117 | return NULL;
|
---|
118 | }
|
---|
119 | memcpy(copy, locobj, sizeof(struct __posix_locale));
|
---|
120 | return copy;
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | *
|
---|
125 | * @param locobj
|
---|
126 | */
|
---|
127 | void posix_freelocale(posix_locale_t locobj)
|
---|
128 | {
|
---|
129 | if (locobj) {
|
---|
130 | free(locobj);
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | *
|
---|
136 | * @param category_mask
|
---|
137 | * @param locale
|
---|
138 | * @param base
|
---|
139 | * @return
|
---|
140 | */
|
---|
141 | posix_locale_t posix_newlocale(int category_mask, const char *locale,
|
---|
142 | posix_locale_t base)
|
---|
143 | {
|
---|
144 | if (locale == NULL ||
|
---|
145 | (category_mask & LC_ALL_MASK) != category_mask) {
|
---|
146 | errno = EINVAL;
|
---|
147 | return NULL;
|
---|
148 | }
|
---|
149 | // TODO
|
---|
150 | posix_locale_t new = malloc(sizeof(struct __posix_locale));
|
---|
151 | if (new == NULL) {
|
---|
152 | errno = ENOMEM;
|
---|
153 | return NULL;
|
---|
154 | }
|
---|
155 | if (base != NULL) {
|
---|
156 | posix_freelocale(base);
|
---|
157 | }
|
---|
158 | return new;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /**
|
---|
162 | *
|
---|
163 | * @param newloc
|
---|
164 | * @return
|
---|
165 | */
|
---|
166 | posix_locale_t posix_uselocale(posix_locale_t newloc)
|
---|
167 | {
|
---|
168 | // TODO
|
---|
169 | return NULL;
|
---|
170 | }
|
---|
171 |
|
---|
172 | /** @}
|
---|
173 | */
|
---|