Deleted Added
full compact
setrunelocale.c (232498) setrunelocale.c (236889)
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 232498 2012-03-04 15:31:13Z theraven $");
39__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 236889 2012-06-11 14:02:02Z theraven $");
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>

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

84 free(l);
85}
86
87const _RuneLocale *__getCurrentRuneLocale(void)
88{
89 return XLOCALE_CTYPE(__get_locale())->runes;
90}
91
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>

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

84 free(l);
85}
86
87const _RuneLocale *__getCurrentRuneLocale(void)
88{
89 return XLOCALE_CTYPE(__get_locale())->runes;
90}
91
92static void free_runes(_RuneLocale *rl)
93{
94 /* FIXME: The "EUC" check here is a hideous abstraction violation. */
95 if ((rl != &_DefaultRuneLocale) && (rl)) {
96 if (strcmp(rl->__encoding, "EUC") == 0) {
97 free(rl->__variable);
98 }
99 free(rl);
100 }
101}
102
92static int
93__setrunelocale(struct xlocale_ctype *l, const char *encoding)
94{
95 FILE *fp;
96 char name[PATH_MAX];
97 _RuneLocale *rl;
98 int saverr, ret;
99 struct xlocale_ctype saved = *l;
100
101 /*
102 * The "C" and "POSIX" locale are always here.
103 */
104 if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
103static int
104__setrunelocale(struct xlocale_ctype *l, const char *encoding)
105{
106 FILE *fp;
107 char name[PATH_MAX];
108 _RuneLocale *rl;
109 int saverr, ret;
110 struct xlocale_ctype saved = *l;
111
112 /*
113 * The "C" and "POSIX" locale are always here.
114 */
115 if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) {
116 free_runes(saved.runes);
105 (void) _none_init(l, (_RuneLocale*)&_DefaultRuneLocale);
106 return (0);
107 }
108
109 /* Range checking not needed, encoding length already checked before */
110 (void) strcpy(name, _PathLocale);
111 (void) strcat(name, "/");
112 (void) strcat(name, encoding);

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

148 ret = _BIG5_init(l, rl);
149 else if (strcmp(rl->__encoding, "MSKanji") == 0)
150 ret = _MSKanji_init(l, rl);
151 else
152 ret = EFTYPE;
153
154 if (ret == 0) {
155 /* Free the old runes if it exists. */
117 (void) _none_init(l, (_RuneLocale*)&_DefaultRuneLocale);
118 return (0);
119 }
120
121 /* Range checking not needed, encoding length already checked before */
122 (void) strcpy(name, _PathLocale);
123 (void) strcat(name, "/");
124 (void) strcat(name, encoding);

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

160 ret = _BIG5_init(l, rl);
161 else if (strcmp(rl->__encoding, "MSKanji") == 0)
162 ret = _MSKanji_init(l, rl);
163 else
164 ret = EFTYPE;
165
166 if (ret == 0) {
167 /* Free the old runes if it exists. */
156 /* FIXME: The "EUC" check here is a hideous abstraction violation. */
157 if ((saved.runes != &_DefaultRuneLocale) && (saved.runes)) {
158 if (strcmp(saved.runes->__encoding, "EUC") == 0) {
159 free(saved.runes->__variable);
160 }
161 free(saved.runes);
162 }
168 free_runes(saved.runes);
163 } else {
164 /* Restore the saved version if this failed. */
165 memcpy(l, &saved, sizeof(struct xlocale_ctype));
166 free(rl);
167 }
168
169 return (ret);
170}

--- 40 unchanged lines hidden ---
169 } else {
170 /* Restore the saved version if this failed. */
171 memcpy(l, &saved, sizeof(struct xlocale_ctype));
172 free(rl);
173 }
174
175 return (ret);
176}

--- 40 unchanged lines hidden ---