--- old/src/java.base/unix/native/libjava/TimeZone_md.c 2015-09-03 14:48:49.168208000 +0200 +++ new/src/java.base/unix/native/libjava/TimeZone_md.c 2015-09-03 14:48:48.822188000 +0200 @@ -40,6 +40,7 @@ #endif #include "jvm.h" +#include "TimeZone_md.h" #define SKIP_SPACE(p) while (*p == ' ' || *p == '\t') p++; @@ -50,8 +51,6 @@ #endif #if defined(__linux__) || defined(_ALLBSD_SOURCE) - - static const char *ETC_TIMEZONE_FILE = "/etc/timezone"; static const char *ZONEINFO_DIR = "/usr/share/zoneinfo"; static const char *DEFAULT_ZONEINFO_FILE = "/etc/localtime"; @@ -62,7 +61,7 @@ static const char *SYS_INIT_FILE = "/etc/default/init"; static const char *ZONEINFO_DIR = "/usr/share/lib/zoneinfo"; static const char *DEFAULT_ZONEINFO_FILE = "/usr/share/lib/zoneinfo/localtime"; -#endif /*__linux__*/ +#endif /* defined(__linux__) || defined(_ALLBSD_SOURCE) */ /* * Returns a pointer to the zone ID portion of the given zoneinfo file @@ -318,8 +317,9 @@ free((void *) buf); return tz; } -#else -#ifdef __solaris__ + +#elif defined(__solaris__) + #if !defined(__sparcv9) && !defined(amd64) /* @@ -444,8 +444,7 @@ } /*NOTREACHED*/ } -#endif /* not __sparcv9 */ - +#endif /* !defined(__sparcv9) && !defined(amd64) */ /* * Performs Solaris dependent mapping. Returns a zone ID if @@ -546,7 +545,7 @@ } /* - * Retruns a zone ID of Solaris when the TZ value is "localtime". + * Returns a zone ID of Solaris when the TZ value is "localtime". * First, it tries scf. If scf fails, it looks for the same file as * /usr/share/lib/zoneinfo/localtime under /usr/share/lib/zoneinfo/. */ @@ -615,10 +614,9 @@ free((void *) buf); return tz; } -#endif /*__solaris__*/ -#endif /*__linux__*/ -#ifdef _AIX +#elif defined(_AIX) + static char * getPlatformTimeZoneID() { @@ -644,8 +642,112 @@ return tz; } -static char *mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz); -#endif + +static char * +mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz) { + FILE *tzmapf; + char mapfilename[PATH_MAX + 1]; + char line[256]; + int linecount = 0; + char *tz_buf = NULL; + char *temp_tz = NULL; + char *str_tmp = NULL; + char *javatz = NULL; + size_t tz_len = 0; + size_t temp_tz_len = 0; + + /* On AIX, the TZ environment variable may end with a comma + * followed by modifier fields. These are ignored here. + */ + tz_len = strlen(tz); + tz_buf = (char *)malloc(tz_len + 1); + strncpy(tz_buf, tz, tz_len); + tz_buf[tz_len] = 0; + temp_tz = strtok_r(tz_buf, ",", &str_tmp); + + if (temp_tz == NULL) + goto tzerr; + + temp_tz_len = strlen(temp_tz); + + if (strlen(java_home_dir) >= (PATH_MAX - 15)) { + jio_fprintf(stderr, "java.home longer than maximum path length \n"); + goto tzerr; + } + + strncpy(mapfilename, java_home_dir, PATH_MAX); + strcat(mapfilename, "/lib/tzmappings"); + + if ((tzmapf = fopen(mapfilename, "r")) == NULL) { + jio_fprintf(stderr, "can't open %s\n", mapfilename); + goto tzerr; + } + + while (fgets(line, sizeof(line), tzmapf) != NULL) { + char *p = line; + char *sol = line; + char *java; + int result; + + linecount++; + /* + * Skip comments and blank lines + */ + if (*p == '#' || *p == '\n') { + continue; + } + + /* + * Get the first field, platform zone ID + */ + while (*p != '\0' && *p != '\t') { + p++; + } + if (*p == '\0') { + /* mapping table is broken! */ + jio_fprintf(stderr, "tzmappings: Illegal format at near line %d.\n", linecount); + break; + } + + *p++ = '\0'; + if ((result = strncmp(temp_tz, sol, temp_tz_len)) == 0) { + /* + * If this is the current platform zone ID, + * take the Java time zone ID (2nd field). + */ + java = p; + while (*p != '\0' && *p != '\n') { + p++; + } + + if (*p == '\0') { + /* mapping table is broken! */ + jio_fprintf(stderr, "tzmappings: Illegal format at line %d.\n", linecount); + break; + } + + *p = '\0'; + javatz = strdup(java); + break; + } else if (result < 0) { + break; + } + } + (void) fclose(tzmapf); + +tzerr: + if (tz_buf != NULL ) { + free((void *) tz_buf); + } + + if (javatz == NULL) { + return getGMTOffsetID(); + } + + return javatz; +} + +#endif /*_AIX*/ /* * findJavaTZ_md() maps platform time zone ID to Java time zone ID @@ -664,54 +766,50 @@ tz = getenv("TZ"); -#if defined(__linux__) || defined(_ALLBSD_SOURCE) - if (tz == NULL) { -#else -#if defined (__solaris__) || defined(_AIX) if (tz == NULL || *tz == '\0') { -#endif -#endif tz = getPlatformTimeZoneID(); freetz = tz; } - /* - * Remove any preceding ':' - */ - if (tz != NULL && *tz == ':') { - tz++; - } - -#ifdef __solaris__ - if (tz != NULL && strcmp(tz, "localtime") == 0) { - tz = getSolarisDefaultZoneID(); - if (freetz != NULL) { - free((void *) freetz); - } - freetz = tz; - } -#endif - if (tz != NULL) { + /* Ignore preceding ':' */ + if (*tz == ':') { + tz++; + } #ifdef __linux__ - /* - * Ignore "posix/" prefix. - */ + /* Ignore "posix/" prefix on Linux. */ if (strncmp(tz, "posix/", 6) == 0) { tz += 6; } #endif - javatz = strdup(tz); + +#if defined(_AIX) + /* On AIX do the platform to Java mapping. */ + javatz = mapPlatformToJavaTimezone(java_home_dir, tz); if (freetz != NULL) { free((void *) freetz); } - -#ifdef _AIX - freetz = mapPlatformToJavaTimezone(java_home_dir, javatz); - if (javatz != NULL) { - free((void *) javatz); +#else +#if defined(__solaris__) + /* Solaris might use localtime, so handle it here. */ + if (strcmp(tz, "localtime") == 0) { + javatz = getSolarisDefaultZoneID(); + if (freetz != NULL) { + free((void *) freetz); + } + } else +#endif + if (freetz == NULL) { + /* strdup if we are still working on getenv result. */ + javatz = strdup(tz); + } else if (freetz != tz) { + /* strdup and free the old buffer, if we moved the pointer. */ + javatz = strdup(tz); + free((void *) freetz); + } else { + /* we are good if we already work on a freshly allocated buffer. */ + javatz = tz; } - javatz = freetz; #endif } @@ -747,6 +845,7 @@ sign, (int)(offset/3600), (int)((offset%3600)/60)); return strdup(buf); } + #else char * @@ -766,7 +865,7 @@ offset = localtm.tm_isdst ? altzone : timezone; #else offset = timezone; -#endif /*__linux__*/ +#endif if (offset == 0) { return strdup("GMT"); @@ -784,101 +883,3 @@ return strdup(buf); } #endif /* MACOSX */ - -#ifdef _AIX -static char * -mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz) { - FILE *tzmapf; - char mapfilename[PATH_MAX+1]; - char line[256]; - int linecount = 0; - char temp[100], *temp_tz; - char *javatz = NULL; - char *str_tmp = NULL; - size_t temp_tz_len = 0; - - /* On AIX, the TZ environment variable may end with a comma - * followed by modifier fields. These are ignored here. - */ - strncpy(temp, tz, 100); - temp_tz = strtok_r(temp, ",", &str_tmp); - - if(temp_tz == NULL) - goto tzerr; - - temp_tz_len = strlen(temp_tz); - - if (strlen(java_home_dir) >= (PATH_MAX - 15)) { - jio_fprintf(stderr, "java.home longer than maximum path length \n"); - goto tzerr; - } - - strncpy(mapfilename, java_home_dir, PATH_MAX); - strcat(mapfilename, "/lib/tzmappings"); - - if ((tzmapf = fopen(mapfilename, "r")) == NULL) { - jio_fprintf(stderr, "can't open %s\n", mapfilename); - goto tzerr; - } - - while (fgets(line, sizeof(line), tzmapf) != NULL) { - char *p = line; - char *sol = line; - char *java; - int result; - - linecount++; - /* - * Skip comments and blank lines - */ - if (*p == '#' || *p == '\n') { - continue; - } - - /* - * Get the first field, platform zone ID - */ - while (*p != '\0' && *p != '\t') { - p++; - } - if (*p == '\0') { - /* mapping table is broken! */ - jio_fprintf(stderr, "tzmappings: Illegal format at near line %d.\n", linecount); - break; - } - - *p++ = '\0'; - if ((result = strncmp(temp_tz, sol, temp_tz_len)) == 0) { - /* - * If this is the current platform zone ID, - * take the Java time zone ID (2nd field). - */ - java = p; - while (*p != '\0' && *p != '\n') { - p++; - } - - if (*p == '\0') { - /* mapping table is broken! */ - jio_fprintf(stderr, "tzmappings: Illegal format at line %d.\n", linecount); - break; - } - - *p = '\0'; - javatz = strdup(java); - break; - } else if (result < 0) { - break; - } - } - (void) fclose(tzmapf); - -tzerr: - if (javatz == NULL) { - return getGMTOffsetID(); - } - - return javatz; -} -#endif -