source: mainline/uspace/lib/posix/src/locale.c@ d92060f

Last change on this file since d92060f was 1b20da0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on non-empty lines, in certain file types.

Command used: tools/srepl '\([^[:space:]]\)\s\+$' '\1' -- *.c *.h *.py *.sh *.s *.S *.ag

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