mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-06 13:24:06 +00:00
kernel32: Simplify GetPrivateProfileStringW().
Signed-off-by: Zebediah Figura <z.figura12@gmail.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
22a6c60e18
commit
e4b2482e53
|
@ -949,64 +949,6 @@ static INT PROFILE_GetSectionNames( LPWSTR buffer, UINT len )
|
|||
return buf-buffer;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* PROFILE_GetString
|
||||
*
|
||||
* Get a profile string.
|
||||
*
|
||||
* Tests with GetPrivateProfileString16, W95a,
|
||||
* with filled buffer ("****...") and section "set1" and key_name "1" valid:
|
||||
* section key_name def_val res buffer
|
||||
* "set1" "1" "x" 43 [data]
|
||||
* "set1" "1 " "x" 43 [data] (!)
|
||||
* "set1" " 1 "' "x" 43 [data] (!)
|
||||
* "set1" "" "x" 1 "x"
|
||||
* "set1" "" "x " 1 "x" (!)
|
||||
* "set1" "" " x " 3 " x" (!)
|
||||
* "set1" NULL "x" 6 "1\02\03\0\0"
|
||||
* "set1" "" "x" 1 "x"
|
||||
* NULL "1" "x" 0 "" (!)
|
||||
* "" "1" "x" 1 "x"
|
||||
* NULL NULL "" 0 ""
|
||||
*
|
||||
*
|
||||
*/
|
||||
static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
|
||||
LPCWSTR def_val, LPWSTR buffer, UINT len )
|
||||
{
|
||||
PROFILEKEY *key = NULL;
|
||||
static const WCHAR empty_strW[] = { 0 };
|
||||
|
||||
if(!buffer || !len) return 0;
|
||||
|
||||
if (!def_val) def_val = empty_strW;
|
||||
if (key_name)
|
||||
{
|
||||
key = PROFILE_Find( &CurProfile->section, section, key_name, FALSE, FALSE);
|
||||
PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
|
||||
len, TRUE );
|
||||
TRACE("(%s,%s,%s): returning %s\n",
|
||||
debugstr_w(section), debugstr_w(key_name),
|
||||
debugstr_w(def_val), debugstr_w(buffer) );
|
||||
return strlenW( buffer );
|
||||
}
|
||||
/* no "else" here ! */
|
||||
if (section)
|
||||
{
|
||||
INT ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, FALSE);
|
||||
if (!buffer[0]) /* no luck -> def_val */
|
||||
{
|
||||
PROFILE_CopyEntry(buffer, def_val, len, TRUE);
|
||||
ret = strlenW(buffer);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
buffer[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
* PROFILE_SetString
|
||||
*
|
||||
|
@ -1087,45 +1029,59 @@ INT WINAPI GetPrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
|
|||
LPCWSTR def_val, LPWSTR buffer,
|
||||
UINT len, LPCWSTR filename )
|
||||
{
|
||||
static const WCHAR emptyW[] = {0};
|
||||
int ret;
|
||||
LPWSTR defval_tmp = NULL;
|
||||
const WCHAR *p;
|
||||
|
||||
TRACE("%s,%s,%s,%p,%u,%s\n", debugstr_w(section), debugstr_w(entry),
|
||||
debugstr_w(def_val), buffer, len, debugstr_w(filename));
|
||||
|
||||
if (!buffer || !len) return 0;
|
||||
if (!def_val) def_val = emptyW;
|
||||
if (!section) return GetPrivateProfileSectionNamesW( buffer, len, filename );
|
||||
|
||||
/* strip any trailing ' ' of def_val. */
|
||||
if (def_val)
|
||||
p = def_val + strlenW(def_val) - 1;
|
||||
|
||||
while (p > def_val && *p == ' ') p--;
|
||||
|
||||
if (p >= def_val)
|
||||
{
|
||||
LPCWSTR p = def_val + strlenW(def_val) - 1;
|
||||
int vlen = (int)(p - def_val) + 1;
|
||||
|
||||
while (p > def_val && *p == ' ')
|
||||
p--;
|
||||
|
||||
if (p >= def_val)
|
||||
{
|
||||
int vlen = (int)(p - def_val) + 1;
|
||||
|
||||
defval_tmp = HeapAlloc(GetProcessHeap(), 0, (vlen + 1) * sizeof(WCHAR));
|
||||
memcpy(defval_tmp, def_val, vlen * sizeof(WCHAR));
|
||||
defval_tmp[vlen] = '\0';
|
||||
def_val = defval_tmp;
|
||||
}
|
||||
defval_tmp = HeapAlloc(GetProcessHeap(), 0, (vlen + 1) * sizeof(WCHAR));
|
||||
memcpy(defval_tmp, def_val, vlen * sizeof(WCHAR));
|
||||
defval_tmp[vlen] = '\0';
|
||||
def_val = defval_tmp;
|
||||
}
|
||||
|
||||
RtlEnterCriticalSection( &PROFILE_CritSect );
|
||||
|
||||
if (PROFILE_Open( filename, FALSE )) {
|
||||
if (section == NULL)
|
||||
ret = PROFILE_GetSectionNames(buffer, len);
|
||||
else
|
||||
/* PROFILE_GetString can handle the 'entry == NULL' case */
|
||||
ret = PROFILE_GetString( section, entry, def_val, buffer, len );
|
||||
} else if (buffer && def_val) {
|
||||
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, TRUE );
|
||||
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, TRUE );
|
||||
ret = strlenW( buffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lstrcpynW( buffer, def_val, len );
|
||||
ret = strlenW( buffer );
|
||||
}
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
RtlLeaveCriticalSection( &PROFILE_CritSect );
|
||||
|
||||
|
|
Loading…
Reference in a new issue