setrunelocale.c (130961) | setrunelocale.c (132497) |
---|---|
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 130961 2004-06-23 07:01:44Z tjr $"); | 41__FBSDID("$FreeBSD: head/lib/libc/locale/setrunelocale.c 132497 2004-07-21 10:54:57Z 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> --- 45 unchanged lines hidden (view full) --- 95 static char ctype_encoding[ENCODING_LEN + 1]; 96 static _RuneLocale *CachedRuneLocale; 97 static int Cached__mb_cur_max; 98 static size_t (*Cached__mbrtowc)(wchar_t * __restrict, 99 const char * __restrict, size_t, mbstate_t * __restrict); 100 static size_t (*Cached__wcrtomb)(char * __restrict, wchar_t, 101 mbstate_t * __restrict); 102 static int (*Cached__mbsinit)(const mbstate_t *); | 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> --- 45 unchanged lines hidden (view full) --- 95 static char ctype_encoding[ENCODING_LEN + 1]; 96 static _RuneLocale *CachedRuneLocale; 97 static int Cached__mb_cur_max; 98 static size_t (*Cached__mbrtowc)(wchar_t * __restrict, 99 const char * __restrict, size_t, mbstate_t * __restrict); 100 static size_t (*Cached__wcrtomb)(char * __restrict, wchar_t, 101 mbstate_t * __restrict); 102 static int (*Cached__mbsinit)(const mbstate_t *); |
103 static size_t (*Cached__mbsrtowcs)(wchar_t * __restrict, 104 const char ** __restrict, size_t, mbstate_t * __restrict); 105 static size_t (*Cached__wcsrtombs)(char * __restrict, 106 const wchar_t ** __restrict, size_t, mbstate_t * __restrict); | 103 static size_t (*Cached__mbsnrtowcs)(wchar_t * __restrict, 104 const char ** __restrict, size_t, size_t, mbstate_t * __restrict); 105 static size_t (*Cached__wcsnrtombs)(char * __restrict, 106 const wchar_t ** __restrict, size_t, size_t, 107 mbstate_t * __restrict); |
107 108 /* 109 * The "C" and "POSIX" locale are always here. 110 */ 111 if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) { 112 _CurrentRuneLocale = &_DefaultRuneLocale; 113 __mb_cur_max = 1; 114 __mbrtowc = _none_mbrtowc; 115 __mbsinit = _none_mbsinit; | 108 109 /* 110 * The "C" and "POSIX" locale are always here. 111 */ 112 if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0) { 113 _CurrentRuneLocale = &_DefaultRuneLocale; 114 __mb_cur_max = 1; 115 __mbrtowc = _none_mbrtowc; 116 __mbsinit = _none_mbsinit; |
116 __mbsrtowcs = _none_mbsrtowcs; | 117 __mbsnrtowcs = _none_mbsnrtowcs; |
117 __wcrtomb = _none_wcrtomb; | 118 __wcrtomb = _none_wcrtomb; |
118 __wcsrtombs = _none_wcsrtombs; | 119 __wcsnrtombs = _none_wcsnrtombs; |
119 return (0); 120 } 121 122 /* 123 * If the locale name is the same as our cache, use the cache. 124 */ 125 if (CachedRuneLocale != NULL && 126 strcmp(encoding, ctype_encoding) == 0) { 127 _CurrentRuneLocale = CachedRuneLocale; 128 __mb_cur_max = Cached__mb_cur_max; 129 __mbrtowc = Cached__mbrtowc; 130 __mbsinit = Cached__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 __mbsinit = Cached__mbsinit; |
131 __mbsrtowcs = Cached__mbsrtowcs; | 132 __mbsnrtowcs = Cached__mbsnrtowcs; |
132 __wcrtomb = Cached__wcrtomb; | 133 __wcrtomb = Cached__wcrtomb; |
133 __wcsrtombs = Cached__wcsrtombs; | 134 __wcsnrtombs = Cached__wcsnrtombs; |
134 return (0); 135 } 136 137 /* 138 * Slurp the locale file into the cache. 139 */ 140 141 /* Range checking not needed, encoding length already checked before */ --- 9 unchanged lines hidden (view full) --- 151 saverr = (errno == 0 ? EFTYPE : errno); 152 (void)fclose(fp); 153 return (saverr); 154 } 155 (void)fclose(fp); 156 157 __mbrtowc = NULL; 158 __mbsinit = NULL; | 135 return (0); 136 } 137 138 /* 139 * Slurp the locale file into the cache. 140 */ 141 142 /* Range checking not needed, encoding length already checked before */ --- 9 unchanged lines hidden (view full) --- 152 saverr = (errno == 0 ? EFTYPE : errno); 153 (void)fclose(fp); 154 return (saverr); 155 } 156 (void)fclose(fp); 157 158 __mbrtowc = NULL; 159 __mbsinit = NULL; |
159 __mbsrtowcs = __mbsrtowcs_std; | 160 __mbsnrtowcs = __mbsnrtowcs_std; |
160 __wcrtomb = NULL; | 161 __wcrtomb = NULL; |
161 __wcsrtombs = __wcsrtombs_std; | 162 __wcsnrtombs = __wcsnrtombs_std; |
162 rl->__sputrune = __emulated_sputrune; 163 rl->__sgetrune = __emulated_sgetrune; 164 if (strcmp(rl->__encoding, "NONE") == 0) 165 ret = _none_init(rl); 166 else if (strcmp(rl->__encoding, "UTF2") == 0) 167 ret = _UTF2_init(rl); 168 else if (strcmp(rl->__encoding, "UTF-8") == 0) 169 ret = _UTF8_init(rl); --- 17 unchanged lines hidden (view full) --- 187 if (strcmp(CachedRuneLocale->__encoding, "EUC") == 0) 188 free(CachedRuneLocale->__variable); 189 free(CachedRuneLocale); 190 } 191 CachedRuneLocale = _CurrentRuneLocale; 192 Cached__mb_cur_max = __mb_cur_max; 193 Cached__mbrtowc = __mbrtowc; 194 Cached__mbsinit = __mbsinit; | 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); --- 17 unchanged lines hidden (view full) --- 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; |
195 Cached__mbsrtowcs = __mbsrtowcs; | 196 Cached__mbsnrtowcs = __mbsnrtowcs; |
196 Cached__wcrtomb = __wcrtomb; | 197 Cached__wcrtomb = __wcrtomb; |
197 Cached__wcsrtombs = __wcsrtombs; | 198 Cached__wcsnrtombs = __wcsnrtombs; |
198 (void)strcpy(ctype_encoding, encoding); 199 } else 200 free(rl); 201 202 return (ret); 203} 204 205int 206__wrap_setrunelocale(const char *locale) 207{ 208 int ret = __setrunelocale(locale); 209 210 if (ret != 0) { 211 errno = ret; 212 return (_LDP_ERROR); 213 } 214 return (_LDP_LOADED); 215} 216 | 199 (void)strcpy(ctype_encoding, encoding); 200 } else 201 free(rl); 202 203 return (ret); 204} 205 206int 207__wrap_setrunelocale(const char *locale) 208{ 209 int ret = __setrunelocale(locale); 210 211 if (ret != 0) { 212 errno = ret; 213 return (_LDP_ERROR); 214 } 215 return (_LDP_LOADED); 216} 217 |