| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 1997-2009, International Business Machines | 4 * Copyright (C) 1997-2009, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ****************************************************************************** | 7 ****************************************************************************** |
| 8 * | 8 * |
| 9 * FILE NAME : putil.c (previously putil.cpp and ptypes.cpp) | 9 * FILE NAME : putil.c (previously putil.cpp and ptypes.cpp) |
| 10 * | 10 * |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 /* If we went through the whole string, then it might be okay. | 654 /* If we went through the whole string, then it might be okay. |
| 655 The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30", | 655 The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30", |
| 656 "GRNLNDST3GRNLNDDT" or similar, so we cannot use it. | 656 "GRNLNDST3GRNLNDDT" or similar, so we cannot use it. |
| 657 The rest of the time it could be an Olson ID. George */ | 657 The rest of the time it could be an Olson ID. George */ |
| 658 return (UBool)(id[idx] == 0 | 658 return (UBool)(id[idx] == 0 |
| 659 || uprv_strcmp(id, "PST8PDT") == 0 | 659 || uprv_strcmp(id, "PST8PDT") == 0 |
| 660 || uprv_strcmp(id, "MST7MDT") == 0 | 660 || uprv_strcmp(id, "MST7MDT") == 0 |
| 661 || uprv_strcmp(id, "CST6CDT") == 0 | 661 || uprv_strcmp(id, "CST6CDT") == 0 |
| 662 || uprv_strcmp(id, "EST5EDT") == 0); | 662 || uprv_strcmp(id, "EST5EDT") == 0); |
| 663 } | 663 } |
| 664 |
| 665 /* On some Unix-like OS, 'posix' subdirectory in |
| 666 /usr/share/zoneinfo replicates the top-level contents. 'right' |
| 667 subdirectory has the same set of files, but individual files |
| 668 are different from those in the top-level directory or 'posix' |
| 669 because 'right' has files for TAI (Int'l Atomic Time) while 'posix' |
| 670 has files for UTC. |
| 671 When the first match for /etc/localtime is in either of them |
| 672 (usually in posix because 'right' has different file contents), |
| 673 or TZ environment variable points to one of them, createTimeZone |
| 674 fails because, say, 'posix/America/New_York' is not an Olson |
| 675 timezone id ('America/New_York' is). So, we have to remove |
| 676 'posix/' and 'right/' at the beginning. */ |
| 677 static void removeZoneIDPrefix(const char** id) { |
| 678 if (uprv_strncmp(*id, "posix/", 6) == 0 |
| 679 || uprv_strncmp(*id, "right/", 6) == 0) |
| 680 { |
| 681 *id += 6; |
| 682 } |
| 683 } |
| 664 #endif | 684 #endif |
| 665 | 685 |
| 666 #if defined(U_TZNAME) && !defined(U_WINDOWS) | 686 #if defined(U_TZNAME) && !defined(U_WINDOWS) |
| 667 | 687 |
| 668 #define CONVERT_HOURS_TO_SECONDS(offset) (int32_t)(offset*3600) | 688 #define CONVERT_HOURS_TO_SECONDS(offset) (int32_t)(offset*3600) |
| 669 typedef struct OffsetZoneMapping { | 689 typedef struct OffsetZoneMapping { |
| 670 int32_t offsetSeconds; | 690 int32_t offsetSeconds; |
| 671 int32_t daylightType; /* 1=daylight in June, 2=daylight in December*/ | 691 int32_t daylightType; /* 1=daylight in June, 2=daylight in December*/ |
| 672 const char *stdID; | 692 const char *stdID; |
| 673 const char *dstID; | 693 const char *dstID; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 char curpath[MAX_PATH_SIZE]; | 882 char curpath[MAX_PATH_SIZE]; |
| 863 | 883 |
| 864 if (dirp == NULL) | 884 if (dirp == NULL) |
| 865 return result; | 885 return result; |
| 866 | 886 |
| 867 uprv_memset(curpath, 0, MAX_PATH_SIZE); | 887 uprv_memset(curpath, 0, MAX_PATH_SIZE); |
| 868 uprv_strcpy(curpath, path); | 888 uprv_strcpy(curpath, path); |
| 869 | 889 |
| 870 /* Check each entry in the directory. */ | 890 /* Check each entry in the directory. */ |
| 871 while((dirEntry = readdir(dirp)) != NULL) { | 891 while((dirEntry = readdir(dirp)) != NULL) { |
| 872 if (uprv_strcmp(dirEntry->d_name, SKIP1) != 0 && uprv_strcmp(dirEntry->d
_name, SKIP2) != 0) { | 892 const char* dirName = dirEntry->d_name; |
| 893 if (uprv_strcmp(dirName, SKIP1) != 0 && uprv_strcmp(dirName, SKIP2) != 0
) { |
| 873 /* Create a newpath with the new entry to test each entry in the dir
ectory. */ | 894 /* Create a newpath with the new entry to test each entry in the dir
ectory. */ |
| 874 char newpath[MAX_PATH_SIZE]; | 895 char newpath[MAX_PATH_SIZE]; |
| 875 uprv_strcpy(newpath, curpath); | 896 uprv_strcpy(newpath, curpath); |
| 876 uprv_strcat(newpath, dirEntry->d_name); | 897 uprv_strcat(newpath, dirName); |
| 877 | 898 |
| 878 if ((subDirp = opendir(newpath)) != NULL) { | 899 if ((subDirp = opendir(newpath)) != NULL) { |
| 879 /* If this new path is a directory, make a recursive call with t
he newpath. */ | 900 /* If this new path is a directory, make a recursive call with t
he newpath. */ |
| 880 closedir(subDirp); | 901 closedir(subDirp); |
| 881 uprv_strcat(newpath, "/"); | 902 uprv_strcat(newpath, "/"); |
| 882 result = searchForTZFile(newpath, tzInfo); | 903 result = searchForTZFile(newpath, tzInfo); |
| 883 /* | 904 /* |
| 884 Have to get out here. Otherwise, we'd keep looking | 905 Have to get out here. Otherwise, we'd keep looking |
| 885 and return the first match in the top-level directory | 906 and return the first match in the top-level directory |
| 886 if there's a match in the top-level. If not, this function | 907 if there's a match in the top-level. If not, this function |
| 887 would return NULL and set gTimeZoneBufferPtr to NULL in initDef
ault(). | 908 would return NULL and set gTimeZoneBufferPtr to NULL in initDef
ault(). |
| 888 It worked without this in most cases because we have a fallback
of calling | 909 It worked without this in most cases because we have a fallback
of calling |
| 889 localtime_r to figure out the default timezone. | 910 localtime_r to figure out the default timezone. |
| 890 */ | 911 */ |
| 891 if (result != NULL) | 912 if (result != NULL) |
| 892 break; | 913 break; |
| 893 } else if (uprv_strcmp(TZFILE_SKIP, dirEntry->d_name) != 0 && uprv_s
trcmp(TZFILE_SKIP2, dirEntry->d_name) != 0) { | 914 } else if (uprv_strcmp(TZFILE_SKIP, dirName) != 0 && uprv_strcmp(TZF
ILE_SKIP2, dirName) != 0) { |
| 894 if(compareBinaryFiles(TZDEFAULT, newpath, tzInfo)) { | 915 if(compareBinaryFiles(TZDEFAULT, newpath, tzInfo)) { |
| 895 uprv_strcpy(SEARCH_TZFILE_RESULT, newpath + (sizeof(TZZONEIN
FO) - 1)); | 916 const char* zoneid = newpath + (sizeof(TZZONEINFO)) - 1; |
| 917 removeZoneIDPrefix(&zoneid); |
| 918 uprv_strcpy(SEARCH_TZFILE_RESULT, zoneid); |
| 896 result = SEARCH_TZFILE_RESULT; | 919 result = SEARCH_TZFILE_RESULT; |
| 897 /* Get out after the first one found. */ | 920 /* Get out after the first one found. */ |
| 898 break; | 921 break; |
| 899 } | 922 } |
| 900 } | 923 } |
| 901 } | 924 } |
| 902 } | 925 } |
| 903 closedir(dirp); | 926 closedir(dirp); |
| 904 return result; | 927 return result; |
| 905 } | 928 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 924 return tzid; | 947 return tzid; |
| 925 } | 948 } |
| 926 #endif*/ | 949 #endif*/ |
| 927 | 950 |
| 928 /* This code can be temporarily disabled to test tzname resolution later on. */ | 951 /* This code can be temporarily disabled to test tzname resolution later on. */ |
| 929 #ifndef DEBUG_TZNAME | 952 #ifndef DEBUG_TZNAME |
| 930 tzid = getenv("TZ"); | 953 tzid = getenv("TZ"); |
| 931 if (tzid != NULL && isValidOlsonID(tzid)) | 954 if (tzid != NULL && isValidOlsonID(tzid)) |
| 932 { | 955 { |
| 933 /* This might be a good Olson ID. */ | 956 /* This might be a good Olson ID. */ |
| 934 if (uprv_strncmp(tzid, "posix/", 6) == 0 | 957 removeZoneIDPrefix(&tzid); |
| 935 || uprv_strncmp(tzid, "right/", 6) == 0) | |
| 936 { | |
| 937 /* Remove the posix/ or right/ prefix. */ | |
| 938 tzid += 6; | |
| 939 } | |
| 940 return tzid; | 958 return tzid; |
| 941 } | 959 } |
| 942 /* else U_TZNAME will give a better result. */ | 960 /* else U_TZNAME will give a better result. */ |
| 943 #endif | 961 #endif |
| 944 | 962 |
| 945 #if defined(CHECK_LOCALTIME_LINK) | 963 #if defined(CHECK_LOCALTIME_LINK) |
| 946 /* Caller must handle threading issues */ | 964 /* Caller must handle threading issues */ |
| 947 if (gTimeZoneBufferPtr == NULL) { | 965 if (gTimeZoneBufferPtr == NULL) { |
| 948 /* | 966 /* |
| 949 This is a trick to look at the name of the link to get the Olson ID | 967 This is a trick to look at the name of the link to get the Olson ID |
| (...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 } | 2001 } |
| 1984 | 2002 |
| 1985 /* | 2003 /* |
| 1986 * Hey, Emacs, please set the following: | 2004 * Hey, Emacs, please set the following: |
| 1987 * | 2005 * |
| 1988 * Local Variables: | 2006 * Local Variables: |
| 1989 * indent-tabs-mode: nil | 2007 * indent-tabs-mode: nil |
| 1990 * End: | 2008 * End: |
| 1991 * | 2009 * |
| 1992 */ | 2010 */ |
| OLD | NEW |