aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/iniutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dutil/iniutil.cpp107
1 files changed, 61 insertions, 46 deletions
diff --git a/src/dutil/iniutil.cpp b/src/dutil/iniutil.cpp
index c9ef6c3d..70b62995 100644
--- a/src/dutil/iniutil.cpp
+++ b/src/dutil/iniutil.cpp
@@ -2,6 +2,21 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5
6// Exit macros
7#define IniExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
8#define IniExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
9#define IniExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
10#define IniExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
11#define IniExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
12#define IniExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_INIUTIL, x, s, __VA_ARGS__)
13#define IniExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_INIUTIL, p, x, e, s, __VA_ARGS__)
14#define IniExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_INIUTIL, p, x, s, __VA_ARGS__)
15#define IniExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_INIUTIL, p, x, e, s, __VA_ARGS__)
16#define IniExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_INIUTIL, p, x, s, __VA_ARGS__)
17#define IniExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_INIUTIL, e, x, s, __VA_ARGS__)
18#define IniExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_INIUTIL, g, x, s, __VA_ARGS__)
19
5const LPCWSTR wzSectionSeparator = L"\\"; 20const LPCWSTR wzSectionSeparator = L"\\";
6 21
7struct INI_STRUCT 22struct INI_STRUCT
@@ -33,7 +48,7 @@ const int INI_HANDLE_BYTES = sizeof(INI_STRUCT);
33 48
34static HRESULT GetSectionPrefixFromName( 49static HRESULT GetSectionPrefixFromName(
35 __in_z LPCWSTR wzName, 50 __in_z LPCWSTR wzName,
36 __deref_out_z LPWSTR* psczOutput 51 __deref_inout_z LPWSTR* psczOutput
37 ); 52 );
38static void UninitializeIniValue( 53static void UninitializeIniValue(
39 INI_VALUE *pivValue 54 INI_VALUE *pivValue
@@ -47,7 +62,7 @@ extern "C" HRESULT DAPI IniInitialize(
47 62
48 // Allocate the handle 63 // Allocate the handle
49 *piHandle = static_cast<INI_HANDLE>(MemAlloc(sizeof(INI_STRUCT), TRUE)); 64 *piHandle = static_cast<INI_HANDLE>(MemAlloc(sizeof(INI_STRUCT), TRUE));
50 ExitOnNull(*piHandle, hr, E_OUTOFMEMORY, "Failed to allocate ini object"); 65 IniExitOnNull(*piHandle, hr, E_OUTOFMEMORY, "Failed to allocate ini object");
51 66
52LExit: 67LExit:
53 return hr; 68 return hr;
@@ -96,7 +111,7 @@ extern "C" HRESULT DAPI IniSetOpenTag(
96 if (wzOpenTagPrefix) 111 if (wzOpenTagPrefix)
97 { 112 {
98 hr = StrAllocString(&pi->sczOpenTagPrefix, wzOpenTagPrefix, 0); 113 hr = StrAllocString(&pi->sczOpenTagPrefix, wzOpenTagPrefix, 0);
99 ExitOnFailure(hr, "Failed to copy open tag prefix to ini struct: %ls", wzOpenTagPrefix); 114 IniExitOnFailure(hr, "Failed to copy open tag prefix to ini struct: %ls", wzOpenTagPrefix);
100 } 115 }
101 else 116 else
102 { 117 {
@@ -106,7 +121,7 @@ extern "C" HRESULT DAPI IniSetOpenTag(
106 if (wzOpenTagPostfix) 121 if (wzOpenTagPostfix)
107 { 122 {
108 hr = StrAllocString(&pi->sczOpenTagPostfix, wzOpenTagPostfix, 0); 123 hr = StrAllocString(&pi->sczOpenTagPostfix, wzOpenTagPostfix, 0);
109 ExitOnFailure(hr, "Failed to copy open tag postfix to ini struct: %ls", wzOpenTagPostfix); 124 IniExitOnFailure(hr, "Failed to copy open tag postfix to ini struct: %ls", wzOpenTagPostfix);
110 } 125 }
111 else 126 else
112 { 127 {
@@ -130,7 +145,7 @@ extern "C" HRESULT DAPI IniSetValueStyle(
130 if (wzValuePrefix) 145 if (wzValuePrefix)
131 { 146 {
132 hr = StrAllocString(&pi->sczValuePrefix, wzValuePrefix, 0); 147 hr = StrAllocString(&pi->sczValuePrefix, wzValuePrefix, 0);
133 ExitOnFailure(hr, "Failed to copy value prefix to ini struct: %ls", wzValuePrefix); 148 IniExitOnFailure(hr, "Failed to copy value prefix to ini struct: %ls", wzValuePrefix);
134 } 149 }
135 else 150 else
136 { 151 {
@@ -140,7 +155,7 @@ extern "C" HRESULT DAPI IniSetValueStyle(
140 if (wzValueSeparator) 155 if (wzValueSeparator)
141 { 156 {
142 hr = StrAllocString(&pi->sczValueSeparator, wzValueSeparator, 0); 157 hr = StrAllocString(&pi->sczValueSeparator, wzValueSeparator, 0);
143 ExitOnFailure(hr, "Failed to copy value separator to ini struct: %ls", wzValueSeparator); 158 IniExitOnFailure(hr, "Failed to copy value separator to ini struct: %ls", wzValueSeparator);
144 } 159 }
145 else 160 else
146 { 161 {
@@ -162,12 +177,12 @@ extern "C" HRESULT DAPI IniSetValueSeparatorException(
162 INI_STRUCT *pi = static_cast<INI_STRUCT *>(piHandle); 177 INI_STRUCT *pi = static_cast<INI_STRUCT *>(piHandle);
163 178
164 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgsczValueSeparatorExceptions), pi->cValueSeparatorExceptions + 1, sizeof(LPWSTR), 5); 179 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgsczValueSeparatorExceptions), pi->cValueSeparatorExceptions + 1, sizeof(LPWSTR), 5);
165 ExitOnFailure(hr, "Failed to increase array size for value separator exceptions"); 180 IniExitOnFailure(hr, "Failed to increase array size for value separator exceptions");
166 dwInsertedIndex = pi->cValueSeparatorExceptions; 181 dwInsertedIndex = pi->cValueSeparatorExceptions;
167 ++pi->cValueSeparatorExceptions; 182 ++pi->cValueSeparatorExceptions;
168 183
169 hr = StrAllocString(&pi->rgsczValueSeparatorExceptions[dwInsertedIndex], wzValueNamePrefix, 0); 184 hr = StrAllocString(&pi->rgsczValueSeparatorExceptions[dwInsertedIndex], wzValueNamePrefix, 0);
170 ExitOnFailure(hr, "Failed to copy value separator exception"); 185 IniExitOnFailure(hr, "Failed to copy value separator exception");
171 186
172LExit: 187LExit:
173 return hr; 188 return hr;
@@ -185,7 +200,7 @@ extern "C" HRESULT DAPI IniSetCommentStyle(
185 if (wzLinePrefix) 200 if (wzLinePrefix)
186 { 201 {
187 hr = StrAllocString(&pi->sczCommentLinePrefix, wzLinePrefix, 0); 202 hr = StrAllocString(&pi->sczCommentLinePrefix, wzLinePrefix, 0);
188 ExitOnFailure(hr, "Failed to copy comment line prefix to ini struct: %ls", wzLinePrefix); 203 IniExitOnFailure(hr, "Failed to copy comment line prefix to ini struct: %ls", wzLinePrefix);
189 } 204 }
190 else 205 else
191 { 206 {
@@ -226,10 +241,10 @@ extern "C" HRESULT DAPI IniParse(
226 BOOL fValuePrefix = (NULL != pi->sczValuePrefix); 241 BOOL fValuePrefix = (NULL != pi->sczValuePrefix);
227 242
228 hr = StrAllocString(&pi->sczPath, wzPath, 0); 243 hr = StrAllocString(&pi->sczPath, wzPath, 0);
229 ExitOnFailure(hr, "Failed to copy path to ini struct: %ls", wzPath); 244 IniExitOnFailure(hr, "Failed to copy path to ini struct: %ls", wzPath);
230 245
231 hr = FileToString(pi->sczPath, &sczContents, &pi->feEncoding); 246 hr = FileToString(pi->sczPath, &sczContents, &pi->feEncoding);
232 ExitOnFailure(hr, "Failed to convert file to string: %ls", pi->sczPath); 247 IniExitOnFailure(hr, "Failed to convert file to string: %ls", pi->sczPath);
233 248
234 if (pfeEncodingFound) 249 if (pfeEncodingFound)
235 { 250 {
@@ -244,7 +259,7 @@ extern "C" HRESULT DAPI IniParse(
244 259
245 dwValuePrefixLength = lstrlenW(pi->sczValuePrefix); 260 dwValuePrefixLength = lstrlenW(pi->sczValuePrefix);
246 hr = StrSplitAllocArray(&pi->rgsczLines, reinterpret_cast<UINT *>(&pi->cLines), sczContents, L"\n"); 261 hr = StrSplitAllocArray(&pi->rgsczLines, reinterpret_cast<UINT *>(&pi->cLines), sczContents, L"\n");
247 ExitOnFailure(hr, "Failed to split INI file into lines"); 262 IniExitOnFailure(hr, "Failed to split INI file into lines");
248 263
249 for (DWORD i = 0; i < pi->cLines; ++i) 264 for (DWORD i = 0; i < pi->cLines; ++i)
250 { 265 {
@@ -324,7 +339,7 @@ extern "C" HRESULT DAPI IniParse(
324 { 339 {
325 // There is an section starting here, let's keep track of it and move on 340 // There is an section starting here, let's keep track of it and move on
326 hr = StrAllocString(&sczCurrentSection, wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix), wzOpenTagPostfix - (wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix))); 341 hr = StrAllocString(&sczCurrentSection, wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix), wzOpenTagPostfix - (wzOpenTagPrefix + lstrlenW(pi->sczOpenTagPrefix)));
327 ExitOnFailure(hr, "Failed to record section name for line: %ls of INI file: %ls", pi->rgsczLines[i], pi->sczPath); 342 IniExitOnFailure(hr, "Failed to record section name for line: %ls of INI file: %ls", pi->rgsczLines[i], pi->sczPath);
328 343
329 // Sections will be calculated dynamically after any set operations, so don't include this in the list of lines to remember for output 344 // Sections will be calculated dynamically after any set operations, so don't include this in the list of lines to remember for output
330 ReleaseNullStr(pi->rgsczLines[i]); 345 ReleaseNullStr(pi->rgsczLines[i]);
@@ -342,28 +357,28 @@ extern "C" HRESULT DAPI IniParse(
342 } 357 }
343 358
344 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgivValues), pi->cValues + 1, sizeof(INI_VALUE), 100); 359 hr = MemEnsureArraySize(reinterpret_cast<void **>(&pi->rgivValues), pi->cValues + 1, sizeof(INI_VALUE), 100);
345 ExitOnFailure(hr, "Failed to increase array size for value array"); 360 IniExitOnFailure(hr, "Failed to increase array size for value array");
346 361
347 if (sczCurrentSection) 362 if (sczCurrentSection)
348 { 363 {
349 hr = StrAllocString(&sczName, sczCurrentSection, 0); 364 hr = StrAllocString(&sczName, sczCurrentSection, 0);
350 ExitOnFailure(hr, "Failed to copy current section name"); 365 IniExitOnFailure(hr, "Failed to copy current section name");
351 366
352 hr = StrAllocConcat(&sczName, wzSectionSeparator, 0); 367 hr = StrAllocConcat(&sczName, wzSectionSeparator, 0);
353 ExitOnFailure(hr, "Failed to copy current section name"); 368 IniExitOnFailure(hr, "Failed to copy current section name");
354 } 369 }
355 370
356 hr = StrAllocConcat(&sczName, wzValueBegin, wzValueSeparator - wzValueBegin); 371 hr = StrAllocConcat(&sczName, wzValueBegin, wzValueSeparator - wzValueBegin);
357 ExitOnFailure(hr, "Failed to copy name"); 372 IniExitOnFailure(hr, "Failed to copy name");
358 373
359 hr = StrAllocString(&sczValue, wzValueSeparator + lstrlenW(pi->sczValueSeparator), 0); 374 hr = StrAllocString(&sczValue, wzValueSeparator + lstrlenW(pi->sczValueSeparator), 0);
360 ExitOnFailure(hr, "Failed to copy value"); 375 IniExitOnFailure(hr, "Failed to copy value");
361 376
362 hr = StrTrimWhitespace(&sczNameTrimmed, sczName); 377 hr = StrTrimWhitespace(&sczNameTrimmed, sczName);
363 ExitOnFailure(hr, "Failed to trim whitespace from name"); 378 IniExitOnFailure(hr, "Failed to trim whitespace from name");
364 379
365 hr = StrTrimWhitespace(&sczValueTrimmed, sczValue); 380 hr = StrTrimWhitespace(&sczValueTrimmed, sczValue);
366 ExitOnFailure(hr, "Failed to trim whitespace from value"); 381 IniExitOnFailure(hr, "Failed to trim whitespace from value");
367 382
368 pi->rgivValues[pi->cValues].wzName = const_cast<LPCWSTR>(sczNameTrimmed); 383 pi->rgivValues[pi->cValues].wzName = const_cast<LPCWSTR>(sczNameTrimmed);
369 sczNameTrimmed = NULL; 384 sczNameTrimmed = NULL;
@@ -397,7 +412,7 @@ LExit:
397 412
398extern "C" HRESULT DAPI IniGetValueList( 413extern "C" HRESULT DAPI IniGetValueList(
399 __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle, 414 __in_bcount(INI_HANDLE_BYTES) INI_HANDLE piHandle,
400 __deref_out_ecount_opt(pcValues) INI_VALUE** prgivValues, 415 __deref_out_ecount_opt(*pcValues) INI_VALUE** prgivValues,
401 __out DWORD *pcValues 416 __out DWORD *pcValues
402 ) 417 )
403{ 418{
@@ -434,7 +449,7 @@ extern "C" HRESULT DAPI IniGetValue(
434 if (NULL == pValue) 449 if (NULL == pValue)
435 { 450 {
436 hr = E_NOTFOUND; 451 hr = E_NOTFOUND;
437 ExitOnFailure(hr, "Failed to check for INI value: %ls", wzValueName); 452 IniExitOnFailure(hr, "Failed to check for INI value: %ls", wzValueName);
438 } 453 }
439 454
440 if (NULL == pValue->wzValue) 455 if (NULL == pValue->wzValue)
@@ -443,7 +458,7 @@ extern "C" HRESULT DAPI IniGetValue(
443 } 458 }
444 459
445 hr = StrAllocString(psczValue, pValue->wzValue, 0); 460 hr = StrAllocString(psczValue, pValue->wzValue, 0);
446 ExitOnFailure(hr, "Failed to make copy of value while looking up INI value named: %ls", wzValueName); 461 IniExitOnFailure(hr, "Failed to make copy of value while looking up INI value named: %ls", wzValueName);
447 462
448LExit: 463LExit:
449 return hr; 464 return hr;
@@ -494,7 +509,7 @@ extern "C" HRESULT DAPI IniSetValue(
494 { 509 {
495 pi->fModified = TRUE; 510 pi->fModified = TRUE;
496 hr = StrAllocString(const_cast<LPWSTR *>(&pValue->wzValue), wzValue, 0); 511 hr = StrAllocString(const_cast<LPWSTR *>(&pValue->wzValue), wzValue, 0);
497 ExitOnFailure(hr, "Failed to update value INI value named: %ls", wzValueName); 512 IniExitOnFailure(hr, "Failed to update value INI value named: %ls", wzValueName);
498 } 513 }
499 514
500 ExitFunction1(hr = S_OK); 515 ExitFunction1(hr = S_OK);
@@ -504,7 +519,7 @@ extern "C" HRESULT DAPI IniSetValue(
504 if (wzValueName) 519 if (wzValueName)
505 { 520 {
506 hr = GetSectionPrefixFromName(wzValueName, &sczSectionPrefix); 521 hr = GetSectionPrefixFromName(wzValueName, &sczSectionPrefix);
507 ExitOnFailure(hr, "Failed to get section prefix from value name: %ls", wzValueName); 522 IniExitOnFailure(hr, "Failed to get section prefix from value name: %ls", wzValueName);
508 } 523 }
509 524
510 // If we have a section prefix, figure out the index to insert it (at the end of the section it belongs in) 525 // If we have a section prefix, figure out the index to insert it (at the end of the section it belongs in)
@@ -545,13 +560,13 @@ extern "C" HRESULT DAPI IniSetValue(
545 560
546 pi->fModified = TRUE; 561 pi->fModified = TRUE;
547 hr = MemInsertIntoArray(reinterpret_cast<void **>(&pi->rgivValues), dwInsertIndex, 1, pi->cValues + 1, sizeof(INI_VALUE), 100); 562 hr = MemInsertIntoArray(reinterpret_cast<void **>(&pi->rgivValues), dwInsertIndex, 1, pi->cValues + 1, sizeof(INI_VALUE), 100);
548 ExitOnFailure(hr, "Failed to insert value into array"); 563 IniExitOnFailure(hr, "Failed to insert value into array");
549 564
550 hr = StrAllocString(&sczName, wzValueName, 0); 565 hr = StrAllocString(&sczName, wzValueName, 0);
551 ExitOnFailure(hr, "Failed to copy name"); 566 IniExitOnFailure(hr, "Failed to copy name");
552 567
553 hr = StrAllocString(&sczValue, wzValue, 0); 568 hr = StrAllocString(&sczValue, wzValue, 0);
554 ExitOnFailure(hr, "Failed to copy value"); 569 IniExitOnFailure(hr, "Failed to copy value");
555 570
556 pi->rgivValues[dwInsertIndex].wzName = const_cast<LPCWSTR>(sczName); 571 pi->rgivValues[dwInsertIndex].wzName = const_cast<LPCWSTR>(sczName);
557 sczName = NULL; 572 sczName = NULL;
@@ -611,7 +626,7 @@ extern "C" HRESULT DAPI IniWriteFile(
611 BOOL fSections = (pi->sczOpenTagPrefix) && (pi->sczOpenTagPostfix); 626 BOOL fSections = (pi->sczOpenTagPrefix) && (pi->sczOpenTagPostfix);
612 627
613 hr = StrAllocString(&sczContents, L"", 0); 628 hr = StrAllocString(&sczContents, L"", 0);
614 ExitOnFailure(hr, "Failed to begin contents string as empty string"); 629 IniExitOnFailure(hr, "Failed to begin contents string as empty string");
615 630
616 // Insert any beginning lines we didn't understand like comments 631 // Insert any beginning lines we didn't understand like comments
617 if (0 < pi->cLines) 632 if (0 < pi->cLines)
@@ -619,10 +634,10 @@ extern "C" HRESULT DAPI IniWriteFile(
619 while (pi->rgsczLines[dwLineArrayIndex]) 634 while (pi->rgsczLines[dwLineArrayIndex])
620 { 635 {
621 hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex], 0); 636 hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex], 0);
622 ExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory"); 637 IniExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory");
623 638
624 hr = StrAllocConcat(&sczContents, L"\r\n", 2); 639 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
625 ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); 640 IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
626 641
627 ++dwLineArrayIndex; 642 ++dwLineArrayIndex;
628 } 643 }
@@ -640,23 +655,23 @@ extern "C" HRESULT DAPI IniWriteFile(
640 655
641 // First see if we need to write a section line 656 // First see if we need to write a section line
642 hr = GetSectionPrefixFromName(pi->rgivValues[i].wzName, &sczNewSectionPrefix); 657 hr = GetSectionPrefixFromName(pi->rgivValues[i].wzName, &sczNewSectionPrefix);
643 ExitOnFailure(hr, "Failed to get section prefix from name: %ls", pi->rgivValues[i].wzName); 658 IniExitOnFailure(hr, "Failed to get section prefix from name: %ls", pi->rgivValues[i].wzName);
644 659
645 // If the new section prefix is different, write a section out for it 660 // If the new section prefix is different, write a section out for it
646 if (fSections && sczNewSectionPrefix && (NULL == sczCurrentSectionPrefix || CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, 0, sczNewSectionPrefix, -1, sczCurrentSectionPrefix, -1))) 661 if (fSections && sczNewSectionPrefix && (NULL == sczCurrentSectionPrefix || CSTR_EQUAL != ::CompareStringW(LOCALE_INVARIANT, 0, sczNewSectionPrefix, -1, sczCurrentSectionPrefix, -1)))
647 { 662 {
648 hr = StrAllocConcat(&sczContents, pi->sczOpenTagPrefix, 0); 663 hr = StrAllocConcat(&sczContents, pi->sczOpenTagPrefix, 0);
649 ExitOnFailure(hr, "Failed to concat open tag prefix to string"); 664 IniExitOnFailure(hr, "Failed to concat open tag prefix to string");
650 665
651 // Exclude section separator (i.e. backslash) from new section prefix 666 // Exclude section separator (i.e. backslash) from new section prefix
652 hr = StrAllocConcat(&sczContents, sczNewSectionPrefix, lstrlenW(sczNewSectionPrefix)-lstrlenW(wzSectionSeparator)); 667 hr = StrAllocConcat(&sczContents, sczNewSectionPrefix, lstrlenW(sczNewSectionPrefix)-lstrlenW(wzSectionSeparator));
653 ExitOnFailure(hr, "Failed to concat section name to string"); 668 IniExitOnFailure(hr, "Failed to concat section name to string");
654 669
655 hr = StrAllocConcat(&sczContents, pi->sczOpenTagPostfix, 0); 670 hr = StrAllocConcat(&sczContents, pi->sczOpenTagPostfix, 0);
656 ExitOnFailure(hr, "Failed to concat open tag postfix to string"); 671 IniExitOnFailure(hr, "Failed to concat open tag postfix to string");
657 672
658 hr = StrAllocConcat(&sczContents, L"\r\n", 2); 673 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
659 ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); 674 IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
660 675
661 ReleaseNullStr(sczCurrentSectionPrefix); 676 ReleaseNullStr(sczCurrentSectionPrefix);
662 sczCurrentSectionPrefix = sczNewSectionPrefix; 677 sczCurrentSectionPrefix = sczNewSectionPrefix;
@@ -674,10 +689,10 @@ extern "C" HRESULT DAPI IniWriteFile(
674 } 689 }
675 690
676 hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex++], 0); 691 hr = StrAllocConcat(&sczContents, pi->rgsczLines[dwLineArrayIndex++], 0);
677 ExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory"); 692 IniExitOnFailure(hr, "Failed to add previous line to ini output buffer in-memory");
678 693
679 hr = StrAllocConcat(&sczContents, L"\r\n", 2); 694 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
680 ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); 695 IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
681 } 696 }
682 697
683 wzName = pi->rgivValues[i].wzName; 698 wzName = pi->rgivValues[i].wzName;
@@ -690,20 +705,20 @@ extern "C" HRESULT DAPI IniWriteFile(
690 if (pi->sczValuePrefix) 705 if (pi->sczValuePrefix)
691 { 706 {
692 hr = StrAllocConcat(&sczContents, pi->sczValuePrefix, 0); 707 hr = StrAllocConcat(&sczContents, pi->sczValuePrefix, 0);
693 ExitOnFailure(hr, "Failed to concat value prefix to ini output buffer"); 708 IniExitOnFailure(hr, "Failed to concat value prefix to ini output buffer");
694 } 709 }
695 710
696 hr = StrAllocConcat(&sczContents, wzName, 0); 711 hr = StrAllocConcat(&sczContents, wzName, 0);
697 ExitOnFailure(hr, "Failed to concat value name to ini output buffer"); 712 IniExitOnFailure(hr, "Failed to concat value name to ini output buffer");
698 713
699 hr = StrAllocConcat(&sczContents, pi->sczValueSeparator, 0); 714 hr = StrAllocConcat(&sczContents, pi->sczValueSeparator, 0);
700 ExitOnFailure(hr, "Failed to concat value separator to ini output buffer"); 715 IniExitOnFailure(hr, "Failed to concat value separator to ini output buffer");
701 716
702 hr = StrAllocConcat(&sczContents, pi->rgivValues[i].wzValue, 0); 717 hr = StrAllocConcat(&sczContents, pi->rgivValues[i].wzValue, 0);
703 ExitOnFailure(hr, "Failed to concat value to ini output buffer"); 718 IniExitOnFailure(hr, "Failed to concat value to ini output buffer");
704 719
705 hr = StrAllocConcat(&sczContents, L"\r\n", 2); 720 hr = StrAllocConcat(&sczContents, L"\r\n", 2);
706 ExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory"); 721 IniExitOnFailure(hr, "Failed to add endline to ini output buffer in-memory");
707 } 722 }
708 723
709 // If no path was specified, use the path to the file we parsed 724 // If no path was specified, use the path to the file we parsed
@@ -713,7 +728,7 @@ extern "C" HRESULT DAPI IniWriteFile(
713 } 728 }
714 729
715 hr = FileFromString(wzPath, 0, sczContents, feEncoding); 730 hr = FileFromString(wzPath, 0, sczContents, feEncoding);
716 ExitOnFailure(hr, "Failed to write INI contents out to file: %ls", wzPath); 731 IniExitOnFailure(hr, "Failed to write INI contents out to file: %ls", wzPath);
717 732
718LExit: 733LExit:
719 ReleaseStr(sczContents); 734 ReleaseStr(sczContents);
@@ -733,7 +748,7 @@ static void UninitializeIniValue(
733 748
734static HRESULT GetSectionPrefixFromName( 749static HRESULT GetSectionPrefixFromName(
735 __in_z LPCWSTR wzName, 750 __in_z LPCWSTR wzName,
736 __deref_out_z LPWSTR* psczOutput 751 __deref_inout_z LPWSTR* psczOutput
737 ) 752 )
738{ 753{
739 HRESULT hr = S_OK; 754 HRESULT hr = S_OK;
@@ -745,7 +760,7 @@ static HRESULT GetSectionPrefixFromName(
745 if (wzSectionDelimiter && wzSectionDelimiter != wzName) 760 if (wzSectionDelimiter && wzSectionDelimiter != wzName)
746 { 761 {
747 hr = StrAllocString(psczOutput, wzName, wzSectionDelimiter - wzName + 1); 762 hr = StrAllocString(psczOutput, wzName, wzSectionDelimiter - wzName + 1);
748 ExitOnFailure(hr, "Failed to copy section prefix"); 763 IniExitOnFailure(hr, "Failed to copy section prefix");
749 } 764 }
750 765
751LExit: 766LExit: