Anything wrong here? ----- Weitergeleitete Nachricht von Stefan Leichter <Stefan.Leichter@camLine.com> ----- Datum: Mon, 17 Mar 2003 09:21:32 +0100 Von: Stefan Leichter <Stefan.Leichter@camLine.com> Antwort an: Stefan Leichter <Stefan.Leichter@camLine.com> Betreff: Get rid of W->A calls: GetPrivateProfileIntA/W An: wine-patches@winehq.com Changelog ------------ moved implementation of GetPrivateProfileInt from ascii to unicode ----- Ende der weitergeleiteten Nachricht -----
--- ../wine/files/profile.c Tue Mar 4 21:56:10 2003 +++ files/profile.c Sun Mar 16 20:49:25 2003 @@ -87,6 +87,7 @@ /* Check for comments in profile */ #define IS_ENTRY_COMMENT(str) ((str)[0] == ';') +static const WCHAR emptystringW[] = {0}; static const WCHAR wininiW[] = { 'w','i','n','.','i','n','i',0 }; static CRITICAL_SECTION PROFILE_CritSect = CRITICAL_SECTION_INIT("PROFILE_CritSect"); @@ -1294,59 +1295,65 @@ } /*********************************************************************** - * GetPrivateProfileIntA (KERNEL32.@) + * GetPrivateProfileIntW (KERNEL32.@) */ -UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry, - INT def_val, LPCSTR filename ) +UINT WINAPI GetPrivateProfileIntW( LPCWSTR section, LPCWSTR entry, + INT def_val, LPCWSTR filename ) { - char buffer[20]; - UINT result = 0; - char *p = buffer; - int negative = 0; - - if (!GetPrivateProfileStringA( section, entry, "", - buffer, sizeof(buffer), filename )) - return def_val; +#define GETPROFILEINTBUFSIZE 30 + UNICODE_STRING bufferW; + DWORD len; + long result; + if(!filename) return 0; + if(!section || !entry) return def_val; + bufferW.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, GETPROFILEINTBUFSIZE ); + bufferW.MaximumLength = GETPROFILEINTBUFSIZE; + bufferW.Length = GETPROFILEINTBUFSIZE - sizeof(WCHAR); + + if (!(len = GetPrivateProfileStringW(section, entry, emptystringW, + bufferW.Buffer, GETPROFILEINTBUFSIZE / sizeof(WCHAR), + filename ))) { + result = def_val; + goto end; + } + if (len+1 == GETPROFILEINTBUFSIZE) FIXME("result may be wrong!"); /* FIXME: if entry can be found but it's empty, then Win16 is * supposed to return 0 instead of def_val ! Difficult/problematic * to implement (every other failure also returns zero buffer), * thus wait until testing framework avail for making sure nothing * else gets broken that way. */ - if (!buffer[0]) return (UINT)def_val; - - /* do the conversion by hand to make sure - * overflow is *not* handled properly ;-) */ - while (*p && isspace(*p)) p++; - if (*p == '-') - { - negative = 1; - p++; + if (!bufferW.Buffer[0]) { + result = def_val; + goto end; } - else if (*p == '+') p++; - while (*p && isdigit(*p)) - { - result = result * 10 + *p - '0'; - p++; - } - return negative ? (UINT)-result : result; + RtlUnicodeStringToInteger( &bufferW, 10, &result); +end: + RtlFreeUnicodeString(&bufferW); + return (UINT)result; } /*********************************************************************** - * GetPrivateProfileIntW (KERNEL32.@) + * GetPrivateProfileIntA (KERNEL32.@) * * FIXME: rewrite using unicode */ -UINT WINAPI GetPrivateProfileIntW( LPCWSTR section, LPCWSTR entry, - INT def_val, LPCWSTR filename ) +UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry, + INT def_val, LPCSTR filename ) { - LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section ); - LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry ); - LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); - UINT res = GetPrivateProfileIntA(sectionA, entryA, def_val, filenameA); - HeapFree( GetProcessHeap(), 0, sectionA ); - HeapFree( GetProcessHeap(), 0, filenameA ); - HeapFree( GetProcessHeap(), 0, entryA ); + UNICODE_STRING entryW, filenameW, sectionW; + UINT res; + if(entry) RtlCreateUnicodeStringFromAsciiz(&entryW, entry); + else entryW.Buffer = NULL; + if(filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename); + else filenameW.Buffer = NULL; + if(section) RtlCreateUnicodeStringFromAsciiz(§ionW, section); + else sectionW.Buffer = NULL; + res = GetPrivateProfileIntW(sectionW.Buffer, entryW.Buffer, def_val, + filenameW.Buffer); + RtlFreeUnicodeString(§ionW); + RtlFreeUnicodeString(&filenameW); + RtlFreeUnicodeString(&entryW); return res; }