Zebediah Figura : kernel32: Open the INI file in PROFILE_GetSection.

Alexandre Julliard julliard at winehq.org
Mon Jun 22 15:55:59 CDT 2020


Module: wine
Branch: master
Commit: 9fa54bf690810c96fe11251d3cc0cfdc22a188d7
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9fa54bf690810c96fe11251d3cc0cfdc22a188d7

Author: Zebediah Figura <z.figura12 at gmail.com>
Date:   Sun Jun 21 19:24:12 2020 -0500

kernel32: Open the INI file in PROFILE_GetSection.

Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/profile.c | 62 ++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c
index 7c50fb9a61..dfda24446c 100644
--- a/dlls/kernel32/profile.c
+++ b/dlls/kernel32/profile.c
@@ -856,16 +856,26 @@ static BOOL PROFILE_Open( LPCWSTR filename, BOOL write_access )
  * Returns all keys of a section.
  * If return_values is TRUE, also include the corresponding values.
  */
-static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
+static INT PROFILE_GetSection( const WCHAR *filename, LPCWSTR section_name,
 			       LPWSTR buffer, UINT len, BOOL return_values )
 {
+    PROFILESECTION *section;
     PROFILEKEY *key;
 
     if(!buffer) return 0;
 
     TRACE("%s,%p,%u\n", debugstr_w(section_name), buffer, len);
 
-    while (section)
+    EnterCriticalSection( &PROFILE_CritSect );
+
+    if (!PROFILE_Open( filename, FALSE ))
+    {
+        LeaveCriticalSection( &PROFILE_CritSect );
+        buffer[0] = 0;
+        return 0;
+    }
+
+    for (section = CurProfile->section; section; section = section->next)
     {
         if (!strcmpiW( section->name, section_name ))
         {
@@ -889,6 +899,9 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
                 }
             }
             *buffer = '\0';
+
+            LeaveCriticalSection( &PROFILE_CritSect );
+
             if (len <= 1)
                 /*If either lpszSection or lpszKey is NULL and the supplied
                   destination buffer is too small to hold all the strings,
@@ -901,9 +914,11 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
             }
             return oldlen - len;
         }
-        section = section->next;
     }
     buffer[0] = buffer[1] = '\0';
+
+    LeaveCriticalSection( &PROFILE_CritSect );
+
     return 0;
 }
 
@@ -1039,6 +1054,16 @@ INT WINAPI GetPrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
     if (!buffer || !len) return 0;
     if (!def_val) def_val = emptyW;
     if (!section) return GetPrivateProfileSectionNamesW( buffer, len, filename );
+    if (!entry)
+    {
+        ret = PROFILE_GetSection( filename, section, buffer, len, FALSE );
+        if (!buffer[0])
+        {
+            PROFILE_CopyEntry( buffer, def_val, len );
+            ret = strlenW( buffer );
+        }
+        return ret;
+    }
 
     /* strip any trailing ' ' of def_val. */
     p = def_val + strlenW(def_val) - 1;
@@ -1059,22 +1084,10 @@ INT WINAPI GetPrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
 
     if (PROFILE_Open( filename, FALSE ))
     {
-        if (entry)
-        {
-            PROFILEKEY *key = PROFILE_Find( &CurProfile->section, section, entry, FALSE, FALSE );
-            PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val, len );
-            TRACE("-> %s\n", debugstr_w( buffer ));
-            ret = strlenW( buffer );
-        }
-        else
-        {
-            ret = PROFILE_GetSection( CurProfile->section, section, buffer, len, FALSE );
-            if (!buffer[0])
-            {
-                PROFILE_CopyEntry( buffer, def_val, len );
-                ret = strlenW( buffer );
-            }
-        }
+        PROFILEKEY *key = PROFILE_Find( &CurProfile->section, section, entry, FALSE, FALSE );
+        PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val, len );
+        TRACE("-> %s\n", debugstr_w( buffer ));
+        ret = strlenW( buffer );
     }
     else
     {
@@ -1229,8 +1242,6 @@ UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry,
 INT WINAPI GetPrivateProfileSectionW( LPCWSTR section, LPWSTR buffer,
 				      DWORD len, LPCWSTR filename )
 {
-    int ret = 0;
-
     if (!section || !buffer)
     {
         SetLastError(ERROR_INVALID_PARAMETER);
@@ -1239,14 +1250,7 @@ INT WINAPI GetPrivateProfileSectionW( LPCWSTR section, LPWSTR buffer,
 
     TRACE("(%s, %p, %d, %s)\n", debugstr_w(section), buffer, len, debugstr_w(filename));
 
-    RtlEnterCriticalSection( &PROFILE_CritSect );
-
-    if (PROFILE_Open( filename, FALSE ))
-        ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, TRUE);
-
-    RtlLeaveCriticalSection( &PROFILE_CritSect );
-
-    return ret;
+    return PROFILE_GetSection( filename, section, buffer, len, TRUE );
 }
 
 /***********************************************************************




More information about the wine-cvs mailing list