From 9a10234ef2b5212ba44b82a797c478f190b4dad1 Mon Sep 17 00:00:00 2001 From: Paul Vriens Date: Thu, 2 Apr 2009 12:16:11 +0200 Subject: [PATCH] kernel32: Fix creation of empty sections in ini files. --- dlls/kernel32/profile.c | 12 ++++++------ dlls/kernel32/tests/profile.c | 30 ++++++------------------------ 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c index d44e819af3b..8a787da2c7f 100644 --- a/dlls/kernel32/profile.c +++ b/dlls/kernel32/profile.c @@ -202,9 +202,9 @@ static void PROFILE_Save( HANDLE hFile, const PROFILESECTION *section, ENCODING for ( ; section; section = section->next) { - int len = 4; + int len = 0; - if (section->name[0]) len += strlenW(section->name); + if (section->name[0]) len += strlenW(section->name) + 4; for (key = section->key; key; key = key->next) { @@ -216,15 +216,15 @@ static void PROFILE_Save( HANDLE hFile, const PROFILESECTION *section, ENCODING if (!buffer) return; p = buffer; - *p++ = '['; if (section->name[0]) { + *p++ = '['; strcpyW( p, section->name ); p += strlenW(p); + *p++ = ']'; + *p++ = '\r'; + *p++ = '\n'; } - *p++ = ']'; - *p++ = '\r'; - *p++ = '\n'; for (key = section->key; key; key = key->next) { diff --git a/dlls/kernel32/tests/profile.c b/dlls/kernel32/tests/profile.c index 5120ec7dfc4..87c0a738670 100644 --- a/dlls/kernel32/tests/profile.c +++ b/dlls/kernel32/tests/profile.c @@ -972,10 +972,7 @@ static void test_WritePrivateProfileString(void) "key5=string5\r\n"; ret = WritePrivateProfileStringA("App3", "key5", "string5", path); ok(ret == TRUE, "Expected TRUE, got %d\n", ret); - todo_wine - { - ok(check_file_data(path, data), "File doesn't match\n"); - } + ok(check_file_data(path, data), "File doesn't match\n"); /* lpString is NULL, key2 key is deleted */ data = "[App1]\r\n" @@ -987,10 +984,7 @@ static void test_WritePrivateProfileString(void) "key5=string5\r\n"; ret = WritePrivateProfileStringA("App1", "key2", NULL, path); ok(ret == TRUE, "Expected TRUE, got %d\n", ret); - todo_wine - { - ok(check_file_data(path, data), "File doesn't match\n"); - } + ok(check_file_data(path, data), "File doesn't match\n"); /* try to delete key2 again */ data = "[App1]\r\n" @@ -1002,10 +996,7 @@ static void test_WritePrivateProfileString(void) "key5=string5\r\n"; ret = WritePrivateProfileStringA("App1", "key2", NULL, path); ok(ret == TRUE, "Expected TRUE, got %d\n", ret); - todo_wine - { - ok(check_file_data(path, data), "File doesn't match\n"); - } + ok(check_file_data(path, data), "File doesn't match\n"); /* lpKeyName is NULL, App1 section is deleted */ data = "[App2]\r\n" @@ -1014,29 +1005,20 @@ static void test_WritePrivateProfileString(void) "key5=string5\r\n"; ret = WritePrivateProfileStringA("App1", NULL, "string1", path); ok(ret == TRUE, "Expected TRUE, got %d\n", ret); - todo_wine - { - ok(check_file_data(path, data), "File doesn't match\n"); - } + ok(check_file_data(path, data), "File doesn't match\n"); /* lpString is not needed to delete a section */ data = "[App3]\r\n" "key5=string5\r\n"; ret = WritePrivateProfileStringA("App2", NULL, NULL, path); ok(ret == TRUE, "Expected TRUE, got %d\n", ret); - todo_wine - { - ok(check_file_data(path, data), "File doesn't match\n"); - } + ok(check_file_data(path, data), "File doesn't match\n"); /* leave just the section */ data = "[App3]\r\n"; ret = WritePrivateProfileStringA("App3", "key5", NULL, path); ok(ret == TRUE, "Expected TRUE, got %d\n", ret); - todo_wine - { - ok(check_file_data(path, data), "File doesn't match\n"); - } + ok(check_file_data(path, data), "File doesn't match\n"); DeleteFileA(path); }