aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/timeutil.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-03-02 14:19:14 -0600
committerSean Hall <r.sean.hall@gmail.com>2021-03-02 15:40:02 -0600
commit10ebf674da5df9224e4eddd3545518434c5b455b (patch)
treeea1f4063edd46e9942eab94dd7adb2f75c6c589e /src/dutil/timeutil.cpp
parent3bbf1347b900ec115a12faf8f46965c9b7649696 (diff)
downloadwix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.gz
wix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.bz2
wix-10ebf674da5df9224e4eddd3545518434c5b455b.zip
Update rest of dutil to use their own source with the Exit* macros.
Fix some CA warnings.
Diffstat (limited to 'src/dutil/timeutil.cpp')
-rw-r--r--src/dutil/timeutil.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/dutil/timeutil.cpp b/src/dutil/timeutil.cpp
index dacb2660..b7953c94 100644
--- a/src/dutil/timeutil.cpp
+++ b/src/dutil/timeutil.cpp
@@ -2,6 +2,21 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5
6// Exit macros
7#define TimeExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
8#define TimeExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
9#define TimeExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
10#define TimeExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
11#define TimeExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
12#define TimeExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, x, s, __VA_ARGS__)
13#define TimeExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_TIMEUTIL, p, x, e, s, __VA_ARGS__)
14#define TimeExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, p, x, s, __VA_ARGS__)
15#define TimeExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_TIMEUTIL, p, x, e, s, __VA_ARGS__)
16#define TimeExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_TIMEUTIL, p, x, s, __VA_ARGS__)
17#define TimeExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_TIMEUTIL, e, x, s, __VA_ARGS__)
18#define TimeExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_TIMEUTIL, g, x, s, __VA_ARGS__)
19
5const LPCWSTR DAY_OF_WEEK[] = { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" }; 20const LPCWSTR DAY_OF_WEEK[] = { L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat" };
6const LPCWSTR MONTH_OF_YEAR[] = { L"None", L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" }; 21const LPCWSTR MONTH_OF_YEAR[] = { L"None", L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" };
7enum TIME_PARSER { DayOfWeek, DayOfMonth, MonthOfYear, Year, Hours, Minutes, Seconds, TimeZone }; 22enum TIME_PARSER { DayOfWeek, DayOfMonth, MonthOfYear, Year, Hours, Minutes, Seconds, TimeZone };
@@ -39,7 +54,7 @@ extern "C" HRESULT DAPI TimeFromString(
39 LPWSTR pwzEnd = NULL; 54 LPWSTR pwzEnd = NULL;
40 55
41 hr = StrAllocString(&pwzTime, wzTime, 0); 56 hr = StrAllocString(&pwzTime, wzTime, 0);
42 ExitOnFailure(hr, "Failed to copy time."); 57 TimeExitOnFailure(hr, "Failed to copy time.");
43 58
44 pwzStart = pwzEnd = pwzTime; 59 pwzStart = pwzEnd = pwzTime;
45 while (pwzEnd && *pwzEnd) 60 while (pwzEnd && *pwzEnd)
@@ -58,7 +73,7 @@ extern "C" HRESULT DAPI TimeFromString(
58 { 73 {
59 case DayOfWeek: 74 case DayOfWeek:
60 hr = DayFromString(pwzStart, &sysTime.wDayOfWeek); 75 hr = DayFromString(pwzStart, &sysTime.wDayOfWeek);
61 ExitOnFailure(hr, "Failed to convert string to day: %ls", pwzStart); 76 TimeExitOnFailure(hr, "Failed to convert string to day: %ls", pwzStart);
62 break; 77 break;
63 78
64 case DayOfMonth: 79 case DayOfMonth:
@@ -67,7 +82,7 @@ extern "C" HRESULT DAPI TimeFromString(
67 82
68 case MonthOfYear: 83 case MonthOfYear:
69 hr = MonthFromString(pwzStart, &sysTime.wMonth); 84 hr = MonthFromString(pwzStart, &sysTime.wMonth);
70 ExitOnFailure(hr, "Failed to convert to month: %ls", pwzStart); 85 TimeExitOnFailure(hr, "Failed to convert to month: %ls", pwzStart);
71 break; 86 break;
72 87
73 case Year: 88 case Year:
@@ -104,7 +119,7 @@ extern "C" HRESULT DAPI TimeFromString(
104 119
105 if (!::SystemTimeToFileTime(&sysTime, pFileTime)) 120 if (!::SystemTimeToFileTime(&sysTime, pFileTime))
106 { 121 {
107 ExitWithLastError(hr, "Failed to convert system time to file time."); 122 TimeExitWithLastError(hr, "Failed to convert system time to file time.");
108 } 123 }
109 124
110LExit: 125LExit:
@@ -134,7 +149,7 @@ extern "C" HRESULT DAPI TimeFromString3339(
134 LPWSTR pwzEnd = NULL; 149 LPWSTR pwzEnd = NULL;
135 150
136 hr = StrAllocString(&pwzTime, wzTime, 0); 151 hr = StrAllocString(&pwzTime, wzTime, 0);
137 ExitOnFailure(hr, "Failed to copy time."); 152 TimeExitOnFailure(hr, "Failed to copy time.");
138 153
139 pwzStart = pwzEnd = pwzTime; 154 pwzStart = pwzEnd = pwzTime;
140 while (pwzEnd && *pwzEnd) 155 while (pwzEnd && *pwzEnd)
@@ -188,7 +203,7 @@ extern "C" HRESULT DAPI TimeFromString3339(
188 203
189 if (!::SystemTimeToFileTime(&sysTime, pFileTime)) 204 if (!::SystemTimeToFileTime(&sysTime, pFileTime))
190 { 205 {
191 ExitWithLastError(hr, "Failed to convert system time to file time."); 206 TimeExitWithLastError(hr, "Failed to convert system time to file time.");
192 } 207 }
193 208
194LExit: 209LExit:
@@ -291,29 +306,29 @@ HRESULT DAPI TimeSystemToDateTimeString(
291 iLenDate = ::GetDateFormatW(locale, 0, pst, DATE_FORMAT, NULL, 0); 306 iLenDate = ::GetDateFormatW(locale, 0, pst, DATE_FORMAT, NULL, 0);
292 if (0 >= iLenDate) 307 if (0 >= iLenDate)
293 { 308 {
294 ExitWithLastError(hr, "Failed to get date format with NULL"); 309 TimeExitWithLastError(hr, "Failed to get date format with NULL");
295 } 310 }
296 311
297 iLenTime = ::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, NULL, 0); 312 iLenTime = ::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, NULL, 0);
298 if (0 >= iLenTime) 313 if (0 >= iLenTime)
299 { 314 {
300 ExitWithLastError(hr, "Failed to get time format with NULL"); 315 TimeExitWithLastError(hr, "Failed to get time format with NULL");
301 } 316 }
302 317
303 // Between both lengths we account for 2 null terminators, and only need one, so we subtract one 318 // Between both lengths we account for 2 null terminators, and only need one, so we subtract one
304 hr = StrAlloc(ppwz, iLenDate + iLenTime - 1); 319 hr = StrAlloc(ppwz, iLenDate + iLenTime - 1);
305 ExitOnFailure(hr, "Failed to allocate string"); 320 TimeExitOnFailure(hr, "Failed to allocate string");
306 321
307 if (!::GetDateFormatW(locale, 0, pst, DATE_FORMAT, *ppwz, iLenDate)) 322 if (!::GetDateFormatW(locale, 0, pst, DATE_FORMAT, *ppwz, iLenDate))
308 { 323 {
309 ExitWithLastError(hr, "Failed to get date format with buffer"); 324 TimeExitWithLastError(hr, "Failed to get date format with buffer");
310 } 325 }
311 // Space to separate them 326 // Space to separate them
312 (*ppwz)[iLenDate - 1] = ' '; 327 (*ppwz)[iLenDate - 1] = ' ';
313 328
314 if (!::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, (*ppwz) + iLenDate - 1, iLenTime)) 329 if (!::GetTimeFormatW(locale, 0, pst, TIME_FORMAT, (*ppwz) + iLenDate - 1, iLenTime))
315 { 330 {
316 ExitWithLastError(hr, "Failed to get time format with buffer"); 331 TimeExitWithLastError(hr, "Failed to get time format with buffer");
317 } 332 }
318 333
319LExit: 334LExit: