From 89fdf0a879712cabdc91a99375bd669413b431b8 Mon Sep 17 00:00:00 2001 From: Dmitry Kislyuk Date: Thu, 26 Mar 2009 22:32:57 -0500 Subject: Set last error when GetPrivateProfileSection can't find section in ini file --- dlls/kernel32/profile.c | 16 +++++++++++++--- dlls/kernel32/tests/profile.c | 3 +-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c index d44e819..7629a99 100644 --- a/dlls/kernel32/profile.c +++ b/dlls/kernel32/profile.c @@ -865,7 +865,8 @@ static BOOL PROFILE_Open( LPCWSTR filename, BOOL write_access ) * If return_values is TRUE, also include the corresponding values. */ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name, - LPWSTR buffer, UINT len, BOOL return_values, BOOL return_noequalkeys ) + LPWSTR buffer, UINT len, BOOL return_values, BOOL return_noequalkeys, + BOOL *section_found) { PROFILEKEY *key; @@ -878,6 +879,9 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name, if (section->name[0] && !strcmpiW( section->name, section_name )) { UINT oldlen = len; + + *section_found = TRUE; + for (key = section->key; key; key = key->next) { if (len <= 2) break; @@ -984,6 +988,7 @@ static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name, { PROFILEKEY *key = NULL; static const WCHAR empty_strW[] = { 0 }; + BOOL section_found = FALSE; if(!buffer || !len) return 0; @@ -1006,7 +1011,7 @@ static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name, /* no "else" here ! */ if (section && section[0]) { - INT ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, FALSE, !win32); + INT ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, FALSE, !win32, §ion_found); if (!buffer[0]) /* no luck -> def_val */ { PROFILE_CopyEntry(buffer, def_val, len, TRUE); @@ -1351,6 +1356,7 @@ INT WINAPI GetPrivateProfileSectionW( LPCWSTR section, LPWSTR buffer, DWORD len, LPCWSTR filename ) { int ret = 0; + BOOL section_found = FALSE; if (!section || !buffer) { @@ -1363,7 +1369,11 @@ INT WINAPI GetPrivateProfileSectionW( LPCWSTR section, LPWSTR buffer, RtlEnterCriticalSection( &PROFILE_CritSect ); if (PROFILE_Open( filename, FALSE )) - ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, TRUE, FALSE); + { + ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, TRUE, FALSE, §ion_found); + if (!section_found) + SetLastError(ERROR_FILE_NOT_FOUND); + } RtlLeaveCriticalSection( &PROFILE_CritSect ); diff --git a/dlls/kernel32/tests/profile.c b/dlls/kernel32/tests/profile.c index 5651deb..f57c797 100644 --- a/dlls/kernel32/tests/profile.c +++ b/dlls/kernel32/tests/profile.c @@ -179,9 +179,8 @@ static void test_profile_sections(void) "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); SetLastError(0xdeadbeef); - ret = GetPrivateProfileSectionA( "section1", buf, sizeof(buf), NULL ); + ret = GetPrivateProfileSectionA( "section1", buf, sizeof(buf), NULL ); ok( ret == 0, "expected return size 0, got %d\n", ret ); - todo_wine ok( GetLastError() == ERROR_FILE_NOT_FOUND || broken(GetLastError() == 0xdeadbeef), /* Win9x, WinME */ "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); -- 1.5.6.3