Support Large Profile Values
Robert Shearman
rob at codeweavers.com
Mon Jul 12 05:03:10 CDT 2004
Hi,
This patch removes the limit of 1024 characters for lines in profiles
(.ini files). It replaces it by a suggestion of 1024 characters that can
be dynamically increased if necessary. This patch depends on my previous
snprintfW change.
Rob
Changelog:
Support large profile values.
-------------- next part --------------
Index: wine/dlls/kernel/profile.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/profile.c,v
retrieving revision 1.12
diff -u -r1.12 profile.c
--- wine/dlls/kernel/profile.c 14 Jun 2004 17:04:35 -0000 1.12
+++ wine/dlls/kernel/profile.c 9 Jul 2004 16:42:57 -0000
@@ -81,7 +81,7 @@
#define CurProfile (MRUProfile[0])
-#define PROFILE_MAX_LINE_LEN 1024
+#define PROFILE_DEFAULT_LINE_LEN 1024
/* Check for comments in profile */
#define IS_ENTRY_COMMENT(str) ((str)[0] == ';')
@@ -156,7 +156,8 @@
static void PROFILE_WriteLine( HANDLE hFile, WCHAR * szLine, int len, ENCODING encoding)
{
- char write_buffer[PROFILE_MAX_LINE_LEN];
+ char * write_buffer;
+ int write_buffer_len;
DWORD dwBytesWritten;
TRACE("writing: %s\n", debugstr_wn(szLine, len));
@@ -164,12 +165,20 @@
switch (encoding)
{
case ENCODING_ANSI:
- len = WideCharToMultiByte(CP_ACP, 0, szLine, len, write_buffer, sizeof(write_buffer), NULL, NULL);
- WriteFile(hFile, write_buffer, len * sizeof(char), &dwBytesWritten, NULL);
+ write_buffer_len = WideCharToMultiByte(CP_ACP, 0, szLine, len, NULL, 0, NULL, NULL);
+ write_buffer = HeapAlloc(GetProcessHeap(), 0, write_buffer_len);
+ if (!write_buffer) return;
+ len = WideCharToMultiByte(CP_ACP, 0, szLine, len, write_buffer, write_buffer_len, NULL, NULL);
+ WriteFile(hFile, write_buffer, len, &dwBytesWritten, NULL);
+ HeapFree(GetProcessHeap(), 0, write_buffer);
break;
case ENCODING_UTF8:
- len = WideCharToMultiByte(CP_UTF8, 0, szLine, len, write_buffer, sizeof(write_buffer), NULL, NULL);
- WriteFile(hFile, write_buffer, len * sizeof(char), &dwBytesWritten, NULL);
+ write_buffer_len = WideCharToMultiByte(CP_ACP, 0, szLine, len, NULL, 0, NULL, NULL);
+ write_buffer = HeapAlloc(GetProcessHeap(), 0, write_buffer_len);
+ if (!write_buffer) return;
+ len = WideCharToMultiByte(CP_UTF8, 0, szLine, len, write_buffer, write_buffer_len, NULL, NULL);
+ WriteFile(hFile, write_buffer, len, &dwBytesWritten, NULL);
+ HeapFree(GetProcessHeap(), 0, write_buffer);
break;
case ENCODING_UTF16LE:
WriteFile(hFile, szLine, len * sizeof(WCHAR), &dwBytesWritten, NULL);
@@ -195,30 +204,54 @@
static const WCHAR wValueFormat[] = {'=','%','s',0};
static const WCHAR wNewLine[] = {'\r','\n',0};
PROFILEKEY *key;
- WCHAR szLine[PROFILE_MAX_LINE_LEN];
+ int cchLine = PROFILE_DEFAULT_LINE_LEN;
+ WCHAR * szLine = HeapAlloc(GetProcessHeap(), 0, (cchLine+1)*sizeof(WCHAR));
int len = 0;
-
+
+ if (!szLine) return;
+
PROFILE_WriteMarker(hFile, encoding);
for ( ; section; section = section->next)
{
if (section->name[0])
{
- len += snprintfW( szLine + len, PROFILE_MAX_LINE_LEN - len, wSectionFormat, section->name );
+ do
+ {
+ if (len > cchLine)
+ {
+ szLine = HeapReAlloc(GetProcessHeap(), 0, szLine, (len+1)*sizeof(WCHAR));
+ if (!szLine) return;
+ cchLine = len;
+ len = 0;
+ }
+ len += snprintfW( szLine + len, cchLine - len, wSectionFormat, section->name );
+ } while (len > cchLine);
PROFILE_WriteLine( hFile, szLine, len, encoding );
len = 0;
}
for (key = section->key; key; key = key->next)
{
- len += snprintfW( szLine + len, PROFILE_MAX_LINE_LEN - len, wNameFormat, key->name );
- if (key->value)
- len += snprintfW( szLine + len, PROFILE_MAX_LINE_LEN - len, wValueFormat, key->value );
- len += snprintfW( szLine + len, PROFILE_MAX_LINE_LEN - len, wNewLine );
+ do
+ {
+ if (len > cchLine)
+ {
+ szLine = HeapReAlloc(GetProcessHeap(), 0, szLine, (len+1)*sizeof(WCHAR));
+ if (!szLine) return;
+ cchLine = len;
+ len = 0;
+ }
+ len += snprintfW( szLine + len, cchLine - len, wNameFormat, key->name );
+ if (key->value)
+ len += snprintfW( szLine + len, cchLine - len, wValueFormat, key->value );
+ len += snprintfW( szLine + len, cchLine - len, wNewLine );
+ } while (len > cchLine);
PROFILE_WriteLine( hFile, szLine, len, encoding );
len = 0;
}
}
+ HeapFree(GetProcessHeap(), 0, szLine);
}
More information about the wine-patches
mailing list