Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/locale/collate.c
Show First 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
int | int | ||||
__collate_load_tables(const char *encoding) | __collate_load_tables(const char *encoding) | ||||
{ | { | ||||
return (__collate_load_tables_l(encoding, &__xlocale_global_collate)); | return (__collate_load_tables_l(encoding, &__xlocale_global_collate)); | ||||
} | } | ||||
int | static int | ||||
__collate_load_tables_l(const char *encoding, struct xlocale_collate *table) | __collate_load_tables_l(const char *encoding, struct xlocale_collate *table) | ||||
{ | { | ||||
int i, chains, z; | int i, chains, z; | ||||
char *buf; | char *buf; | ||||
char *TMP; | char *TMP; | ||||
char *map; | char *map; | ||||
collate_info_t *info; | collate_info_t *info; | ||||
struct stat sbuf; | struct stat sbuf; | ||||
Show All 21 Lines | __collate_load_tables_l(const char *encoding, struct xlocale_collate *table) | ||||
} | } | ||||
if (sbuf.st_size < (COLLATE_STR_LEN + sizeof (info))) { | if (sbuf.st_size < (COLLATE_STR_LEN + sizeof (info))) { | ||||
(void) _close(fd); | (void) _close(fd); | ||||
errno = EINVAL; | errno = EINVAL; | ||||
return (_LDP_ERROR); | return (_LDP_ERROR); | ||||
} | } | ||||
map = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | map = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | ||||
(void) _close(fd); | (void) _close(fd); | ||||
if ((TMP = map) == NULL) { | if ((TMP = map) == MAP_FAILED) { | ||||
return (_LDP_ERROR); | return (_LDP_ERROR); | ||||
} | } | ||||
if (strncmp(TMP, COLLATE_VERSION, COLLATE_STR_LEN) != 0) { | if (strncmp(TMP, COLLATE_VERSION, COLLATE_STR_LEN) != 0) { | ||||
(void) munmap(map, sbuf.st_size); | (void) munmap(map, sbuf.st_size); | ||||
errno = EINVAL; | errno = EINVAL; | ||||
return (_LDP_ERROR); | return (_LDP_ERROR); | ||||
} | } | ||||
Show All 17 Lines | for (z = 0; z < info->directive_count; z++) { | ||||
i += sizeof (collate_subst_t) * info->subst_count[z]; | i += sizeof (collate_subst_t) * info->subst_count[z]; | ||||
} | } | ||||
if (i != (sbuf.st_size - (TMP - map))) { | if (i != (sbuf.st_size - (TMP - map))) { | ||||
(void) munmap(map, sbuf.st_size); | (void) munmap(map, sbuf.st_size); | ||||
errno = EINVAL; | errno = EINVAL; | ||||
return (_LDP_ERROR); | return (_LDP_ERROR); | ||||
} | } | ||||
if (table->map && (table->maplen > 0)) { | |||||
(void) munmap(table->map, table->maplen); | |||||
} | |||||
table->map = map; | |||||
table->maplen = sbuf.st_size; | |||||
table->info = info; | table->info = info; | ||||
table->char_pri_table = (void *)TMP; | table->char_pri_table = (void *)TMP; | ||||
TMP += sizeof (collate_char_t) * (UCHAR_MAX + 1); | TMP += sizeof (collate_char_t) * (UCHAR_MAX + 1); | ||||
for (z = 0; z < info->directive_count; z++) { | for (z = 0; z < info->directive_count; z++) { | ||||
if (info->subst_count[z] > 0) { | if (info->subst_count[z] > 0) { | ||||
table->subst_table[z] = (void *)TMP; | table->subst_table[z] = (void *)TMP; | ||||
TMP += info->subst_count[z] * sizeof (collate_subst_t); | TMP += info->subst_count[z] * sizeof (collate_subst_t); | ||||
▲ Show 20 Lines • Show All 520 Lines • Show Last 20 Lines |