119
#define MY_CHARSET_INDEX "Index.xml"
121
const char *charsets_dir= NULL;
122
static int charset_initialized=0;
125
char *get_charsets_dir(char *buf)
129
if (charsets_dir != NULL)
130
strncpy(buf, charsets_dir, FN_REFLEN-1);
133
if (test_if_hard_path(PKGDATADIR) ||
134
is_prefix(PKGDATADIR, PREFIX))
135
sprintf(buf,"%s/%s",PKGDATADIR,CHARSET_DIR);
137
sprintf(buf,"%s/%s/%s",PREFIX,PKGDATADIR,CHARSET_DIR);
139
res= convert_dirname(buf,buf,NULL);
119
static bool charset_initialized= false;
143
121
CHARSET_INFO *all_charsets[256];
144
122
const CHARSET_INFO *default_charset_info = &my_charset_utf8_general_ci;
158
136
static bool init_available_charsets(myf myflags)
160
char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
163
140
We have to use charset_initialized to not lock on THR_LOCK_charset
164
141
inside get_internal_charset...
166
if (!charset_initialized)
143
if (charset_initialized == false)
168
145
CHARSET_INFO **cs;
170
To make things thread safe we are not allowing other threads to interfere
171
while we may changing the cs_info_table
173
pthread_mutex_lock(&THR_LOCK_charset);
174
if (!charset_initialized)
146
memset(&all_charsets, 0, sizeof(all_charsets));
147
init_compiled_charsets(myflags);
149
/* Copy compiled charsets */
150
for (cs=all_charsets;
151
cs < all_charsets+array_elements(all_charsets)-1 ;
176
memset(&all_charsets, 0, sizeof(all_charsets));
177
init_compiled_charsets(myflags);
179
/* Copy compiled charsets */
180
for (cs=all_charsets;
181
cs < all_charsets+array_elements(all_charsets)-1 ;
187
if (init_state_maps(*cs))
157
if (init_state_maps(*cs))
192
strcpy(get_charsets_dir(fname), MY_CHARSET_INDEX);
193
charset_initialized=1;
195
pthread_mutex_unlock(&THR_LOCK_charset);
162
charset_initialized= true;
164
assert(charset_initialized);
201
170
void free_charsets(void)
203
charset_initialized=0;
172
charset_initialized= true;
248
217
To make things thread safe we are not allowing other threads to interfere
249
218
while we may changing the cs_info_table
251
pthread_mutex_lock(&THR_LOCK_charset);
252
220
if ((cs= all_charsets[cs_number]))
254
222
if (!(cs->state & MY_CS_COMPILED) && !(cs->state & MY_CS_LOADED))
266
234
cs->state|= MY_CS_READY;
268
pthread_mutex_unlock(&THR_LOCK_charset);
273
const CHARSET_INFO *get_charset(uint32_t cs_number, myf flags)
241
const CHARSET_INFO *get_charset(uint32_t cs_number)
275
243
const CHARSET_INFO *cs;
276
244
if (cs_number == default_charset_info->number)
284
252
cs= get_internal_charset(cs_number);
286
if (!cs && (flags & MY_WME))
288
char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)], cs_string[23];
289
strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
291
int10_to_str(cs_number, cs_string+1, 10);
292
my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file);
297
const CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags)
257
const CHARSET_INFO *get_charset_by_name(const char *cs_name)
299
259
uint32_t cs_number;
300
260
const CHARSET_INFO *cs;
303
263
cs_number=get_collation_number(cs_name);
304
264
cs= cs_number ? get_internal_charset(cs_number) : NULL;
306
if (!cs && (flags & MY_WME))
308
char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
309
strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
310
my_error(EE_UNKNOWN_COLLATION, MYF(ME_BELL), cs_name, index_file);
317
const CHARSET_INFO *get_charset_by_csname(const char *cs_name,
270
const CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint32_t cs_flags)
321
272
uint32_t cs_number;
322
273
const CHARSET_INFO *cs;
326
277
cs_number= get_charset_number(cs_name, cs_flags);
327
278
cs= cs_number ? get_internal_charset(cs_number) : NULL;
329
if (!cs && (flags & MY_WME))
331
char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
332
strcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX);
333
my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file);
357
301
const CHARSET_INFO *default_cs,
358
302
const CHARSET_INFO **cs)
360
*cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY, MYF(0));
304
*cs= get_charset_by_csname(cs_name, MY_CS_PRIMARY);