xref: /reactos/sdk/lib/rtl/timezone.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:         See COPYING in the top level directory
3  * PROJECT:           ReactOS system libraries
4  * PURPOSE:           Timezone functions
5  * FILE:              lib/rtl/timezone.c
6  * PROGRAMER:         Eric Kohl
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include <rtl.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FUNCTIONS ***************************************************************/
17 
18 /*
19  * @implemented
20  */
21 NTSTATUS
22 NTAPI
RtlQueryTimeZoneInformation(PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)23 RtlQueryTimeZoneInformation(PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)
24 {
25     RTL_QUERY_REGISTRY_TABLE QueryTable[8];
26     UNICODE_STRING StandardName;
27     UNICODE_STRING DaylightName;
28     NTSTATUS Status;
29 
30     DPRINT("RtlQueryTimeZoneInformation()\n");
31 
32     PAGED_CODE_RTL();
33 
34     RtlZeroMemory(QueryTable,
35                   sizeof(QueryTable));
36 
37     StandardName.Length = 0;
38     StandardName.MaximumLength = 32 * sizeof(WCHAR);
39     StandardName.Buffer = TimeZoneInformation->StandardName;
40 
41     DaylightName.Length = 0;
42     DaylightName.MaximumLength = 32 * sizeof(WCHAR);
43     DaylightName.Buffer = TimeZoneInformation->DaylightName;
44 
45     QueryTable[0].Name = L"Bias";
46     QueryTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
47     QueryTable[0].EntryContext = &TimeZoneInformation->Bias;
48 
49     QueryTable[1].Name = L"StandardName";
50     QueryTable[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
51     QueryTable[1].EntryContext = &StandardName;
52 
53     QueryTable[2].Name = L"StandardBias";
54     QueryTable[2].Flags = RTL_QUERY_REGISTRY_DIRECT;
55     QueryTable[2].EntryContext = &TimeZoneInformation->StandardBias;
56 
57     QueryTable[3].Name = L"StandardStart";
58     QueryTable[3].Flags = RTL_QUERY_REGISTRY_DIRECT;
59     QueryTable[3].EntryContext = &TimeZoneInformation->StandardDate;
60 
61     QueryTable[4].Name = L"DaylightName";
62     QueryTable[4].Flags = RTL_QUERY_REGISTRY_DIRECT;
63     QueryTable[4].EntryContext = &DaylightName;
64 
65     QueryTable[5].Name = L"DaylightBias";
66     QueryTable[5].Flags = RTL_QUERY_REGISTRY_DIRECT;
67     QueryTable[5].EntryContext = &TimeZoneInformation->DaylightBias;
68 
69     QueryTable[6].Name = L"DaylightStart";
70     QueryTable[6].Flags = RTL_QUERY_REGISTRY_DIRECT;
71     QueryTable[6].EntryContext = &TimeZoneInformation->DaylightDate;
72 
73     Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
74                                     L"TimeZoneInformation",
75                                     QueryTable,
76                                     NULL,
77                                     NULL);
78 
79     return Status;
80 }
81 
82 
83 /*
84  * @implemented
85  */
86 NTSTATUS
87 NTAPI
RtlSetTimeZoneInformation(PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)88 RtlSetTimeZoneInformation(PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)
89 {
90     SIZE_T Length;
91     NTSTATUS Status;
92 
93     DPRINT("RtlSetTimeZoneInformation()\n");
94 
95     PAGED_CODE_RTL();
96 
97     Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
98                                    L"TimeZoneInformation",
99                                    L"Bias",
100                                    REG_DWORD,
101                                    &TimeZoneInformation->Bias,
102                                    sizeof(LONG));
103     if (!NT_SUCCESS(Status))
104     {
105         return Status;
106     }
107 
108     Length = (wcslen(TimeZoneInformation->StandardName) + 1) * sizeof(WCHAR);
109     Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
110                                    L"TimeZoneInformation",
111                                    L"StandardName",
112                                    REG_SZ,
113                                    TimeZoneInformation->StandardName,
114                                    (ULONG)Length);
115     if (!NT_SUCCESS(Status))
116     {
117         return Status;
118     }
119 
120     Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
121                                    L"TimeZoneInformation",
122                                    L"StandardBias",
123                                    REG_DWORD,
124                                    &TimeZoneInformation->StandardBias,
125                                    sizeof(LONG));
126     if (!NT_SUCCESS(Status))
127     {
128         return Status;
129     }
130 
131     Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
132                                    L"TimeZoneInformation",
133                                    L"StandardStart",
134                                    REG_BINARY,
135                                    &TimeZoneInformation->StandardDate,
136                                    sizeof(SYSTEMTIME));
137     if (!NT_SUCCESS(Status))
138     {
139         return Status;
140     }
141 
142     Length = (wcslen(TimeZoneInformation->DaylightName) + 1) * sizeof(WCHAR);
143     Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
144                                    L"TimeZoneInformation",
145                                    L"DaylightName",
146                                    REG_SZ,
147                                    TimeZoneInformation->DaylightName,
148                                    (ULONG)Length);
149     if (!NT_SUCCESS(Status))
150     {
151         return Status;
152     }
153 
154     Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
155                                    L"TimeZoneInformation",
156                                    L"DaylightBias",
157                                    REG_DWORD,
158                                    &TimeZoneInformation->DaylightBias,
159                                    sizeof(LONG));
160     if (!NT_SUCCESS(Status))
161     {
162         return Status;
163     }
164 
165     Status = RtlWriteRegistryValue(RTL_REGISTRY_CONTROL,
166                                    L"TimeZoneInformation",
167                                    L"DaylightStart",
168                                    REG_BINARY,
169                                    &TimeZoneInformation->DaylightDate,
170                                    sizeof(SYSTEMTIME));
171 
172     return Status;
173 }
174 
175 /* EOF */
176