105 char *temp = malloc(strlen(envstring) + strlen(current) + 2); 106 strcpy(temp, name); 107 strcat(temp, "="); 108 strcat(temp, current); 109 strcat(temp, ":"); 110 strcat(temp, value); 111 putenv(temp); 112 } 113 /* else the value has already been set, do nothing */ 114 } 115 else { 116 /* environment variable is not found */ 117 putenv(envstring); 118 } 119 } 120 121 #ifndef P_tmpdir 122 #define P_tmpdir "/var/tmp" 123 #endif 124 125 static int ParseLocale(int cat, char ** std_language, char ** std_script, 126 char ** std_country, char ** std_variant, char ** std_encoding) { 127 char temp[64]; 128 char *language = NULL, *country = NULL, *variant = NULL, 129 *encoding = NULL; 130 char *p, encoding_variant[64]; 131 char *lc; 132 133 /* Query the locale set for the category */ 134 lc = setlocale(cat, NULL); 135 136 #ifndef __linux__ 137 if (lc == NULL) { 138 return 0; 139 } 140 141 if (cat == LC_CTYPE) { 142 /* 143 * Workaround for Solaris bug 4201684: Xlib doesn't like @euro 144 * locales. Since we don't depend on the libc @euro behavior, 145 * we just remove the qualifier. 146 * On Linux, the bug doesn't occur; on the other hand, @euro 147 * is needed there because it's a shortcut that also determines 148 * the encoding - without it, we wouldn't get ISO-8859-15. 149 * Therefore, this code section is Solaris-specific. 150 */ 151 lc = strdup(lc); /* keep a copy, setlocale trashes original. */ 152 strcpy(temp, lc); 153 p = strstr(temp, "@euro"); 154 if (p != NULL) { 155 *p = '\0'; 156 setlocale(LC_ALL, temp); 157 } 158 } 159 #else 160 if (lc == NULL || !strcmp(lc, "C") || !strcmp(lc, "POSIX")) { 161 lc = "en_US"; 162 } 163 #endif 164 165 /* 166 * locale string format in Solaris is 167 * <language name>_<country name>.<encoding name>@<variant name> 168 * <country name>, <encoding name>, and <variant name> are optional. 169 */ 170 171 strcpy(temp, lc); 172 173 /* Parse the language, country, encoding, and variant from the 174 * locale. Any of the elements may be missing, but they must occur 175 * in the order language_country.encoding@variant, and must be 176 * preceded by their delimiter (except for language). 177 * 178 * If the locale name (without .encoding@variant, if any) matches 179 * any of the names in the locale_aliases list, map it to the 180 * corresponding full locale name. Most of the entries in the 181 * locale_aliases list are locales that include a language name but 182 * no country name, and this facility is used to map each language 183 * to a default country if that's possible. It's also used to map 184 * the Solaris locale aliases to their proper Java locale IDs. 185 */ 186 if ((p = strchr(temp, '.')) != NULL) { 187 strcpy(encoding_variant, p); /* Copy the leading '.' */ 188 *p = '\0'; 189 } else if ((p = strchr(temp, '@')) != NULL) { 190 strcpy(encoding_variant, p); /* Copy the leading '@' */ 191 *p = '\0'; 192 } else { 193 *encoding_variant = '\0'; 194 } 195 196 if (mapLookup(locale_aliases, temp, &p)) { 197 strcpy(temp, p); 198 // check the "encoding_variant" again, if any. 199 if ((p = strchr(temp, '.')) != NULL) { 200 strcpy(encoding_variant, p); /* Copy the leading '.' */ 201 *p = '\0'; 202 } else if ((p = strchr(temp, '@')) != NULL) { 203 strcpy(encoding_variant, p); /* Copy the leading '@' */ 204 *p = '\0'; 205 } 206 } 207 208 language = temp; 209 if ((country = strchr(temp, '_')) != NULL) { 210 *country++ = '\0'; 211 } 212 213 p = encoding_variant; 214 if ((encoding = strchr(p, '.')) != NULL) { 215 p[encoding++ - p] = '\0'; 216 p = encoding; 217 } 289 * customized EUC-JP converter 290 */ 291 *std_encoding = "eucJP-open"; 292 } else if (strcmp(p, "Big5") == 0 || strcmp(p, "BIG5") == 0) { 293 /* 294 * Remap the encoding string to Big5_Solaris which augments 295 * the default converter for Solaris Big5 locales to include 296 * seven additional ideographic characters beyond those included 297 * in the Java "Big5" converter. 298 */ 299 *std_encoding = "Big5_Solaris"; 300 } else if (strcmp(p, "Big5-HKSCS") == 0) { 301 /* 302 * Solaris uses HKSCS2001 303 */ 304 *std_encoding = "Big5-HKSCS-2001"; 305 } 306 #endif 307 } 308 309 return 1; 310 } 311 312 #ifdef JAVASE_EMBEDDED 313 /* Determine the default embedded toolkit based on whether lib/xawt/ 314 * exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX 315 */ 316 static char* getEmbeddedToolkit() { 317 Dl_info dlinfo; 318 char buf[MAXPATHLEN]; 319 int32_t len; 320 char *p; 321 struct stat statbuf; 322 323 /* Get address of this library and the directory containing it. */ 324 dladdr((void *)getEmbeddedToolkit, &dlinfo); 325 realpath((char *)dlinfo.dli_fname, buf); 326 len = strlen(buf); 327 p = strrchr(buf, '/'); 328 /* Default AWT Toolkit on Linux and Solaris is XAWT. */ 398 { 399 struct utsname name; 400 uname(&name); 401 sprops.os_name = strdup(name.sysname); 402 sprops.os_version = strdup(name.release); 403 404 sprops.os_arch = ARCHPROPNAME; 405 406 if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) { 407 sprops.desktop = "gnome"; 408 } 409 else { 410 sprops.desktop = NULL; 411 } 412 } 413 414 /* Determine the language, country, variant, and encoding from the host, 415 * and store these in the user.language, user.country, user.variant and 416 * file.encoding system properties. */ 417 setlocale(LC_ALL, ""); 418 if (ParseLocale(LC_CTYPE, 419 &(sprops.format_language), 420 &(sprops.format_script), 421 &(sprops.format_country), 422 &(sprops.format_variant), 423 &(sprops.encoding))) { 424 ParseLocale(LC_MESSAGES, 425 &(sprops.language), 426 &(sprops.script), 427 &(sprops.country), 428 &(sprops.variant), 429 NULL); 430 } else { 431 sprops.language = "en"; 432 sprops.encoding = "ISO8859-1"; 433 } 434 sprops.display_language = sprops.language; 435 sprops.display_script = sprops.script; 436 sprops.display_country = sprops.country; 437 sprops.display_variant = sprops.variant; 438 sprops.sun_jnu_encoding = sprops.encoding; 439 440 #ifdef __linux__ 441 #if __BYTE_ORDER == __LITTLE_ENDIAN 442 sprops.unicode_encoding = "UnicodeLittle"; 443 #else 444 sprops.unicode_encoding = "UnicodeBig"; | 105 char *temp = malloc(strlen(envstring) + strlen(current) + 2); 106 strcpy(temp, name); 107 strcat(temp, "="); 108 strcat(temp, current); 109 strcat(temp, ":"); 110 strcat(temp, value); 111 putenv(temp); 112 } 113 /* else the value has already been set, do nothing */ 114 } 115 else { 116 /* environment variable is not found */ 117 putenv(envstring); 118 } 119 } 120 121 #ifndef P_tmpdir 122 #define P_tmpdir "/var/tmp" 123 #endif 124 125 static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_script, 126 char ** std_country, char ** std_variant, char ** std_encoding) { 127 char *temp = NULL; 128 char *language = NULL, *country = NULL, *variant = NULL, 129 *encoding = NULL; 130 char *p, *encoding_variant; 131 char *lc; 132 133 /* Query the locale set for the category */ 134 lc = setlocale(cat, NULL); 135 136 #ifndef __linux__ 137 if (lc == NULL) { 138 return 0; 139 } 140 141 temp = malloc(strlen(lc) + 1); 142 if (temp == NULL) { 143 JNU_ThrowOutOfMemoryError(env, NULL); 144 return 0; 145 } 146 147 if (cat == LC_CTYPE) { 148 /* 149 * Workaround for Solaris bug 4201684: Xlib doesn't like @euro 150 * locales. Since we don't depend on the libc @euro behavior, 151 * we just remove the qualifier. 152 * On Linux, the bug doesn't occur; on the other hand, @euro 153 * is needed there because it's a shortcut that also determines 154 * the encoding - without it, we wouldn't get ISO-8859-15. 155 * Therefore, this code section is Solaris-specific. 156 */ 157 lc = strdup(lc); /* keep a copy, setlocale trashes original. */ 158 strcpy(temp, lc); 159 p = strstr(temp, "@euro"); 160 if (p != NULL) { 161 *p = '\0'; 162 setlocale(LC_ALL, temp); 163 } 164 } 165 #else 166 if (lc == NULL || !strcmp(lc, "C") || !strcmp(lc, "POSIX")) { 167 lc = "en_US"; 168 } 169 170 temp = malloc(strlen(lc) + 1); 171 if (temp == NULL) { 172 JNU_ThrowOutOfMemoryError(env, NULL); 173 return 0; 174 } 175 176 #endif 177 178 /* 179 * locale string format in Solaris is 180 * <language name>_<country name>.<encoding name>@<variant name> 181 * <country name>, <encoding name>, and <variant name> are optional. 182 */ 183 184 strcpy(temp, lc); 185 186 /* Parse the language, country, encoding, and variant from the 187 * locale. Any of the elements may be missing, but they must occur 188 * in the order language_country.encoding@variant, and must be 189 * preceded by their delimiter (except for language). 190 * 191 * If the locale name (without .encoding@variant, if any) matches 192 * any of the names in the locale_aliases list, map it to the 193 * corresponding full locale name. Most of the entries in the 194 * locale_aliases list are locales that include a language name but 195 * no country name, and this facility is used to map each language 196 * to a default country if that's possible. It's also used to map 197 * the Solaris locale aliases to their proper Java locale IDs. 198 */ 199 200 encoding_variant = malloc(strlen(temp)+1); 201 if (encoding_variant == NULL) { 202 JNU_ThrowOutOfMemoryError(env, NULL); 203 return 0; 204 } 205 206 if ((p = strchr(temp, '.')) != NULL) { 207 strcpy(encoding_variant, p); /* Copy the leading '.' */ 208 *p = '\0'; 209 } else if ((p = strchr(temp, '@')) != NULL) { 210 strcpy(encoding_variant, p); /* Copy the leading '@' */ 211 *p = '\0'; 212 } else { 213 *encoding_variant = '\0'; 214 } 215 216 if (mapLookup(locale_aliases, temp, &p)) { 217 temp = realloc(temp, strlen(p)+1); 218 if (temp == NULL) { 219 JNU_ThrowOutOfMemoryError(env, NULL); 220 return 0; 221 } 222 strcpy(temp, p); 223 encoding_variant = realloc(encoding_variant, strlen(temp)+1); 224 if (encoding_variant == NULL) { 225 JNU_ThrowOutOfMemoryError(env, NULL); 226 return 0; 227 } 228 // check the "encoding_variant" again, if any. 229 if ((p = strchr(temp, '.')) != NULL) { 230 strcpy(encoding_variant, p); /* Copy the leading '.' */ 231 *p = '\0'; 232 } else if ((p = strchr(temp, '@')) != NULL) { 233 strcpy(encoding_variant, p); /* Copy the leading '@' */ 234 *p = '\0'; 235 } 236 } 237 238 language = temp; 239 if ((country = strchr(temp, '_')) != NULL) { 240 *country++ = '\0'; 241 } 242 243 p = encoding_variant; 244 if ((encoding = strchr(p, '.')) != NULL) { 245 p[encoding++ - p] = '\0'; 246 p = encoding; 247 } 319 * customized EUC-JP converter 320 */ 321 *std_encoding = "eucJP-open"; 322 } else if (strcmp(p, "Big5") == 0 || strcmp(p, "BIG5") == 0) { 323 /* 324 * Remap the encoding string to Big5_Solaris which augments 325 * the default converter for Solaris Big5 locales to include 326 * seven additional ideographic characters beyond those included 327 * in the Java "Big5" converter. 328 */ 329 *std_encoding = "Big5_Solaris"; 330 } else if (strcmp(p, "Big5-HKSCS") == 0) { 331 /* 332 * Solaris uses HKSCS2001 333 */ 334 *std_encoding = "Big5-HKSCS-2001"; 335 } 336 #endif 337 } 338 339 free(temp); 340 free(encoding_variant); 341 342 return 1; 343 } 344 345 #ifdef JAVASE_EMBEDDED 346 /* Determine the default embedded toolkit based on whether lib/xawt/ 347 * exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX 348 */ 349 static char* getEmbeddedToolkit() { 350 Dl_info dlinfo; 351 char buf[MAXPATHLEN]; 352 int32_t len; 353 char *p; 354 struct stat statbuf; 355 356 /* Get address of this library and the directory containing it. */ 357 dladdr((void *)getEmbeddedToolkit, &dlinfo); 358 realpath((char *)dlinfo.dli_fname, buf); 359 len = strlen(buf); 360 p = strrchr(buf, '/'); 361 /* Default AWT Toolkit on Linux and Solaris is XAWT. */ 431 { 432 struct utsname name; 433 uname(&name); 434 sprops.os_name = strdup(name.sysname); 435 sprops.os_version = strdup(name.release); 436 437 sprops.os_arch = ARCHPROPNAME; 438 439 if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) { 440 sprops.desktop = "gnome"; 441 } 442 else { 443 sprops.desktop = NULL; 444 } 445 } 446 447 /* Determine the language, country, variant, and encoding from the host, 448 * and store these in the user.language, user.country, user.variant and 449 * file.encoding system properties. */ 450 setlocale(LC_ALL, ""); 451 if (ParseLocale(env, LC_CTYPE, 452 &(sprops.format_language), 453 &(sprops.format_script), 454 &(sprops.format_country), 455 &(sprops.format_variant), 456 &(sprops.encoding))) { 457 ParseLocale(env, LC_MESSAGES, 458 &(sprops.language), 459 &(sprops.script), 460 &(sprops.country), 461 &(sprops.variant), 462 NULL); 463 } else { 464 sprops.language = "en"; 465 sprops.encoding = "ISO8859-1"; 466 } 467 sprops.display_language = sprops.language; 468 sprops.display_script = sprops.script; 469 sprops.display_country = sprops.country; 470 sprops.display_variant = sprops.variant; 471 sprops.sun_jnu_encoding = sprops.encoding; 472 473 #ifdef __linux__ 474 #if __BYTE_ORDER == __LITTLE_ENDIAN 475 sprops.unicode_encoding = "UnicodeLittle"; 476 #else 477 sprops.unicode_encoding = "UnicodeBig"; |