kernel32: Reimplement GetPrivateProfileString16 on top of 32-bit functions and move it to file16.c.
This commit is contained in:
parent
362ecd06f6
commit
86c6021c71
|
@ -427,6 +427,81 @@ UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* GetPrivateProfileString (KERNEL.128)
|
||||||
|
*/
|
||||||
|
INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry,
|
||||||
|
LPCSTR def_val, LPSTR buffer,
|
||||||
|
UINT16 len, LPCSTR filename )
|
||||||
|
{
|
||||||
|
if (!section)
|
||||||
|
{
|
||||||
|
if (buffer && len) buffer[0] = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!entry)
|
||||||
|
{
|
||||||
|
/* We have to return the list of keys in the section but without the values
|
||||||
|
* so we need to massage the results of GetPrivateProfileSectionA.
|
||||||
|
*/
|
||||||
|
UINT ret, oldlen = len, size = min( len, 1024 );
|
||||||
|
LPSTR data, src;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (!(data = HeapAlloc(GetProcessHeap(), 0, size ))) return 0;
|
||||||
|
ret = GetPrivateProfileSectionA( section, data, size, filename );
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
HeapFree( GetProcessHeap(), 0, data );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (ret != size - 2) break;
|
||||||
|
/* overflow, try again */
|
||||||
|
size *= 2;
|
||||||
|
HeapFree( GetProcessHeap(), 0, data );
|
||||||
|
}
|
||||||
|
|
||||||
|
src = data;
|
||||||
|
while (len && *src)
|
||||||
|
{
|
||||||
|
char *p = strchr( src, '=' );
|
||||||
|
|
||||||
|
if (!p) p = src + strlen(src);
|
||||||
|
if (p - src < len)
|
||||||
|
{
|
||||||
|
memcpy( buffer, src, p - src );
|
||||||
|
buffer += p - src;
|
||||||
|
*buffer++ = 0;
|
||||||
|
len -= (p - src) + 1;
|
||||||
|
src += strlen(src) + 1;
|
||||||
|
}
|
||||||
|
else /* overflow */
|
||||||
|
{
|
||||||
|
memcpy( buffer, src, len );
|
||||||
|
buffer += len;
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HeapFree( GetProcessHeap(), 0, data );
|
||||||
|
|
||||||
|
if (len)
|
||||||
|
{
|
||||||
|
*buffer = 0;
|
||||||
|
return oldlen - len;
|
||||||
|
}
|
||||||
|
if (oldlen > 2)
|
||||||
|
{
|
||||||
|
buffer[-2] = 0;
|
||||||
|
buffer[-1] = 0;
|
||||||
|
return oldlen - 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return GetPrivateProfileStringA( section, entry, def_val, buffer, len, filename );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* WritePrivateProfileString (KERNEL.129)
|
* WritePrivateProfileString (KERNEL.129)
|
||||||
*/
|
*/
|
||||||
|
@ -548,6 +623,15 @@ WORD WINAPI GetShortPathName16( LPCSTR longpath, LPSTR shortpath, WORD len )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* WriteOutProfiles (KERNEL.315)
|
||||||
|
*/
|
||||||
|
void WINAPI WriteOutProfiles16(void)
|
||||||
|
{
|
||||||
|
WritePrivateProfileSectionW( NULL, NULL, NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* WritePrivateProfileStruct (KERNEL.406)
|
* WritePrivateProfileStruct (KERNEL.406)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -199,7 +199,7 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
||||||
thread_detach();
|
thread_detach();
|
||||||
break;
|
break;
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
WriteOutProfiles16();
|
WritePrivateProfileSectionW( NULL, NULL, NULL );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "winnls.h"
|
#include "winnls.h"
|
||||||
#include "winerror.h"
|
#include "winerror.h"
|
||||||
#include "winternl.h"
|
#include "winternl.h"
|
||||||
#include "wine/winbase16.h"
|
|
||||||
#include "wine/unicode.h"
|
#include "wine/unicode.h"
|
||||||
#include "wine/library.h"
|
#include "wine/library.h"
|
||||||
#include "wine/debug.h"
|
#include "wine/debug.h"
|
||||||
|
@ -865,7 +864,7 @@ static BOOL PROFILE_Open( LPCWSTR filename, BOOL write_access )
|
||||||
* If return_values is TRUE, also include the corresponding values.
|
* If return_values is TRUE, also include the corresponding values.
|
||||||
*/
|
*/
|
||||||
static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
|
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 )
|
||||||
{
|
{
|
||||||
PROFILEKEY *key;
|
PROFILEKEY *key;
|
||||||
|
|
||||||
|
@ -883,7 +882,7 @@ static INT PROFILE_GetSection( PROFILESECTION *section, LPCWSTR section_name,
|
||||||
if (len <= 2) break;
|
if (len <= 2) break;
|
||||||
if (!*key->name) continue; /* Skip empty lines */
|
if (!*key->name) continue; /* Skip empty lines */
|
||||||
if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
|
if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
|
||||||
if (!return_noequalkeys && !return_values && !key->value) continue; /* Skip lines w.o. '=' */
|
if (!return_values && !key->value) continue; /* Skip lines w.o. '=' */
|
||||||
PROFILE_CopyEntry( buffer, key->name, len - 1, 0 );
|
PROFILE_CopyEntry( buffer, key->name, len - 1, 0 );
|
||||||
len -= strlenW(buffer) + 1;
|
len -= strlenW(buffer) + 1;
|
||||||
buffer += strlenW(buffer) + 1;
|
buffer += strlenW(buffer) + 1;
|
||||||
|
@ -980,7 +979,7 @@ static INT PROFILE_GetSectionNames( LPWSTR buffer, UINT len )
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
|
static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
|
||||||
LPCWSTR def_val, LPWSTR buffer, UINT len, BOOL win32 )
|
LPCWSTR def_val, LPWSTR buffer, UINT len )
|
||||||
{
|
{
|
||||||
PROFILEKEY *key = NULL;
|
PROFILEKEY *key = NULL;
|
||||||
static const WCHAR empty_strW[] = { 0 };
|
static const WCHAR empty_strW[] = { 0 };
|
||||||
|
@ -1006,7 +1005,7 @@ static INT PROFILE_GetString( LPCWSTR section, LPCWSTR key_name,
|
||||||
/* no "else" here ! */
|
/* no "else" here ! */
|
||||||
if (section && section[0])
|
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);
|
||||||
if (!buffer[0]) /* no luck -> def_val */
|
if (!buffer[0]) /* no luck -> def_val */
|
||||||
{
|
{
|
||||||
PROFILE_CopyEntry(buffer, def_val, len, TRUE);
|
PROFILE_CopyEntry(buffer, def_val, len, TRUE);
|
||||||
|
@ -1092,16 +1091,12 @@ UINT WINAPI GetProfileIntW( LPCWSTR section, LPCWSTR entry, INT def_val )
|
||||||
return GetPrivateProfileIntW( section, entry, def_val, wininiW );
|
return GetPrivateProfileIntW( section, entry, def_val, wininiW );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/***********************************************************************
|
||||||
* if win32, copy:
|
* GetPrivateProfileStringW (KERNEL32.@)
|
||||||
* - Section names if 'section' is NULL
|
|
||||||
* - Keys in a Section if 'entry' is NULL
|
|
||||||
* (see MSDN doc for GetPrivateProfileString)
|
|
||||||
*/
|
*/
|
||||||
static int PROFILE_GetPrivateProfileString( LPCWSTR section, LPCWSTR entry,
|
INT WINAPI GetPrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
|
||||||
LPCWSTR def_val, LPWSTR buffer,
|
LPCWSTR def_val, LPWSTR buffer,
|
||||||
UINT len, LPCWSTR filename,
|
UINT len, LPCWSTR filename )
|
||||||
BOOL win32 )
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
LPWSTR defval_tmp = NULL;
|
LPWSTR defval_tmp = NULL;
|
||||||
|
@ -1131,11 +1126,11 @@ static int PROFILE_GetPrivateProfileString( LPCWSTR section, LPCWSTR entry,
|
||||||
RtlEnterCriticalSection( &PROFILE_CritSect );
|
RtlEnterCriticalSection( &PROFILE_CritSect );
|
||||||
|
|
||||||
if (PROFILE_Open( filename, FALSE )) {
|
if (PROFILE_Open( filename, FALSE )) {
|
||||||
if (win32 && (section == NULL))
|
if (section == NULL)
|
||||||
ret = PROFILE_GetSectionNames(buffer, len);
|
ret = PROFILE_GetSectionNames(buffer, len);
|
||||||
else
|
else
|
||||||
/* PROFILE_GetString can handle the 'entry == NULL' case */
|
/* PROFILE_GetString can handle the 'entry == NULL' case */
|
||||||
ret = PROFILE_GetString( section, entry, def_val, buffer, len, win32 );
|
ret = PROFILE_GetString( section, entry, def_val, buffer, len );
|
||||||
} else if (buffer && def_val) {
|
} else if (buffer && def_val) {
|
||||||
lstrcpynW( buffer, def_val, len );
|
lstrcpynW( buffer, def_val, len );
|
||||||
ret = strlenW( buffer );
|
ret = strlenW( buffer );
|
||||||
|
@ -1152,50 +1147,6 @@ static int PROFILE_GetPrivateProfileString( LPCWSTR section, LPCWSTR entry,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* GetPrivateProfileString (KERNEL.128)
|
|
||||||
*/
|
|
||||||
INT16 WINAPI GetPrivateProfileString16( LPCSTR section, LPCSTR entry,
|
|
||||||
LPCSTR def_val, LPSTR buffer,
|
|
||||||
UINT16 len, LPCSTR filename )
|
|
||||||
{
|
|
||||||
UNICODE_STRING sectionW, entryW, def_valW, filenameW;
|
|
||||||
LPWSTR bufferW;
|
|
||||||
INT16 retW, ret = 0;
|
|
||||||
|
|
||||||
bufferW = buffer ? HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)) : NULL;
|
|
||||||
if (section) RtlCreateUnicodeStringFromAsciiz(§ionW, section);
|
|
||||||
else sectionW.Buffer = NULL;
|
|
||||||
if (entry) RtlCreateUnicodeStringFromAsciiz(&entryW, entry);
|
|
||||||
else entryW.Buffer = NULL;
|
|
||||||
if (def_val) RtlCreateUnicodeStringFromAsciiz(&def_valW, def_val);
|
|
||||||
else def_valW.Buffer = NULL;
|
|
||||||
if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
|
|
||||||
else filenameW.Buffer = NULL;
|
|
||||||
|
|
||||||
retW = PROFILE_GetPrivateProfileString( sectionW.Buffer, entryW.Buffer,
|
|
||||||
def_valW.Buffer, bufferW, len,
|
|
||||||
filenameW.Buffer, FALSE );
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 1, buffer, len, NULL, NULL);
|
|
||||||
if (!ret)
|
|
||||||
{
|
|
||||||
ret = len - 1;
|
|
||||||
buffer[ret] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ret--; /* strip terminating 0 */
|
|
||||||
}
|
|
||||||
|
|
||||||
RtlFreeUnicodeString(§ionW);
|
|
||||||
RtlFreeUnicodeString(&entryW);
|
|
||||||
RtlFreeUnicodeString(&def_valW);
|
|
||||||
RtlFreeUnicodeString(&filenameW);
|
|
||||||
HeapFree(GetProcessHeap(), 0, bufferW);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* GetPrivateProfileStringA (KERNEL32.@)
|
* GetPrivateProfileStringA (KERNEL32.@)
|
||||||
*/
|
*/
|
||||||
|
@ -1240,19 +1191,6 @@ INT WINAPI GetPrivateProfileStringA( LPCSTR section, LPCSTR entry,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* GetPrivateProfileStringW (KERNEL32.@)
|
|
||||||
*/
|
|
||||||
INT WINAPI GetPrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
|
|
||||||
LPCWSTR def_val, LPWSTR buffer,
|
|
||||||
UINT len, LPCWSTR filename )
|
|
||||||
{
|
|
||||||
TRACE("(%s, %s, %s, %p, %d, %s)\n", debugstr_w(section), debugstr_w(entry), debugstr_w(def_val), buffer, len, debugstr_w(filename));
|
|
||||||
|
|
||||||
return PROFILE_GetPrivateProfileString( section, entry, def_val,
|
|
||||||
buffer, len, filename, TRUE );
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* GetProfileStringA (KERNEL32.@)
|
* GetProfileStringA (KERNEL32.@)
|
||||||
*/
|
*/
|
||||||
|
@ -1363,7 +1301,7 @@ INT WINAPI GetPrivateProfileSectionW( LPCWSTR section, LPWSTR buffer,
|
||||||
RtlEnterCriticalSection( &PROFILE_CritSect );
|
RtlEnterCriticalSection( &PROFILE_CritSect );
|
||||||
|
|
||||||
if (PROFILE_Open( filename, FALSE ))
|
if (PROFILE_Open( filename, FALSE ))
|
||||||
ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, TRUE, FALSE);
|
ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, TRUE);
|
||||||
|
|
||||||
RtlLeaveCriticalSection( &PROFILE_CritSect );
|
RtlLeaveCriticalSection( &PROFILE_CritSect );
|
||||||
|
|
||||||
|
@ -1846,16 +1784,6 @@ BOOL WINAPI WritePrivateProfileStructA (LPCSTR section, LPCSTR key,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* WriteOutProfiles (KERNEL.315)
|
|
||||||
*/
|
|
||||||
void WINAPI WriteOutProfiles16(void)
|
|
||||||
{
|
|
||||||
RtlEnterCriticalSection( &PROFILE_CritSect );
|
|
||||||
PROFILE_FlushFile();
|
|
||||||
RtlLeaveCriticalSection( &PROFILE_CritSect );
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* OpenProfileUserMapping (KERNEL32.@)
|
* OpenProfileUserMapping (KERNEL32.@)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue