51 #include <paths.h> 52 #define P_tmpdir _PATH_VARTMP 53 #endif 54 #endif 55 56 #include "locale_str.h" 57 #include "java_props.h" 58 59 #if !defined(_ALLBSD_SOURCE) 60 #ifdef __linux__ 61 #ifndef CODESET 62 #define CODESET _NL_CTYPE_CODESET_NAME 63 #endif 64 #else 65 #ifdef ALT_CODESET_KEY 66 #define CODESET ALT_CODESET_KEY 67 #endif 68 #endif 69 #endif /* !_ALLBSD_SOURCE */ 70 71 #ifdef JAVASE_EMBEDDED 72 #include <dlfcn.h> 73 #include <sys/stat.h> 74 #endif 75 76 /* Take an array of string pairs (map of key->value) and a string (key). 77 * Examine each pair in the map to see if the first string (key) matches the 78 * string. If so, store the second string of the pair (value) in the value and 79 * return 1. Otherwise do nothing and return 0. The end of the map is 80 * indicated by an empty string at the start of a pair (key of ""). 81 */ 82 static int 83 mapLookup(char* map[], const char* key, char** value) { 84 int i; 85 for (i = 0; strcmp(map[i], ""); i += 2){ 86 if (!strcmp(key, map[i])){ 87 *value = map[i + 1]; 88 return 1; 89 } 90 } 91 return 0; 92 } 93 94 #ifndef P_tmpdir 95 #define P_tmpdir "/var/tmp" 333 * correctly, but so will files containing UTF-8 characters beyond the 334 * standard ASCII range. 335 * 336 * Specifically, this allows apps launched by double-clicking a .jar 337 * file to correctly read UTF-8 files using the default encoding (see 338 * 8011194). 339 */ 340 if (strcmp(p,"US-ASCII") == 0 && getenv("LANG") == NULL && 341 getenv("LC_ALL") == NULL && getenv("LC_CTYPE") == NULL) { 342 *std_encoding = "UTF-8"; 343 } 344 #endif 345 } 346 347 free(temp); 348 free(encoding_variant); 349 350 return 1; 351 } 352 353 #ifdef JAVASE_EMBEDDED 354 /* Determine the default embedded toolkit based on whether libawt_xawt 355 * exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX 356 */ 357 static char* getEmbeddedToolkit() { 358 Dl_info dlinfo; 359 char buf[MAXPATHLEN]; 360 int32_t len; 361 char *p; 362 struct stat statbuf; 363 364 /* Get address of this library and the directory containing it. */ 365 dladdr((void *)getEmbeddedToolkit, &dlinfo); 366 realpath((char *)dlinfo.dli_fname, buf); 367 len = strlen(buf); 368 p = strrchr(buf, '/'); 369 /* Default AWT Toolkit on Linux and Solaris is XAWT (libawt_xawt.so). */ 370 strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1); 371 /* Check if it exists */ 372 if (stat(buf, &statbuf) == -1 && errno == ENOENT) { 373 /* No - this is a reduced-headless-jre so use special HToolkit */ 374 return "sun.awt.HToolkit"; 375 } 376 else { 377 /* Yes - this is a headful JRE so fallback to SE defaults */ 378 return NULL; 379 } 380 } 381 #endif 382 383 /* This function gets called very early, before VM_CALLS are setup. 384 * Do not use any of the VM_CALLS entries!!! 385 */ 386 java_props_t * 387 GetJavaProperties(JNIEnv *env) 388 { 389 static java_props_t sprops; 390 char *v; /* tmp var */ 391 392 if (sprops.user_dir) { 393 return &sprops; 394 } 395 396 /* tmp dir */ 397 sprops.tmp_dir = P_tmpdir; 398 #ifdef MACOSX 399 /* darwin has a per-user temp dir */ 400 static char tmp_path[PATH_MAX]; 401 int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, tmp_path, PATH_MAX); 402 if (pathSize > 0 && pathSize <= PATH_MAX) { 407 /* Printing properties */ 408 #ifdef MACOSX 409 sprops.printerJob = "sun.lwawt.macosx.CPrinterJob"; 410 #else 411 sprops.printerJob = "sun.print.PSPrinterJob"; 412 #endif 413 414 /* patches/service packs installed */ 415 sprops.patch_level = "unknown"; 416 417 /* Java 2D/AWT properties */ 418 #ifdef MACOSX 419 // Always the same GraphicsEnvironment and Toolkit on Mac OS X 420 sprops.graphics_env = "sun.awt.CGraphicsEnvironment"; 421 sprops.awt_toolkit = "sun.lwawt.macosx.LWCToolkit"; 422 423 // check if we're in a GUI login session and set java.awt.headless=true if not 424 sprops.awt_headless = isInAquaSession() ? NULL : "true"; 425 #else 426 sprops.graphics_env = "sun.awt.X11GraphicsEnvironment"; 427 #ifdef JAVASE_EMBEDDED 428 sprops.awt_toolkit = getEmbeddedToolkit(); 429 if (sprops.awt_toolkit == NULL) // default as below 430 #endif 431 sprops.awt_toolkit = "sun.awt.X11.XToolkit"; 432 #endif 433 434 /* This is used only for debugging of font problems. */ 435 v = getenv("JAVA2D_FONTPATH"); 436 sprops.font_dir = v ? v : NULL; 437 438 #ifdef SI_ISALIST 439 /* supported instruction sets */ 440 { 441 char list[258]; 442 sysinfo(SI_ISALIST, list, sizeof(list)); 443 sprops.cpu_isalist = strdup(list); 444 } 445 #else 446 sprops.cpu_isalist = NULL; 447 #endif 448 449 /* endianness of platform */ 450 { | 51 #include <paths.h> 52 #define P_tmpdir _PATH_VARTMP 53 #endif 54 #endif 55 56 #include "locale_str.h" 57 #include "java_props.h" 58 59 #if !defined(_ALLBSD_SOURCE) 60 #ifdef __linux__ 61 #ifndef CODESET 62 #define CODESET _NL_CTYPE_CODESET_NAME 63 #endif 64 #else 65 #ifdef ALT_CODESET_KEY 66 #define CODESET ALT_CODESET_KEY 67 #endif 68 #endif 69 #endif /* !_ALLBSD_SOURCE */ 70 71 /* Take an array of string pairs (map of key->value) and a string (key). 72 * Examine each pair in the map to see if the first string (key) matches the 73 * string. If so, store the second string of the pair (value) in the value and 74 * return 1. Otherwise do nothing and return 0. The end of the map is 75 * indicated by an empty string at the start of a pair (key of ""). 76 */ 77 static int 78 mapLookup(char* map[], const char* key, char** value) { 79 int i; 80 for (i = 0; strcmp(map[i], ""); i += 2){ 81 if (!strcmp(key, map[i])){ 82 *value = map[i + 1]; 83 return 1; 84 } 85 } 86 return 0; 87 } 88 89 #ifndef P_tmpdir 90 #define P_tmpdir "/var/tmp" 328 * correctly, but so will files containing UTF-8 characters beyond the 329 * standard ASCII range. 330 * 331 * Specifically, this allows apps launched by double-clicking a .jar 332 * file to correctly read UTF-8 files using the default encoding (see 333 * 8011194). 334 */ 335 if (strcmp(p,"US-ASCII") == 0 && getenv("LANG") == NULL && 336 getenv("LC_ALL") == NULL && getenv("LC_CTYPE") == NULL) { 337 *std_encoding = "UTF-8"; 338 } 339 #endif 340 } 341 342 free(temp); 343 free(encoding_variant); 344 345 return 1; 346 } 347 348 /* This function gets called very early, before VM_CALLS are setup. 349 * Do not use any of the VM_CALLS entries!!! 350 */ 351 java_props_t * 352 GetJavaProperties(JNIEnv *env) 353 { 354 static java_props_t sprops; 355 char *v; /* tmp var */ 356 357 if (sprops.user_dir) { 358 return &sprops; 359 } 360 361 /* tmp dir */ 362 sprops.tmp_dir = P_tmpdir; 363 #ifdef MACOSX 364 /* darwin has a per-user temp dir */ 365 static char tmp_path[PATH_MAX]; 366 int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, tmp_path, PATH_MAX); 367 if (pathSize > 0 && pathSize <= PATH_MAX) { 372 /* Printing properties */ 373 #ifdef MACOSX 374 sprops.printerJob = "sun.lwawt.macosx.CPrinterJob"; 375 #else 376 sprops.printerJob = "sun.print.PSPrinterJob"; 377 #endif 378 379 /* patches/service packs installed */ 380 sprops.patch_level = "unknown"; 381 382 /* Java 2D/AWT properties */ 383 #ifdef MACOSX 384 // Always the same GraphicsEnvironment and Toolkit on Mac OS X 385 sprops.graphics_env = "sun.awt.CGraphicsEnvironment"; 386 sprops.awt_toolkit = "sun.lwawt.macosx.LWCToolkit"; 387 388 // check if we're in a GUI login session and set java.awt.headless=true if not 389 sprops.awt_headless = isInAquaSession() ? NULL : "true"; 390 #else 391 sprops.graphics_env = "sun.awt.X11GraphicsEnvironment"; 392 sprops.awt_toolkit = "sun.awt.X11.XToolkit"; 393 #endif 394 395 /* This is used only for debugging of font problems. */ 396 v = getenv("JAVA2D_FONTPATH"); 397 sprops.font_dir = v ? v : NULL; 398 399 #ifdef SI_ISALIST 400 /* supported instruction sets */ 401 { 402 char list[258]; 403 sysinfo(SI_ISALIST, list, sizeof(list)); 404 sprops.cpu_isalist = strdup(list); 405 } 406 #else 407 sprops.cpu_isalist = NULL; 408 #endif 409 410 /* endianness of platform */ 411 { |