1 /* |
1 /* |
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
54 |
54 |
55 static const char *ETC_TIMEZONE_FILE = "/etc/timezone"; |
55 static const char *ETC_TIMEZONE_FILE = "/etc/timezone"; |
56 static const char *ZONEINFO_DIR = "/usr/share/zoneinfo"; |
56 static const char *ZONEINFO_DIR = "/usr/share/zoneinfo"; |
57 static const char *DEFAULT_ZONEINFO_FILE = "/etc/localtime"; |
57 static const char *DEFAULT_ZONEINFO_FILE = "/etc/localtime"; |
58 #else |
58 #else |
|
59 #ifdef _AIX |
|
60 static const char *ETC_ENVIRONMENT_FILE = "/etc/environment"; |
|
61 #endif |
59 static const char *SYS_INIT_FILE = "/etc/default/init"; |
62 static const char *SYS_INIT_FILE = "/etc/default/init"; |
60 static const char *ZONEINFO_DIR = "/usr/share/lib/zoneinfo"; |
63 static const char *ZONEINFO_DIR = "/usr/share/lib/zoneinfo"; |
61 static const char *DEFAULT_ZONEINFO_FILE = "/usr/share/lib/zoneinfo/localtime"; |
64 static const char *DEFAULT_ZONEINFO_FILE = "/usr/share/lib/zoneinfo/localtime"; |
62 #endif /*__linux__*/ |
65 #endif /*__linux__*/ |
63 |
66 |
617 |
620 |
618 #ifdef _AIX |
621 #ifdef _AIX |
619 static char * |
622 static char * |
620 getPlatformTimeZoneID() |
623 getPlatformTimeZoneID() |
621 { |
624 { |
622 return NULL; |
625 FILE *fp; |
623 } |
626 char *tz = NULL; |
|
627 char *tz_key = "TZ="; |
|
628 char line[256]; |
|
629 size_t tz_key_len = strlen(tz_key); |
|
630 |
|
631 if ((fp = fopen(ETC_ENVIRONMENT_FILE, "r")) != NULL) { |
|
632 while (fgets(line, sizeof(line), fp) != NULL) { |
|
633 char *p = strchr(line, '\n'); |
|
634 if (p != NULL) { |
|
635 *p = '\0'; |
|
636 } |
|
637 if (0 == strncmp(line, tz_key, tz_key_len)) { |
|
638 tz = strdup(line + tz_key_len); |
|
639 break; |
|
640 } |
|
641 } |
|
642 (void) fclose(fp); |
|
643 } |
|
644 |
|
645 return tz; |
|
646 } |
|
647 static char *mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz); |
624 #endif |
648 #endif |
625 |
649 |
626 /* |
650 /* |
627 * findJavaTZ_md() maps platform time zone ID to Java time zone ID |
651 * findJavaTZ_md() maps platform time zone ID to Java time zone ID |
628 * using <java_home>/lib/tzmappings. If the TZ value is not found, it |
652 * using <java_home>/lib/tzmappings. If the TZ value is not found, it |
745 sprintf(buf, (const char *)"GMT%c%02d:%02d", |
779 sprintf(buf, (const char *)"GMT%c%02d:%02d", |
746 sign, (int)(offset/3600), (int)((offset%3600)/60)); |
780 sign, (int)(offset/3600), (int)((offset%3600)/60)); |
747 return strdup(buf); |
781 return strdup(buf); |
748 } |
782 } |
749 #endif /* MACOSX */ |
783 #endif /* MACOSX */ |
|
784 |
|
785 #ifdef _AIX |
|
786 static char * |
|
787 mapPlatformToJavaTimezone(const char *java_home_dir, const char *tz) { |
|
788 FILE *tzmapf; |
|
789 char mapfilename[PATH_MAX+1]; |
|
790 char line[256]; |
|
791 int linecount = 0; |
|
792 char temp[100], *temp_tz; |
|
793 char *javatz = NULL; |
|
794 char *str_tmp = NULL; |
|
795 size_t temp_tz_len = 0; |
|
796 |
|
797 /* On AIX, the TZ environment variable may end with a comma |
|
798 * followed by modifier fields. These are ignored here. |
|
799 */ |
|
800 strncpy(temp, tz, 100); |
|
801 temp_tz = strtok_r(temp, ",", &str_tmp); |
|
802 |
|
803 if(temp_tz == NULL) |
|
804 goto tzerr; |
|
805 |
|
806 temp_tz_len = strlen(temp_tz); |
|
807 |
|
808 if (strlen(java_home_dir) >= (PATH_MAX - 15)) { |
|
809 jio_fprintf(stderr, "java.home longer than maximum path length \n"); |
|
810 goto tzerr; |
|
811 } |
|
812 |
|
813 strncpy(mapfilename, java_home_dir, PATH_MAX); |
|
814 strcat(mapfilename, "/lib/tzmappings"); |
|
815 |
|
816 if ((tzmapf = fopen(mapfilename, "r")) == NULL) { |
|
817 jio_fprintf(stderr, "can't open %s\n", mapfilename); |
|
818 goto tzerr; |
|
819 } |
|
820 |
|
821 while (fgets(line, sizeof(line), tzmapf) != NULL) { |
|
822 char *p = line; |
|
823 char *sol = line; |
|
824 char *java; |
|
825 int result; |
|
826 |
|
827 linecount++; |
|
828 /* |
|
829 * Skip comments and blank lines |
|
830 */ |
|
831 if (*p == '#' || *p == '\n') { |
|
832 continue; |
|
833 } |
|
834 |
|
835 /* |
|
836 * Get the first field, platform zone ID |
|
837 */ |
|
838 while (*p != '\0' && *p != '\t') { |
|
839 p++; |
|
840 } |
|
841 if (*p == '\0') { |
|
842 /* mapping table is broken! */ |
|
843 jio_fprintf(stderr, "tzmappings: Illegal format at near line %d.\n", linecount); |
|
844 break; |
|
845 } |
|
846 |
|
847 *p++ = '\0'; |
|
848 if ((result = strncmp(temp_tz, sol, temp_tz_len)) == 0) { |
|
849 /* |
|
850 * If this is the current platform zone ID, |
|
851 * take the Java time zone ID (2nd field). |
|
852 */ |
|
853 java = p; |
|
854 while (*p != '\0' && *p != '\n') { |
|
855 p++; |
|
856 } |
|
857 |
|
858 if (*p == '\0') { |
|
859 /* mapping table is broken! */ |
|
860 jio_fprintf(stderr, "tzmappings: Illegal format at line %d.\n", linecount); |
|
861 break; |
|
862 } |
|
863 |
|
864 *p = '\0'; |
|
865 javatz = strdup(java); |
|
866 break; |
|
867 } else if (result < 0) { |
|
868 break; |
|
869 } |
|
870 } |
|
871 (void) fclose(tzmapf); |
|
872 |
|
873 tzerr: |
|
874 if (javatz == NULL) { |
|
875 return getGMTOffsetID(); |
|
876 } |
|
877 |
|
878 return javatz; |
|
879 } |
|
880 #endif |
|
881 |