Moved implementation of GetPrivateProfileInt from ascii to unicode.

This commit is contained in:
Stefan Leichter 2003-03-23 20:03:13 +00:00 committed by Alexandre Julliard
parent e048adab83
commit b56950864b
1 changed files with 33 additions and 35 deletions

View File

@ -87,6 +87,7 @@ static PROFILE *MRUProfile[N_CACHED_PROFILES]={NULL};
/* Check for comments in profile */ /* Check for comments in profile */
#define IS_ENTRY_COMMENT(str) ((str)[0] == ';') #define IS_ENTRY_COMMENT(str) ((str)[0] == ';')
static const WCHAR emptystringW[] = {0};
static const WCHAR wininiW[] = { 'w','i','n','.','i','n','i',0 }; static const WCHAR wininiW[] = { 'w','i','n','.','i','n','i',0 };
static CRITICAL_SECTION PROFILE_CritSect = CRITICAL_SECTION_INIT("PROFILE_CritSect"); static CRITICAL_SECTION PROFILE_CritSect = CRITICAL_SECTION_INIT("PROFILE_CritSect");
@ -1293,19 +1294,23 @@ UINT16 WINAPI GetPrivateProfileInt16( LPCSTR section, LPCSTR entry,
} }
/*********************************************************************** /***********************************************************************
* GetPrivateProfileIntA (KERNEL32.@) * GetPrivateProfileIntW (KERNEL32.@)
*/ */
UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry, UINT WINAPI GetPrivateProfileIntW( LPCWSTR section, LPCWSTR entry,
INT def_val, LPCSTR filename ) INT def_val, LPCWSTR filename )
{ {
char buffer[20]; WCHAR buffer[30];
UINT result = 0; UNICODE_STRING bufferW;
char *p = buffer; INT len;
int negative = 0; ULONG result;
if (!GetPrivateProfileStringA( section, entry, "", if (!(len = GetPrivateProfileStringW( section, entry, emptystringW,
buffer, sizeof(buffer), filename )) buffer, sizeof(buffer)/sizeof(WCHAR),
filename )))
return def_val; return def_val;
if (len+1 == sizeof(buffer)/sizeof(WCHAR)) FIXME("result may be wrong!");
/* FIXME: if entry can be found but it's empty, then Win16 is /* FIXME: if entry can be found but it's empty, then Win16 is
* supposed to return 0 instead of def_val ! Difficult/problematic * supposed to return 0 instead of def_val ! Difficult/problematic
* to implement (every other failure also returns zero buffer), * to implement (every other failure also returns zero buffer),
@ -1313,39 +1318,32 @@ UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry,
* else gets broken that way. */ * else gets broken that way. */
if (!buffer[0]) return (UINT)def_val; if (!buffer[0]) return (UINT)def_val;
/* do the conversion by hand to make sure RtlInitUnicodeString( &bufferW, buffer );
* overflow is *not* handled properly ;-) */ RtlUnicodeStringToInteger( &bufferW, 10, &result);
while (*p && isspace(*p)) p++; return result;
if (*p == '-')
{
negative = 1;
p++;
}
else if (*p == '+') p++;
while (*p && isdigit(*p))
{
result = result * 10 + *p - '0';
p++;
}
return negative ? (UINT)-result : result;
} }
/*********************************************************************** /***********************************************************************
* GetPrivateProfileIntW (KERNEL32.@) * GetPrivateProfileIntA (KERNEL32.@)
* *
* FIXME: rewrite using unicode * FIXME: rewrite using unicode
*/ */
UINT WINAPI GetPrivateProfileIntW( LPCWSTR section, LPCWSTR entry, UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry,
INT def_val, LPCWSTR filename ) INT def_val, LPCSTR filename )
{ {
LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); UNICODE_STRING entryW, filenameW, sectionW;
LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry ); UINT res;
LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); if(entry) RtlCreateUnicodeStringFromAsciiz(&entryW, entry);
UINT res = GetPrivateProfileIntA(sectionA, entryA, def_val, filenameA); else entryW.Buffer = NULL;
HeapFree( GetProcessHeap(), 0, sectionA ); if(filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
HeapFree( GetProcessHeap(), 0, filenameA ); else filenameW.Buffer = NULL;
HeapFree( GetProcessHeap(), 0, entryA ); if(section) RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
else sectionW.Buffer = NULL;
res = GetPrivateProfileIntW(sectionW.Buffer, entryW.Buffer, def_val,
filenameW.Buffer);
RtlFreeUnicodeString(&sectionW);
RtlFreeUnicodeString(&filenameW);
RtlFreeUnicodeString(&entryW);
return res; return res;
} }