Deleted Added
full compact
setrunelocale.c (127835) setrunelocale.c (128004)
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 * Redistribution and use in source and binary forms, with or without

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

33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37/* setrunelocale() is obsolete in FreeBSD 6 -- use ANSI functions instead. */
38#define OBSOLETE_IN_6
39
40#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 * Redistribution and use in source and binary forms, with or without

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

33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37/* setrunelocale() is obsolete in FreeBSD 6 -- use ANSI functions instead. */
38#define OBSOLETE_IN_6
39
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 127835 2004-04-04 11:31:29Z tjr $");
41__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 128004 2004-04-07 10:48:19Z tjr $");
42
43#include <rune.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>

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

59extern int _GB2312_init(_RuneLocale *);
60extern int _GBK_init(_RuneLocale *);
61extern int _BIG5_init(_RuneLocale *);
62extern int _MSKanji_init(_RuneLocale *);
63extern _RuneLocale *_Read_RuneMagi(FILE *);
64
65extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
66 size_t, mbstate_t * __restrict);
42
43#include <rune.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>

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

59extern int _GB2312_init(_RuneLocale *);
60extern int _GBK_init(_RuneLocale *);
61extern int _BIG5_init(_RuneLocale *);
62extern int _MSKanji_init(_RuneLocale *);
63extern _RuneLocale *_Read_RuneMagi(FILE *);
64
65extern size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
66 size_t, mbstate_t * __restrict);
67extern int (*__mbsinit)(const mbstate_t *);
67extern size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict);
68extern rune_t __emulated_sgetrune(const char *, size_t, const char **);
69extern int __emulated_sputrune(rune_t, char *, size_t, char **);
70extern size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict,
71 size_t, mbstate_t * __restrict);
68extern size_t (*__wcrtomb)(char * __restrict, wchar_t, mbstate_t * __restrict);
69extern rune_t __emulated_sgetrune(const char *, size_t, const char **);
70extern int __emulated_sputrune(rune_t, char *, size_t, char **);
71extern size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict,
72 size_t, mbstate_t * __restrict);
73extern int _none_mbsinit(const mbstate_t *);
72extern size_t _none_wcrtomb(char * __restrict, wchar_t,
73 mbstate_t * __restrict);
74
75static int __setrunelocale(const char *);
76
77__warn_references(setrunelocale, "warning: setrunelocale() is deprecated. See setrunelocale(3).");
78int
79setrunelocale(char *encoding)

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

103 int saverr, ret;
104 static char ctype_encoding[ENCODING_LEN + 1];
105 static _RuneLocale *CachedRuneLocale;
106 static int Cached__mb_cur_max;
107 static size_t (*Cached__mbrtowc)(wchar_t * __restrict,
108 const char * __restrict, size_t, mbstate_t * __restrict);
109 static size_t (*Cached__wcrtomb)(char * __restrict, wchar_t,
110 mbstate_t * __restrict);
74extern size_t _none_wcrtomb(char * __restrict, wchar_t,
75 mbstate_t * __restrict);
76
77static int __setrunelocale(const char *);
78
79__warn_references(setrunelocale, "warning: setrunelocale() is deprecated. See setrunelocale(3).");
80int
81setrunelocale(char *encoding)

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

105 int saverr, ret;
106 static char ctype_encoding[ENCODING_LEN + 1];
107 static _RuneLocale *CachedRuneLocale;
108 static int Cached__mb_cur_max;
109 static size_t (*Cached__mbrtowc)(wchar_t * __restrict,
110 const char * __restrict, size_t, mbstate_t * __restrict);
111 static size_t (*Cached__wcrtomb)(char * __restrict, wchar_t,
112 mbstate_t * __restrict);
113 static int (*Cached__mbsinit)(const mbstate_t *);
111
112 /*
113 * The "C" and "POSIX" locale are always here.
114 */
115 if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
116 _CurrentRuneLocale = &_DefaultRuneLocale;
117 __mb_cur_max = 1;
118 __mbrtowc = _none_mbrtowc;
119 __wcrtomb = _none_wcrtomb;
114
115 /*
116 * The "C" and "POSIX" locale are always here.
117 */
118 if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
119 _CurrentRuneLocale = &_DefaultRuneLocale;
120 __mb_cur_max = 1;
121 __mbrtowc = _none_mbrtowc;
122 __wcrtomb = _none_wcrtomb;
123 __mbsinit = _none_mbsinit;
120 return (0);
121 }
122
123 /*
124 * If the locale name is the same as our cache, use the cache.
125 */
126 if (CachedRuneLocale != NULL &&
127 strcmp(encoding, ctype_encoding) == 0) {
128 _CurrentRuneLocale = CachedRuneLocale;
129 __mb_cur_max = Cached__mb_cur_max;
130 __mbrtowc = Cached__mbrtowc;
131 __wcrtomb = Cached__wcrtomb;
124 return (0);
125 }
126
127 /*
128 * If the locale name is the same as our cache, use the cache.
129 */
130 if (CachedRuneLocale != NULL &&
131 strcmp(encoding, ctype_encoding) == 0) {
132 _CurrentRuneLocale = CachedRuneLocale;
133 __mb_cur_max = Cached__mb_cur_max;
134 __mbrtowc = Cached__mbrtowc;
135 __wcrtomb = Cached__wcrtomb;
136 __mbsinit = Cached__mbsinit;
132 return (0);
133 }
134
135 /*
136 * Slurp the locale file into the cache.
137 */
138
139 /* Range checking not needed, encoding length already checked before */

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

149 saverr = (errno == 0 ? EFTYPE : errno);
150 (void)fclose(fp);
151 return (saverr);
152 }
153 (void)fclose(fp);
154
155 __mbrtowc = NULL;
156 __wcrtomb = NULL;
137 return (0);
138 }
139
140 /*
141 * Slurp the locale file into the cache.
142 */
143
144 /* Range checking not needed, encoding length already checked before */

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

154 saverr = (errno == 0 ? EFTYPE : errno);
155 (void)fclose(fp);
156 return (saverr);
157 }
158 (void)fclose(fp);
159
160 __mbrtowc = NULL;
161 __wcrtomb = NULL;
162 __mbsinit = NULL;
157 rl->sputrune = __emulated_sputrune;
158 rl->sgetrune = __emulated_sgetrune;
159 if (strcmp(rl->encoding, "NONE") == 0)
160 ret = _none_init(rl);
161 else if (strcmp(rl->encoding, "UTF2") == 0)
162 ret = _UTF2_init(rl);
163 else if (strcmp(rl->encoding, "UTF-8") == 0)
164 ret = _UTF8_init(rl);

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

181 /* See euc.c */
182 if (strcmp(CachedRuneLocale->encoding, "EUC") == 0)
183 free(CachedRuneLocale->variable);
184 free(CachedRuneLocale);
185 }
186 CachedRuneLocale = _CurrentRuneLocale;
187 Cached__mb_cur_max = __mb_cur_max;
188 Cached__mbrtowc = __mbrtowc;
163 rl->sputrune = __emulated_sputrune;
164 rl->sgetrune = __emulated_sgetrune;
165 if (strcmp(rl->encoding, "NONE") == 0)
166 ret = _none_init(rl);
167 else if (strcmp(rl->encoding, "UTF2") == 0)
168 ret = _UTF2_init(rl);
169 else if (strcmp(rl->encoding, "UTF-8") == 0)
170 ret = _UTF8_init(rl);

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

187 /* See euc.c */
188 if (strcmp(CachedRuneLocale->encoding, "EUC") == 0)
189 free(CachedRuneLocale->variable);
190 free(CachedRuneLocale);
191 }
192 CachedRuneLocale = _CurrentRuneLocale;
193 Cached__mb_cur_max = __mb_cur_max;
194 Cached__mbrtowc = __mbrtowc;
195 Cached__mbsinit = __mbsinit;
189 Cached__wcrtomb = __wcrtomb;
190 (void)strcpy(ctype_encoding, encoding);
191 } else
192 free(rl);
193
194 return (ret);
195}
196

--- 12 unchanged lines hidden ---
196 Cached__wcrtomb = __wcrtomb;
197 (void)strcpy(ctype_encoding, encoding);
198 } else
199 free(rl);
200
201 return (ret);
202}
203

--- 12 unchanged lines hidden ---