1027
gl_rwlock_unlock (domain->conversions_lock);
1025
1029
if (convd == NULL)
1027
/* Allocate a table for the converted translations for this
1029
struct converted_domain *new_conversions =
1030
(struct converted_domain *)
1031
(domain->conversions != NULL
1032
? realloc (domain->conversions,
1033
(nconversions + 1) * sizeof (struct converted_domain))
1034
: malloc ((nconversions + 1) * sizeof (struct converted_domain)));
1036
if (__builtin_expect (new_conversions == NULL, 0))
1037
/* Nothing we can do, no more memory. We cannot use the
1038
translation because it might be encoded incorrectly. */
1041
domain->conversions = new_conversions;
1043
/* Copy the 'encoding' string to permanent storage. */
1044
encoding = strdup (encoding);
1045
if (__builtin_expect (encoding == NULL, 0))
1046
/* Nothing we can do, no more memory. We cannot use the
1047
translation because it might be encoded incorrectly. */
1050
convd = &new_conversions[nconversions];
1051
convd->encoding = encoding;
1053
/* Find out about the character set the file is encoded with.
1054
This can be found (in textual form) in the entry "". If this
1055
entry does not exist or if this does not contain the 'charset='
1056
information, we will assume the charset matches the one the
1057
current locale and we don't have to perform any conversion. */
1059
convd->conv = (__gconv_t) -1;
1062
convd->conv = (iconv_t) -1;
1031
/* We have to allocate a new conversions table. */
1032
gl_rwlock_wrlock (domain->conversions_lock);
1034
/* Maybe in the meantime somebody added the translation.
1036
for (i = nconversions; i > 0; )
1039
if (strcmp (domain->conversions[i].encoding, encoding) == 0)
1041
convd = &domain->conversions[i];
1067
size_t nullentrylen;
1069
/* Get the header entry. This is a recursion, but it doesn't
1070
reallocate domain->conversions because we pass
1071
encoding = NULL or convert = 0, respectively. */
1073
# ifdef IN_LIBGLOCALE
1074
_nl_find_msg (domain_file, domainbinding, NULL, "",
1077
_nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen);
1080
if (nullentry != NULL)
1047
/* Allocate a table for the converted translations for this
1049
struct converted_domain *new_conversions =
1050
(struct converted_domain *)
1051
(domain->conversions != NULL
1052
? realloc (domain->conversions,
1053
(nconversions + 1) * sizeof (struct converted_domain))
1054
: malloc ((nconversions + 1) * sizeof (struct converted_domain)));
1056
if (__builtin_expect (new_conversions == NULL, 0))
1082
const char *charsetstr;
1084
charsetstr = strstr (nullentry, "charset=");
1085
if (charsetstr != NULL)
1089
const char *outcharset;
1091
charsetstr += strlen ("charset=");
1092
len = strcspn (charsetstr, " \t\n");
1094
charset = (char *) alloca (len + 1);
1058
/* Nothing we can do, no more memory. We cannot use the
1059
translation because it might be encoded incorrectly. */
1061
gl_rwlock_unlock (domain->conversions_lock);
1065
domain->conversions = new_conversions;
1067
/* Copy the 'encoding' string to permanent storage. */
1068
encoding = strdup (encoding);
1069
if (__builtin_expect (encoding == NULL, 0))
1070
/* Nothing we can do, no more memory. We cannot use the
1071
translation because it might be encoded incorrectly. */
1074
convd = &new_conversions[nconversions];
1075
convd->encoding = encoding;
1077
/* Find out about the character set the file is encoded with.
1078
This can be found (in textual form) in the entry "". If this
1079
entry does not exist or if this does not contain the 'charset='
1080
information, we will assume the charset matches the one the
1081
current locale and we don't have to perform any conversion. */
1083
convd->conv = (__gconv_t) -1;
1086
convd->conv = (iconv_t) -1;
1091
size_t nullentrylen;
1093
/* Get the header entry. This is a recursion, but it doesn't
1094
reallocate domain->conversions because we pass
1095
encoding = NULL or convert = 0, respectively. */
1097
# ifdef IN_LIBGLOCALE
1098
_nl_find_msg (domain_file, domainbinding, NULL, "",
1101
_nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen);
1104
if (nullentry != NULL)
1106
const char *charsetstr;
1108
charsetstr = strstr (nullentry, "charset=");
1109
if (charsetstr != NULL)
1113
const char *outcharset;
1115
charsetstr += strlen ("charset=");
1116
len = strcspn (charsetstr, " \t\n");
1118
charset = (char *) alloca (len + 1);
1095
1119
# if defined _LIBC || HAVE_MEMPCPY
1096
*((char *) mempcpy (charset, charsetstr, len)) = '\0';
1120
*((char *) mempcpy (charset, charsetstr, len)) = '\0';
1098
memcpy (charset, charsetstr, len);
1099
charset[len] = '\0';
1122
memcpy (charset, charsetstr, len);
1123
charset[len] = '\0';
1102
outcharset = encoding;
1126
outcharset = encoding;
1105
/* We always want to use transliteration. */
1106
outcharset = norm_add_slashes (outcharset, "TRANSLIT");
1107
charset = norm_add_slashes (charset, "");
1108
int r = __gconv_open (outcharset, charset, &convd->conv,
1109
GCONV_AVOID_NOCONV);
1110
if (__builtin_expect (r != __GCONV_OK, 0))
1112
/* If the output encoding is the same there is
1113
nothing to do. Otherwise do not use the
1114
translation at all. */
1115
if (__builtin_expect (r != __GCONV_NOCONV, 1))
1129
/* We always want to use transliteration. */
1130
outcharset = norm_add_slashes (outcharset, "TRANSLIT");
1131
charset = norm_add_slashes (charset, "");
1132
int r = __gconv_open (outcharset, charset, &convd->conv,
1133
GCONV_AVOID_NOCONV);
1134
if (__builtin_expect (r != __GCONV_OK, 0))
1136
/* If the output encoding is the same there is
1137
nothing to do. Otherwise do not use the
1138
translation at all. */
1139
if (__builtin_expect (r != __GCONV_NULCONV, 1))
1141
gl_rwlock_unlock (domain->conversions_lock);
1142
free ((char *) encoding);
1118
convd->conv = (__gconv_t) -1;
1146
convd->conv = (__gconv_t) -1;
1121
1149
# if HAVE_ICONV
1122
/* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
1123
we want to use transliteration. */
1150
/* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
1151
we want to use transliteration. */
1124
1152
# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
1125
1153
|| _LIBICONV_VERSION >= 0x0105
1126
if (strchr (outcharset, '/') == NULL)
1130
len = strlen (outcharset);
1131
tmp = (char *) alloca (len + 10 + 1);
1132
memcpy (tmp, outcharset, len);
1133
memcpy (tmp + len, "//TRANSLIT", 10 + 1);
1154
if (strchr (outcharset, '/') == NULL)
1158
len = strlen (outcharset);
1159
tmp = (char *) alloca (len + 10 + 1);
1160
memcpy (tmp, outcharset, len);
1161
memcpy (tmp + len, "//TRANSLIT", 10 + 1);
1164
convd->conv = iconv_open (outcharset, charset);
1136
1170
convd->conv = iconv_open (outcharset, charset);
1142
convd->conv = iconv_open (outcharset, charset);
1178
convd->conv_tab = NULL;
1179
/* Here domain->conversions is still == new_conversions. */
1180
domain->nconversions++;
1150
convd->conv_tab = NULL;
1151
/* Here domain->conversions is still == new_conversions. */
1152
domain->nconversions++;
1184
gl_rwlock_unlock (domain->conversions_lock);