Deleted Added
full compact
setrunelocale.c (231682) setrunelocale.c (231714)
1/*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Paul Borman at Krystal Technologies.
7 *
8 * Copyright (c) 2011 The FreeBSD Foundation

--- 22 unchanged lines hidden (view full) ---

31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Paul Borman at Krystal Technologies.
7 *
8 * Copyright (c) 2011 The FreeBSD Foundation

--- 22 unchanged lines hidden (view full) ---

31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 231682 2012-02-14 14:24:37Z theraven $");
39__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 231714 2012-02-14 21:48:46Z dim $");
40
40
41#define __RUNETYPE_INTERNAL 1
42
43#include <runetype.h>
44#include <errno.h>
45#include <limits.h>
46#include <string.h>
47#include <stdio.h>
48#include <stdlib.h>
49#include <unistd.h>
50#include <wchar.h>
51#include "ldpart.h"
52#include "mblocal.h"
53#include "setlocale.h"
54
41#include <runetype.h>
42#include <errno.h>
43#include <limits.h>
44#include <string.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <unistd.h>
48#include <wchar.h>
49#include "ldpart.h"
50#include "mblocal.h"
51#include "setlocale.h"
52
55#undef _CurrentRuneLocale
56extern _RuneLocale const *_CurrentRuneLocale;
57#ifndef __NO_TLS
58/*
59 * A cached version of the runes for this thread. Used by ctype.h
60 */
61_Thread_local const _RuneLocale *_ThreadRuneLocale;
62#endif
63
64extern int __mb_sb_limit;
65
66extern _RuneLocale *_Read_RuneMagi(FILE *);
67
68static int __setrunelocale(struct xlocale_ctype *l, const char *);
69
70#define __collate_load_error (table->__collate_load_error)
71#define __collate_substitute_nontrivial (table->__collate_substitute_nontrivial)

--- 6 unchanged lines hidden (view full) ---

78{
79 struct xlocale_ctype *l = v;
80 if (strcmp(l->runes->__encoding, "EUC") == 0)
81 free(l->runes->__variable);
82 if (&_DefaultRuneLocale != l->runes)
83 free(l->runes);
84 free(l);
85}
53extern int __mb_sb_limit;
54
55extern _RuneLocale *_Read_RuneMagi(FILE *);
56
57static int __setrunelocale(struct xlocale_ctype *l, const char *);
58
59#define __collate_load_error (table->__collate_load_error)
60#define __collate_substitute_nontrivial (table->__collate_substitute_nontrivial)

--- 6 unchanged lines hidden (view full) ---

67{
68 struct xlocale_ctype *l = v;
69 if (strcmp(l->runes->__encoding, "EUC") == 0)
70 free(l->runes->__variable);
71 if (&_DefaultRuneLocale != l->runes)
72 free(l->runes);
73 free(l);
74}
86
87const _RuneLocale *__getCurrentRuneLocale(void)
75_RuneLocale *__getCurrentRuneLocale(void)
88{
89 return XLOCALE_CTYPE(__get_locale())->runes;
90}
91
92static int
93__setrunelocale(struct xlocale_ctype *l, const char *encoding)
94{
95 FILE *fp;

--- 79 unchanged lines hidden (view full) ---

175 int ret = __setrunelocale(&__xlocale_global_ctype, locale);
176
177 if (ret != 0) {
178 errno = ret;
179 return (_LDP_ERROR);
180 }
181 __mb_cur_max = __xlocale_global_ctype.__mb_cur_max;
182 __mb_sb_limit = __xlocale_global_ctype.__mb_sb_limit;
76{
77 return XLOCALE_CTYPE(__get_locale())->runes;
78}
79
80static int
81__setrunelocale(struct xlocale_ctype *l, const char *encoding)
82{
83 FILE *fp;

--- 79 unchanged lines hidden (view full) ---

163 int ret = __setrunelocale(&__xlocale_global_ctype, locale);
164
165 if (ret != 0) {
166 errno = ret;
167 return (_LDP_ERROR);
168 }
169 __mb_cur_max = __xlocale_global_ctype.__mb_cur_max;
170 __mb_sb_limit = __xlocale_global_ctype.__mb_sb_limit;
183 _CurrentRuneLocale = __xlocale_global_ctype.runes;
184 return (_LDP_LOADED);
185}
171 return (_LDP_LOADED);
172}
186
187#ifndef __NO_TLS
188void
189__set_thread_rune_locale(locale_t loc) {
190
191 if (loc == NULL) {
192 _ThreadRuneLocale = &_DefaultRuneLocale;
193 } else {
194 _ThreadRuneLocale = XLOCALE_CTYPE(loc)->runes;
195 }
196}
197#endif
198
199void *
200__ctype_load(const char *locale, locale_t unused)
173void *__ctype_load(const char *locale, locale_t unused)
201{
202 struct xlocale_ctype *l = calloc(sizeof(struct xlocale_ctype), 1);
203 l->header.header.destructor = destruct_ctype;
204 if (__setrunelocale(l, locale))
205 {
206 free(l);
207 return NULL;
208 }
209 return l;
210}
174{
175 struct xlocale_ctype *l = calloc(sizeof(struct xlocale_ctype), 1);
176 l->header.header.destructor = destruct_ctype;
177 if (__setrunelocale(l, locale))
178 {
179 free(l);
180 return NULL;
181 }
182 return l;
183}