source: mainline/uspace/lib/posix/locale.c@ 5273eb6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5273eb6 was 324d46b, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 14 years ago

Partial time.h implementation (WIP, untested)

  • Property mode set to 100644
File size: 3.5 KB
Line 
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
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
44struct __posix_locale {
45 int _dummy;
46};
47
48const struct posix_lconv C_LOCALE = {
49 .currency_symbol = (char *) "",
50 .decimal_point = (char *) ".",
51 .frac_digits = CHAR_MAX,
52 .grouping = (char *) "",
53 .int_curr_symbol = (char *) "",
54 .int_frac_digits = CHAR_MAX,
55 .int_n_cs_precedes = CHAR_MAX,
56 .int_n_sep_by_space = CHAR_MAX,
57 .int_n_sign_posn = CHAR_MAX,
58 .int_p_cs_precedes = CHAR_MAX,
59 .int_p_sep_by_space = CHAR_MAX,
60 .int_p_sign_posn = CHAR_MAX,
61 .mon_decimal_point = (char *) "",
62 .mon_grouping = (char *) "",
63 .mon_thousands_sep = (char *) "",
64 .negative_sign = (char *) "",
65 .n_cs_precedes = CHAR_MAX,
66 .n_sep_by_space = CHAR_MAX,
67 .n_sign_posn = CHAR_MAX,
68 .positive_sign = (char *) "",
69 .p_cs_precedes = CHAR_MAX,
70 .p_sep_by_space = CHAR_MAX,
71 .p_sign_posn = CHAR_MAX,
72 .thousands_sep = (char *) ""
73};
74
75char *posix_setlocale(int category, const char *locale)
76{
77 // TODO
78 if (locale == NULL || *locale == '\0' ||
79 posix_strcmp(locale, "C") == 0) {
80 return (char *) "C";
81 }
82 return NULL;
83}
84
85struct posix_lconv *posix_localeconv(void)
86{
87 // TODO
88 return (struct posix_lconv *) &C_LOCALE;
89}
90
91posix_locale_t posix_duplocale(posix_locale_t locobj)
92{
93 if (locobj == NULL) {
94 errno = EINVAL;
95 return NULL;
96 }
97 posix_locale_t copy = malloc(sizeof(struct __posix_locale));
98 if (copy == NULL) {
99 errno = ENOMEM;
100 return NULL;
101 }
102 memcpy(copy, locobj, sizeof(struct __posix_locale));
103 return copy;
104}
105
106void posix_freelocale(posix_locale_t locobj)
107{
108 free(locobj);
109}
110
111posix_locale_t posix_newlocale(int category_mask, const char *locale,
112 posix_locale_t base)
113{
114 if (locale == NULL ||
115 (category_mask & LC_ALL_MASK) != category_mask) {
116 errno = EINVAL;
117 return NULL;
118 }
119 // TODO
120 posix_locale_t new = malloc(sizeof(struct __posix_locale));
121 if (new == NULL) {
122 errno = ENOMEM;
123 return NULL;
124 }
125 if (base != NULL) {
126 posix_freelocale(base);
127 }
128 return new;
129}
130
131posix_locale_t posix_uselocale (posix_locale_t newloc)
132{
133 // TODO
134 return NULL;
135}
136
137/** @}
138 */
Note: See TracBrowser for help on using the repository browser.