[d9eaa43] | 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 | */
|
---|
[4cf8ca6] | 32 | /** @file Locale-specific definitions.
|
---|
[d9eaa43] | 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 |
|
---|
[4c8f5e7] | 44 | /* Just a very basic dummy implementation.
|
---|
| 45 | * This should allow code using locales to work properly, but doesn't provide
|
---|
| 46 | * any localization functionality.
|
---|
| 47 | * Should be extended/rewritten when or if HelenOS supports locales natively.
|
---|
| 48 | */
|
---|
[4cf8ca6] | 49 |
|
---|
[324d46b] | 50 | struct __posix_locale {
|
---|
[d9eaa43] | 51 | int _dummy;
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | const struct posix_lconv C_LOCALE = {
|
---|
| 55 | .currency_symbol = (char *) "",
|
---|
| 56 | .decimal_point = (char *) ".",
|
---|
| 57 | .frac_digits = CHAR_MAX,
|
---|
| 58 | .grouping = (char *) "",
|
---|
| 59 | .int_curr_symbol = (char *) "",
|
---|
| 60 | .int_frac_digits = CHAR_MAX,
|
---|
| 61 | .int_n_cs_precedes = CHAR_MAX,
|
---|
| 62 | .int_n_sep_by_space = CHAR_MAX,
|
---|
| 63 | .int_n_sign_posn = CHAR_MAX,
|
---|
| 64 | .int_p_cs_precedes = CHAR_MAX,
|
---|
| 65 | .int_p_sep_by_space = CHAR_MAX,
|
---|
| 66 | .int_p_sign_posn = CHAR_MAX,
|
---|
| 67 | .mon_decimal_point = (char *) "",
|
---|
| 68 | .mon_grouping = (char *) "",
|
---|
| 69 | .mon_thousands_sep = (char *) "",
|
---|
| 70 | .negative_sign = (char *) "",
|
---|
| 71 | .n_cs_precedes = CHAR_MAX,
|
---|
| 72 | .n_sep_by_space = CHAR_MAX,
|
---|
| 73 | .n_sign_posn = CHAR_MAX,
|
---|
| 74 | .positive_sign = (char *) "",
|
---|
| 75 | .p_cs_precedes = CHAR_MAX,
|
---|
| 76 | .p_sep_by_space = CHAR_MAX,
|
---|
| 77 | .p_sign_posn = CHAR_MAX,
|
---|
| 78 | .thousands_sep = (char *) ""
|
---|
| 79 | };
|
---|
| 80 |
|
---|
[4c8f5e7] | 81 | /** Set program locale.
|
---|
[4cf8ca6] | 82 | *
|
---|
[4c8f5e7] | 83 | * @param category What category to set.
|
---|
| 84 | * @param locale Locale name.
|
---|
| 85 | * @return Original locale name on success, NULL on failure.
|
---|
[4cf8ca6] | 86 | */
|
---|
[d9eaa43] | 87 | char *posix_setlocale(int category, const char *locale)
|
---|
| 88 | {
|
---|
| 89 | // TODO
|
---|
| 90 | if (locale == NULL || *locale == '\0' ||
|
---|
| 91 | posix_strcmp(locale, "C") == 0) {
|
---|
| 92 | return (char *) "C";
|
---|
| 93 | }
|
---|
| 94 | return NULL;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[4c8f5e7] | 97 | /** Return locale-specific information.
|
---|
[4cf8ca6] | 98 | *
|
---|
[4c8f5e7] | 99 | * @return Information about the current locale.
|
---|
[4cf8ca6] | 100 | */
|
---|
[324d46b] | 101 | struct posix_lconv *posix_localeconv(void)
|
---|
[d9eaa43] | 102 | {
|
---|
| 103 | // TODO
|
---|
| 104 | return (struct posix_lconv *) &C_LOCALE;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[4c8f5e7] | 107 | /** Duplicate locale object.
|
---|
[4cf8ca6] | 108 | *
|
---|
[4c8f5e7] | 109 | * @param locobj Object to duplicate.
|
---|
| 110 | * @return Duplicated object.
|
---|
[4cf8ca6] | 111 | */
|
---|
[d9eaa43] | 112 | posix_locale_t posix_duplocale(posix_locale_t locobj)
|
---|
| 113 | {
|
---|
| 114 | if (locobj == NULL) {
|
---|
| 115 | errno = EINVAL;
|
---|
| 116 | return NULL;
|
---|
| 117 | }
|
---|
[324d46b] | 118 | posix_locale_t copy = malloc(sizeof(struct __posix_locale));
|
---|
[d9eaa43] | 119 | if (copy == NULL) {
|
---|
| 120 | errno = ENOMEM;
|
---|
| 121 | return NULL;
|
---|
| 122 | }
|
---|
[324d46b] | 123 | memcpy(copy, locobj, sizeof(struct __posix_locale));
|
---|
[d9eaa43] | 124 | return copy;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[4c8f5e7] | 127 | /** Free locale object.
|
---|
[4cf8ca6] | 128 | *
|
---|
[4c8f5e7] | 129 | * @param locobj Object to free.
|
---|
[4cf8ca6] | 130 | */
|
---|
[d9eaa43] | 131 | void posix_freelocale(posix_locale_t locobj)
|
---|
| 132 | {
|
---|
[a12f7f1] | 133 | if (locobj) {
|
---|
| 134 | free(locobj);
|
---|
| 135 | }
|
---|
[d9eaa43] | 136 | }
|
---|
| 137 |
|
---|
[4c8f5e7] | 138 | /** Create or modify a locale object.
|
---|
[4cf8ca6] | 139 | *
|
---|
[4c8f5e7] | 140 | * @param category_mask Mask of categories to be set or modified.
|
---|
| 141 | * @param locale Locale to be used.
|
---|
| 142 | * @param base Object to modify. 0 if new object is to be created.
|
---|
| 143 | * @return The new/modified locale object.
|
---|
[4cf8ca6] | 144 | */
|
---|
[d9eaa43] | 145 | posix_locale_t posix_newlocale(int category_mask, const char *locale,
|
---|
| 146 | posix_locale_t base)
|
---|
| 147 | {
|
---|
| 148 | if (locale == NULL ||
|
---|
| 149 | (category_mask & LC_ALL_MASK) != category_mask) {
|
---|
| 150 | errno = EINVAL;
|
---|
| 151 | return NULL;
|
---|
| 152 | }
|
---|
| 153 | // TODO
|
---|
[324d46b] | 154 | posix_locale_t new = malloc(sizeof(struct __posix_locale));
|
---|
[d9eaa43] | 155 | if (new == NULL) {
|
---|
| 156 | errno = ENOMEM;
|
---|
| 157 | return NULL;
|
---|
| 158 | }
|
---|
| 159 | if (base != NULL) {
|
---|
| 160 | posix_freelocale(base);
|
---|
| 161 | }
|
---|
| 162 | return new;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[4c8f5e7] | 165 | /** Set locale for the current thread.
|
---|
[4cf8ca6] | 166 | *
|
---|
[4c8f5e7] | 167 | * @param newloc Locale to use.
|
---|
| 168 | * @return The previously set locale or LC_GLOBAL_LOCALE
|
---|
[4cf8ca6] | 169 | */
|
---|
| 170 | posix_locale_t posix_uselocale(posix_locale_t newloc)
|
---|
[d9eaa43] | 171 | {
|
---|
| 172 | // TODO
|
---|
[4c8f5e7] | 173 | return LC_GLOBAL_LOCALE;
|
---|
[d9eaa43] | 174 | }
|
---|
| 175 |
|
---|
| 176 | /** @}
|
---|
| 177 | */
|
---|