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