comparison src/win32/libc_interface.c @ 13370:cf292e05a6cc

[gaim-migrate @ 15743] Don't re-cache the cached value. strcpy() is fine because the src and dest are the same size and src is always nul terminated. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 01 Mar 2006 13:20:59 +0000
parents f33077f19b60
children cb2060acb34f
comparison
equal deleted inserted replaced
13369:d34730f73777 13370:cf292e05a6cc
802 }; 802 };
803 803
804 const char * 804 const char *
805 wgaim_get_timezone_abbreviation(const struct tm *tm) 805 wgaim_get_timezone_abbreviation(const struct tm *tm)
806 { 806 {
807 int i; 807 int i;
808 char tzname[128]; 808 char tzname[128];
809 char localtzname[256]; 809 char localtzname[256];
810 HKEY rootKey; 810 HKEY rootKey;
811 int idx; 811 int idx;
812 812
813 if (!tm) 813 if (!tm)
814 { 814 {
815 gaim_debug_warning("wgaim", "could not determine current date/time: localtime failed\n"); 815 gaim_debug_warning("wgaim", "could not determine current date/time: localtime failed\n");
816 return ""; 816 return "";
829 #if 0 829 #if 0
830 gaim_debug_info("wgaim", "TZ \"%s\" matches Windows timezone \"%s\"\n", 830 gaim_debug_info("wgaim", "TZ \"%s\" matches Windows timezone \"%s\"\n",
831 win32_tzmap[i].ustd, tzname); 831 win32_tzmap[i].ustd, tzname);
832 #endif 832 #endif
833 /* Cache the Result */ 833 /* Cache the Result */
834 if (win32_tzmap[0].wstd[0] != '\0') 834 if (i > 0) {
835 g_free(win32_tzmap[0].wstd); 835 if (win32_tzmap[0].wstd[0] != '\0')
836 win32_tzmap[0].wstd = g_strdup(tzname); 836 g_free(win32_tzmap[0].wstd);
837 win32_tzmap[0].ustd = win32_tzmap[i].ustd; 837 win32_tzmap[0].wstd = g_strdup(tzname);
838 win32_tzmap[0].ustd = win32_tzmap[i].ustd;
839 }
838 840
839 return win32_tzmap[i].ustd; 841 return win32_tzmap[i].ustd;
840 } 842 }
841 if (strcmp(tzname, win32_tzmap[i].wdst) == 0) 843 if (strcmp(tzname, win32_tzmap[i].wdst) == 0)
842 { 844 {
843 #if 0 845 #if 0
844 gaim_debug_info("wgaim", "TZ \"%s\" matches Windows timezone \"%s\"\n", 846 gaim_debug_info("wgaim", "TZ \"%s\" matches Windows timezone \"%s\"\n",
845 win32_tzmap[i].udst, tzname); 847 win32_tzmap[i].udst, tzname);
846 #endif 848 #endif
847 /* Cache the Result */ 849 /* Cache the Result */
848 if (win32_tzmap[0].wdst[0] != '\0') 850 if (i > 0) {
849 g_free(win32_tzmap[0].wdst); 851 if (win32_tzmap[0].wdst[0] != '\0')
850 win32_tzmap[0].wdst = g_strdup(tzname); 852 g_free(win32_tzmap[0].wdst);
851 win32_tzmap[0].udst = win32_tzmap[i].udst; 853 win32_tzmap[0].wdst = g_strdup(tzname);
854 win32_tzmap[0].udst = win32_tzmap[i].udst;
855 }
852 856
853 return win32_tzmap[i].udst; 857 return win32_tzmap[i].udst;
854 } 858 }
855 } 859 }
856 860
870 return ""; 874 return "";
871 } 875 }
872 876
873 for (idx = 0;; idx++) 877 for (idx = 0;; idx++)
874 { 878 {
875 char keyname[256]; 879 char keyname[256];
876 char zonename[256]; 880 char zonename[256];
877 DWORD namesize; 881 DWORD namesize;
878 FILETIME lastwrite; 882 FILETIME lastwrite;
879 HKEY key; 883 HKEY key;
880 LONG r; 884 LONG r;
881 885
882 memset(keyname, 0, sizeof(keyname)); 886 memset(keyname, 0, sizeof(keyname));
883 namesize = sizeof(keyname); 887 namesize = sizeof(keyname);
884 if ((r = RegEnumKeyEx(rootKey, 888 if ((r = RegEnumKeyEx(rootKey,
885 idx, 889 idx,
911 break; 915 break;
912 } 916 }
913 if (strcmp(tzname, zonename) == 0) 917 if (strcmp(tzname, zonename) == 0)
914 { 918 {
915 /* Matched zone */ 919 /* Matched zone */
916 gaim_strlcpy(localtzname, keyname); 920 strcpy(localtzname, keyname);
917 RegCloseKey(key); 921 RegCloseKey(key);
918 break; 922 break;
919 } 923 }
920 memset(zonename, 0, sizeof(zonename)); 924 memset(zonename, 0, sizeof(zonename));
921 namesize = sizeof(zonename); 925 namesize = sizeof(zonename);
926 break; 930 break;
927 } 931 }
928 if (strcmp(tzname, zonename) == 0) 932 if (strcmp(tzname, zonename) == 0)
929 { 933 {
930 /* Matched DST zone */ 934 /* Matched DST zone */
931 gaim_strlcpy(localtzname, keyname); 935 strcpy(localtzname, keyname);
932 RegCloseKey(key); 936 RegCloseKey(key);
933 break; 937 break;
934 } 938 }
935 939
936 RegCloseKey(key); 940 RegCloseKey(key);