wow64: In wow64_NtSetInformationToken forward TokenIntegrityLevel.
[wine.git] / dlls / kernel32 / profile.c
blobf65790ecc92290ffb000a07d215d8b06f59f7aae
1 /*
2 * Profile functions
4 * Copyright 1993 Miguel de Icaza
5 * Copyright 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <string.h>
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "winerror.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "shlwapi.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(profile);
36 static const char bom_utf8[] = {0xEF,0xBB,0xBF};
38 typedef enum
40 ENCODING_ANSI = 1,
41 ENCODING_UTF8,
42 ENCODING_UTF16LE,
43 ENCODING_UTF16BE
44 } ENCODING;
46 typedef struct tagPROFILEKEY
48 WCHAR *value;
49 struct tagPROFILEKEY *next;
50 WCHAR name[1];
51 } PROFILEKEY;
53 typedef struct tagPROFILESECTION
55 struct tagPROFILEKEY *key;
56 struct tagPROFILESECTION *next;
57 WCHAR name[1];
58 } PROFILESECTION;
61 typedef struct
63 BOOL changed;
64 PROFILESECTION *section;
65 WCHAR *filename;
66 FILETIME LastWriteTime;
67 ENCODING encoding;
68 } PROFILE;
71 #define N_CACHED_PROFILES 10
73 /* Cached profile files */
74 static PROFILE *MRUProfile[N_CACHED_PROFILES]={NULL};
76 #define CurProfile (MRUProfile[0])
78 /* Check for comments in profile */
79 #define IS_ENTRY_COMMENT(str) ((str)[0] == ';')
81 static CRITICAL_SECTION PROFILE_CritSect;
82 static CRITICAL_SECTION_DEBUG critsect_debug =
84 0, 0, &PROFILE_CritSect,
85 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
86 0, 0, { (DWORD_PTR)(__FILE__ ": PROFILE_CritSect") }
88 static CRITICAL_SECTION PROFILE_CritSect = { &critsect_debug, -1, 0, 0, 0, 0 };
90 static const char hex[16] = "0123456789ABCDEF";
92 /***********************************************************************
93 * PROFILE_CopyEntry
95 * Copy the content of an entry into a buffer, removing quotes, and possibly
96 * translating environment variables.
98 static void PROFILE_CopyEntry( LPWSTR buffer, LPCWSTR value, int len )
100 WCHAR quote = '\0';
102 if(!buffer) return;
104 if (*value == '\'' || *value == '\"')
106 if (value[1] && (value[lstrlenW(value)-1] == *value)) quote = *value++;
109 lstrcpynW( buffer, value, len );
110 if (quote && (len >= lstrlenW(value))) buffer[lstrlenW(buffer)-1] = '\0';
113 /* byte-swaps shorts in-place in a buffer. len is in WCHARs */
114 static inline void PROFILE_ByteSwapShortBuffer(WCHAR * buffer, int len)
116 int i;
117 USHORT * shortbuffer = buffer;
118 for (i = 0; i < len; i++)
119 shortbuffer[i] = RtlUshortByteSwap(shortbuffer[i]);
122 /* writes any necessary encoding marker to the file */
123 static inline void PROFILE_WriteMarker(HANDLE hFile, ENCODING encoding)
125 DWORD dwBytesWritten;
126 WCHAR bom;
127 switch (encoding)
129 case ENCODING_ANSI:
130 break;
131 case ENCODING_UTF8:
132 WriteFile(hFile, bom_utf8, sizeof(bom_utf8), &dwBytesWritten, NULL);
133 break;
134 case ENCODING_UTF16LE:
135 bom = 0xFEFF;
136 WriteFile(hFile, &bom, sizeof(bom), &dwBytesWritten, NULL);
137 break;
138 case ENCODING_UTF16BE:
139 bom = 0xFFFE;
140 WriteFile(hFile, &bom, sizeof(bom), &dwBytesWritten, NULL);
141 break;
145 static void PROFILE_WriteLine( HANDLE hFile, WCHAR * szLine, int len, ENCODING encoding)
147 char * write_buffer;
148 int write_buffer_len;
149 DWORD dwBytesWritten;
151 TRACE("writing: %s\n", debugstr_wn(szLine, len));
153 switch (encoding)
155 case ENCODING_ANSI:
156 write_buffer_len = WideCharToMultiByte(CP_ACP, 0, szLine, len, NULL, 0, NULL, NULL);
157 write_buffer = HeapAlloc(GetProcessHeap(), 0, write_buffer_len);
158 if (!write_buffer) return;
159 len = WideCharToMultiByte(CP_ACP, 0, szLine, len, write_buffer, write_buffer_len, NULL, NULL);
160 WriteFile(hFile, write_buffer, len, &dwBytesWritten, NULL);
161 HeapFree(GetProcessHeap(), 0, write_buffer);
162 break;
163 case ENCODING_UTF8:
164 write_buffer_len = WideCharToMultiByte(CP_UTF8, 0, szLine, len, NULL, 0, NULL, NULL);
165 write_buffer = HeapAlloc(GetProcessHeap(), 0, write_buffer_len);
166 if (!write_buffer) return;
167 len = WideCharToMultiByte(CP_UTF8, 0, szLine, len, write_buffer, write_buffer_len, NULL, NULL);
168 WriteFile(hFile, write_buffer, len, &dwBytesWritten, NULL);
169 HeapFree(GetProcessHeap(), 0, write_buffer);
170 break;
171 case ENCODING_UTF16LE:
172 WriteFile(hFile, szLine, len * sizeof(WCHAR), &dwBytesWritten, NULL);
173 break;
174 case ENCODING_UTF16BE:
175 PROFILE_ByteSwapShortBuffer(szLine, len);
176 WriteFile(hFile, szLine, len * sizeof(WCHAR), &dwBytesWritten, NULL);
177 break;
178 default:
179 FIXME("encoding type %d not implemented\n", encoding);
183 /***********************************************************************
184 * PROFILE_Save
186 * Save a profile tree to a file.
188 static void PROFILE_Save( HANDLE hFile, const PROFILESECTION *section, ENCODING encoding )
190 PROFILEKEY *key;
191 WCHAR *buffer, *p;
193 PROFILE_WriteMarker(hFile, encoding);
195 for ( ; section; section = section->next)
197 int len = 0;
199 if (section->name[0]) len += lstrlenW(section->name) + 4;
201 for (key = section->key; key; key = key->next)
203 len += lstrlenW(key->name) + 2;
204 if (key->value) len += lstrlenW(key->value) + 1;
207 buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
208 if (!buffer) return;
210 p = buffer;
211 if (section->name[0])
213 *p++ = '[';
214 lstrcpyW( p, section->name );
215 p += lstrlenW(p);
216 *p++ = ']';
217 *p++ = '\r';
218 *p++ = '\n';
221 for (key = section->key; key; key = key->next)
223 lstrcpyW( p, key->name );
224 p += lstrlenW(p);
225 if (key->value)
227 *p++ = '=';
228 lstrcpyW( p, key->value );
229 p += lstrlenW(p);
231 *p++ = '\r';
232 *p++ = '\n';
234 PROFILE_WriteLine( hFile, buffer, len, encoding );
235 HeapFree(GetProcessHeap(), 0, buffer);
240 /***********************************************************************
241 * PROFILE_Free
243 * Free a profile tree.
245 static void PROFILE_Free( PROFILESECTION *section )
247 PROFILESECTION *next_section;
248 PROFILEKEY *key, *next_key;
250 for ( ; section; section = next_section)
252 for (key = section->key; key; key = next_key)
254 next_key = key->next;
255 HeapFree( GetProcessHeap(), 0, key->value );
256 HeapFree( GetProcessHeap(), 0, key );
258 next_section = section->next;
259 HeapFree( GetProcessHeap(), 0, section );
263 /* returns TRUE if a whitespace character, else FALSE */
264 static inline BOOL PROFILE_isspaceW(WCHAR c)
266 /* ^Z (DOS EOF) is a space too (found on CD-ROMs) */
267 return (c >= 0x09 && c <= 0x0d) || c == 0x1a || c == 0x20;
270 static inline ENCODING PROFILE_DetectTextEncoding(const void * buffer, int * len)
272 int flags = IS_TEXT_UNICODE_SIGNATURE |
273 IS_TEXT_UNICODE_REVERSE_SIGNATURE |
274 IS_TEXT_UNICODE_ODD_LENGTH;
275 if (*len >= sizeof(bom_utf8) && !memcmp(buffer, bom_utf8, sizeof(bom_utf8)))
277 *len = sizeof(bom_utf8);
278 return ENCODING_UTF8;
280 RtlIsTextUnicode(buffer, *len, &flags);
281 if (flags & IS_TEXT_UNICODE_SIGNATURE)
283 *len = sizeof(WCHAR);
284 return ENCODING_UTF16LE;
286 if (flags & IS_TEXT_UNICODE_REVERSE_SIGNATURE)
288 *len = sizeof(WCHAR);
289 return ENCODING_UTF16BE;
291 *len = 0;
292 return ENCODING_ANSI;
295 static void profile_trim_spaces(WCHAR **start, WCHAR **end)
297 WCHAR *s = *start, *e = *end;
299 while (s < e && PROFILE_isspaceW(*s)) s++;
300 while ((e > s) && PROFILE_isspaceW(e[-1])) e--;
302 *start = s;
303 *end = e;
306 /***********************************************************************
307 * PROFILE_Load
309 * Load a profile tree from a file.
311 static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
313 void *buffer_base, *pBuffer;
314 WCHAR * szFile;
315 WCHAR *szLineStart, *szLineEnd, *next_line;
316 const WCHAR *szValueStart, *szEnd;
317 int len;
318 PROFILESECTION *section, *first_section;
319 PROFILESECTION **next_section;
320 PROFILEKEY *key, *prev_key, **next_key;
321 DWORD dwFileSize;
323 TRACE("%p\n", hFile);
325 dwFileSize = GetFileSize(hFile, NULL);
326 if (dwFileSize == INVALID_FILE_SIZE || dwFileSize == 0)
327 return NULL;
329 buffer_base = HeapAlloc(GetProcessHeap(), 0 , dwFileSize);
330 if (!buffer_base) return NULL;
332 if (!ReadFile(hFile, buffer_base, dwFileSize, &dwFileSize, NULL))
334 HeapFree(GetProcessHeap(), 0, buffer_base);
335 WARN("Error %ld reading file\n", GetLastError());
336 return NULL;
338 len = dwFileSize;
339 *pEncoding = PROFILE_DetectTextEncoding(buffer_base, &len);
340 /* len is set to the number of bytes in the character marker.
341 * we want to skip these bytes */
342 pBuffer = (char *)buffer_base + len;
343 dwFileSize -= len;
344 switch (*pEncoding)
346 case ENCODING_ANSI:
347 TRACE("ANSI encoding\n");
349 len = MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, NULL, 0);
350 szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
351 if (!szFile)
353 HeapFree(GetProcessHeap(), 0, buffer_base);
354 return NULL;
356 MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, szFile, len);
357 szEnd = szFile + len;
358 break;
359 case ENCODING_UTF8:
360 TRACE("UTF8 encoding\n");
362 len = MultiByteToWideChar(CP_UTF8, 0, pBuffer, dwFileSize, NULL, 0);
363 szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
364 if (!szFile)
366 HeapFree(GetProcessHeap(), 0, buffer_base);
367 return NULL;
369 MultiByteToWideChar(CP_UTF8, 0, pBuffer, dwFileSize, szFile, len);
370 szEnd = szFile + len;
371 break;
372 case ENCODING_UTF16LE:
373 TRACE("UTF16 Little Endian encoding\n");
374 szFile = pBuffer;
375 szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
376 break;
377 case ENCODING_UTF16BE:
378 TRACE("UTF16 Big Endian encoding\n");
379 szFile = pBuffer;
380 szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
381 PROFILE_ByteSwapShortBuffer(szFile, dwFileSize / sizeof(WCHAR));
382 break;
383 default:
384 FIXME("encoding type %d not implemented\n", *pEncoding);
385 HeapFree(GetProcessHeap(), 0, buffer_base);
386 return NULL;
389 first_section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) );
390 if(first_section == NULL)
392 if (szFile != pBuffer)
393 HeapFree(GetProcessHeap(), 0, szFile);
394 HeapFree(GetProcessHeap(), 0, buffer_base);
395 return NULL;
397 first_section->name[0] = 0;
398 first_section->key = NULL;
399 first_section->next = NULL;
400 next_section = &first_section->next;
401 next_key = &first_section->key;
402 prev_key = NULL;
403 next_line = szFile;
405 while (next_line < szEnd)
407 szLineStart = next_line;
408 while (next_line < szEnd && *next_line != '\n' && *next_line != '\r') next_line++;
409 while (next_line < szEnd && (*next_line == '\n' || *next_line == '\r')) next_line++;
410 szLineEnd = next_line;
412 /* get rid of white space */
413 profile_trim_spaces(&szLineStart, &szLineEnd);
415 if (szLineStart >= szLineEnd) continue;
417 if (*szLineStart == '[') /* section start */
419 for (len = szLineEnd - szLineStart; len > 0; len--) if (szLineStart[len - 1] == ']') break;
420 if (!len)
422 WARN("Invalid section header: %s\n",
423 debugstr_wn(szLineStart, (int)(szLineEnd - szLineStart)) );
425 else
427 /* Skip brackets */
428 szLineStart++;
429 len -= 2;
430 szLineEnd = szLineStart + len;
431 profile_trim_spaces(&szLineStart, &szLineEnd);
432 len = szLineEnd - szLineStart;
434 /* no need to allocate +1 for NULL terminating character as
435 * already included in structure */
436 if (!(section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) + len * sizeof(WCHAR) )))
437 break;
438 memcpy(section->name, szLineStart, len * sizeof(WCHAR));
439 section->name[len] = '\0';
440 section->key = NULL;
441 section->next = NULL;
442 *next_section = section;
443 next_section = &section->next;
444 next_key = &section->key;
445 prev_key = NULL;
447 TRACE("New section: %s\n", debugstr_w(section->name));
449 continue;
453 /* get rid of white space after the name and before the start
454 * of the value */
455 len = szLineEnd - szLineStart;
456 for (szValueStart = szLineStart; szValueStart < szLineEnd; szValueStart++) if (*szValueStart == '=') break;
457 if (szValueStart < szLineEnd)
459 const WCHAR *szNameEnd = szValueStart;
460 while ((szNameEnd > szLineStart) && PROFILE_isspaceW(szNameEnd[-1])) szNameEnd--;
461 len = szNameEnd - szLineStart;
462 szValueStart++;
463 while (szValueStart < szLineEnd && PROFILE_isspaceW(*szValueStart)) szValueStart++;
465 else szValueStart = NULL;
467 if (len || !prev_key || *prev_key->name)
469 /* no need to allocate +1 for NULL terminating character as
470 * already included in structure */
471 if (!(key = HeapAlloc( GetProcessHeap(), 0, sizeof(*key) + len * sizeof(WCHAR) ))) break;
472 memcpy(key->name, szLineStart, len * sizeof(WCHAR));
473 key->name[len] = '\0';
474 if (szValueStart)
476 len = (int)(szLineEnd - szValueStart);
477 key->value = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
478 memcpy(key->value, szValueStart, len * sizeof(WCHAR));
479 key->value[len] = '\0';
481 else key->value = NULL;
483 key->next = NULL;
484 *next_key = key;
485 next_key = &key->next;
486 prev_key = key;
488 TRACE("New key: name=%s, value=%s\n",
489 debugstr_w(key->name), key->value ? debugstr_w(key->value) : "(none)");
492 if (szFile != pBuffer)
493 HeapFree(GetProcessHeap(), 0, szFile);
494 HeapFree(GetProcessHeap(), 0, buffer_base);
495 return first_section;
499 /***********************************************************************
500 * PROFILE_DeleteKey
502 * Delete a key from a profile tree.
504 static BOOL PROFILE_DeleteKey( PROFILESECTION **section,
505 LPCWSTR section_name, LPCWSTR key_name )
507 while (*section)
509 if (!wcsicmp( (*section)->name, section_name ))
511 PROFILEKEY **key = &(*section)->key;
512 while (*key)
514 if (!wcsicmp( (*key)->name, key_name ))
516 PROFILEKEY *to_del = *key;
517 *key = to_del->next;
518 HeapFree( GetProcessHeap(), 0, to_del->value);
519 HeapFree( GetProcessHeap(), 0, to_del );
520 return TRUE;
522 key = &(*key)->next;
525 section = &(*section)->next;
527 return FALSE;
531 /***********************************************************************
532 * PROFILE_DeleteAllKeys
534 * Delete all keys from a profile tree.
536 static void PROFILE_DeleteAllKeys( LPCWSTR section_name)
538 PROFILESECTION **section= &CurProfile->section;
539 while (*section)
541 if (!wcsicmp( (*section)->name, section_name ))
543 PROFILEKEY **key = &(*section)->key;
544 while (*key)
546 PROFILEKEY *to_del = *key;
547 *key = to_del->next;
548 HeapFree( GetProcessHeap(), 0, to_del->value);
549 HeapFree( GetProcessHeap(), 0, to_del );
550 CurProfile->changed =TRUE;
553 section = &(*section)->next;
558 /***********************************************************************
559 * PROFILE_Find
561 * Find a key in a profile tree, optionally creating it.
563 static PROFILEKEY *PROFILE_Find( PROFILESECTION **section, LPCWSTR section_name,
564 LPCWSTR key_name, BOOL create, BOOL create_always )
566 LPCWSTR p;
567 int seclen = 0, keylen = 0;
569 while (PROFILE_isspaceW(*section_name)) section_name++;
570 if (*section_name)
572 p = section_name + lstrlenW(section_name) - 1;
573 while ((p > section_name) && PROFILE_isspaceW(*p)) p--;
574 seclen = p - section_name + 1;
577 while (PROFILE_isspaceW(*key_name)) key_name++;
578 if (*key_name)
580 p = key_name + lstrlenW(key_name) - 1;
581 while ((p > key_name) && PROFILE_isspaceW(*p)) p--;
582 keylen = p - key_name + 1;
585 while (*section)
587 if (!wcsnicmp((*section)->name, section_name, seclen) &&
588 ((*section)->name)[seclen] == '\0')
590 PROFILEKEY **key = &(*section)->key;
592 while (*key)
594 /* If create_always is FALSE then we check if the keyname
595 * already exists. Otherwise we add it regardless of its
596 * existence, to allow keys to be added more than once in
597 * some cases.
599 if(!create_always)
601 if ( (!(wcsnicmp( (*key)->name, key_name, keylen )))
602 && (((*key)->name)[keylen] == '\0') )
603 return *key;
605 key = &(*key)->next;
607 if (!create) return NULL;
608 if (!(*key = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILEKEY) + lstrlenW(key_name) * sizeof(WCHAR) )))
609 return NULL;
610 lstrcpyW( (*key)->name, key_name );
611 (*key)->value = NULL;
612 (*key)->next = NULL;
613 return *key;
615 section = &(*section)->next;
617 if (!create) return NULL;
618 *section = HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILESECTION) + lstrlenW(section_name) * sizeof(WCHAR) );
619 if(*section == NULL) return NULL;
620 lstrcpyW( (*section)->name, section_name );
621 (*section)->next = NULL;
622 if (!((*section)->key = HeapAlloc( GetProcessHeap(), 0,
623 sizeof(PROFILEKEY) + lstrlenW(key_name) * sizeof(WCHAR) )))
625 HeapFree(GetProcessHeap(), 0, *section);
626 return NULL;
628 lstrcpyW( (*section)->key->name, key_name );
629 (*section)->key->value = NULL;
630 (*section)->key->next = NULL;
631 return (*section)->key;
635 /***********************************************************************
636 * PROFILE_FlushFile
638 * Flush the current profile to disk if changed.
640 static BOOL PROFILE_FlushFile(void)
642 HANDLE hFile = NULL;
643 FILETIME LastWriteTime;
645 if(!CurProfile)
647 WARN("No current profile!\n");
648 return FALSE;
651 if (!CurProfile->changed) return TRUE;
653 hFile = CreateFileW(CurProfile->filename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
654 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
656 if (hFile == INVALID_HANDLE_VALUE)
658 WARN("could not save profile file %s (error was %ld)\n", debugstr_w(CurProfile->filename), GetLastError());
659 return FALSE;
662 TRACE("Saving %s\n", debugstr_w(CurProfile->filename));
663 PROFILE_Save( hFile, CurProfile->section, CurProfile->encoding );
664 if(GetFileTime(hFile, NULL, NULL, &LastWriteTime))
665 CurProfile->LastWriteTime=LastWriteTime;
666 CloseHandle( hFile );
667 CurProfile->changed = FALSE;
668 return TRUE;
672 /***********************************************************************
673 * PROFILE_ReleaseFile
675 * Flush the current profile to disk and remove it from the cache.
677 static void PROFILE_ReleaseFile(void)
679 PROFILE_FlushFile();
680 PROFILE_Free( CurProfile->section );
681 HeapFree( GetProcessHeap(), 0, CurProfile->filename );
682 CurProfile->changed = FALSE;
683 CurProfile->section = NULL;
684 CurProfile->filename = NULL;
685 CurProfile->encoding = ENCODING_ANSI;
686 ZeroMemory(&CurProfile->LastWriteTime, sizeof(CurProfile->LastWriteTime));
689 /***********************************************************************
691 * Compares a file time with the current time. If the file time is
692 * at least 2.1 seconds in the past, return true.
694 * Intended as cache safety measure: The time resolution on FAT is
695 * two seconds, so files that are not at least two seconds old might
696 * keep their time even on modification, so don't cache them.
698 static BOOL is_not_current(FILETIME *ft)
700 LARGE_INTEGER now;
701 LONGLONG ftll;
703 NtQuerySystemTime( &now );
704 ftll = ((LONGLONG)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
705 TRACE("%s; %s\n", wine_dbgstr_longlong(ftll), wine_dbgstr_longlong(now.QuadPart));
706 return ftll + 21000000 < now.QuadPart;
709 /***********************************************************************
710 * PROFILE_Open
712 * Open a profile file, checking the cached file first.
714 static BOOL PROFILE_Open( LPCWSTR filename, BOOL write_access )
716 WCHAR buffer[MAX_PATH];
717 HANDLE hFile = INVALID_HANDLE_VALUE;
718 FILETIME LastWriteTime;
719 int i,j;
720 PROFILE *tempProfile;
722 ZeroMemory(&LastWriteTime, sizeof(LastWriteTime));
724 /* First time around */
726 if(!CurProfile)
727 for(i=0;i<N_CACHED_PROFILES;i++)
729 MRUProfile[i]=HeapAlloc( GetProcessHeap(), 0, sizeof(PROFILE) );
730 if(MRUProfile[i] == NULL) break;
731 MRUProfile[i]->changed=FALSE;
732 MRUProfile[i]->section=NULL;
733 MRUProfile[i]->filename=NULL;
734 MRUProfile[i]->encoding=ENCODING_ANSI;
735 ZeroMemory(&MRUProfile[i]->LastWriteTime, sizeof(FILETIME));
738 if (!filename)
739 filename = L"win.ini";
741 if ((RtlDetermineDosPathNameType_U(filename) == RELATIVE_PATH) &&
742 !wcschr(filename, '\\') && !wcschr(filename, '/'))
744 WCHAR windirW[MAX_PATH];
745 GetWindowsDirectoryW( windirW, MAX_PATH );
746 lstrcpyW(buffer, windirW);
747 lstrcatW(buffer, L"\\");
748 lstrcatW(buffer, filename);
750 else
752 LPWSTR dummy;
753 GetFullPathNameW(filename, ARRAY_SIZE(buffer), buffer, &dummy);
756 TRACE("path: %s\n", debugstr_w(buffer));
758 hFile = CreateFileW(buffer, GENERIC_READ | (write_access ? GENERIC_WRITE : 0),
759 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
760 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
762 if ((hFile == INVALID_HANDLE_VALUE) && (GetLastError() != ERROR_FILE_NOT_FOUND))
764 WARN("Error %ld opening file %s\n", GetLastError(), debugstr_w(buffer));
765 return FALSE;
768 for(i=0;i<N_CACHED_PROFILES;i++)
770 if ((MRUProfile[i]->filename && !wcsicmp( buffer, MRUProfile[i]->filename )))
772 TRACE("MRU Filename: %s, new filename: %s\n", debugstr_w(MRUProfile[i]->filename), debugstr_w(buffer));
773 if(i)
775 PROFILE_FlushFile();
776 tempProfile=MRUProfile[i];
777 for(j=i;j>0;j--)
778 MRUProfile[j]=MRUProfile[j-1];
779 CurProfile=tempProfile;
782 if (hFile != INVALID_HANDLE_VALUE)
784 GetFileTime(hFile, NULL, NULL, &LastWriteTime);
785 if (!memcmp( &CurProfile->LastWriteTime, &LastWriteTime, sizeof(FILETIME) ) &&
786 is_not_current(&LastWriteTime))
787 TRACE("(%s): already opened (mru=%d)\n",
788 debugstr_w(buffer), i);
789 else
791 TRACE("(%s): already opened, needs refreshing (mru=%d)\n",
792 debugstr_w(buffer), i);
793 PROFILE_Free(CurProfile->section);
794 CurProfile->section = PROFILE_Load(hFile, &CurProfile->encoding);
795 CurProfile->LastWriteTime = LastWriteTime;
797 CloseHandle(hFile);
798 return TRUE;
800 else TRACE("(%s): already opened, not yet created (mru=%d)\n",
801 debugstr_w(buffer), i);
805 /* Flush the old current profile */
806 PROFILE_FlushFile();
808 /* Make the oldest profile the current one only in order to get rid of it */
809 if(i==N_CACHED_PROFILES)
811 tempProfile=MRUProfile[N_CACHED_PROFILES-1];
812 for(i=N_CACHED_PROFILES-1;i>0;i--)
813 MRUProfile[i]=MRUProfile[i-1];
814 CurProfile=tempProfile;
816 if(CurProfile->filename) PROFILE_ReleaseFile();
818 /* OK, now that CurProfile is definitely free we assign it our new file */
819 CurProfile->filename = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(buffer)+1) * sizeof(WCHAR) );
820 lstrcpyW( CurProfile->filename, buffer );
822 if (hFile != INVALID_HANDLE_VALUE)
824 CurProfile->section = PROFILE_Load(hFile, &CurProfile->encoding);
825 GetFileTime(hFile, NULL, NULL, &CurProfile->LastWriteTime);
826 CloseHandle(hFile);
828 else
830 /* Does not exist yet, we will create it in PROFILE_FlushFile */
831 WARN("profile file %s not found\n", debugstr_w(buffer) );
833 return TRUE;
837 /***********************************************************************
838 * PROFILE_GetSection
840 * Returns all keys of a section.
841 * If return_values is TRUE, also include the corresponding values.
843 static INT PROFILE_GetSection( const WCHAR *filename, LPCWSTR section_name,
844 LPWSTR buffer, UINT len, BOOL return_values )
846 PROFILESECTION *section;
847 PROFILEKEY *key;
849 if(!buffer) return 0;
851 TRACE("%s,%p,%u\n", debugstr_w(section_name), buffer, len);
853 EnterCriticalSection( &PROFILE_CritSect );
855 if (!PROFILE_Open( filename, FALSE ))
857 LeaveCriticalSection( &PROFILE_CritSect );
858 buffer[0] = 0;
859 return 0;
862 for (section = CurProfile->section; section; section = section->next)
864 if (!wcsicmp( section->name, section_name ))
866 UINT oldlen = len;
867 for (key = section->key; key; key = key->next)
869 if (len <= 2) break;
870 if (!*key->name && !key->value) continue; /* Skip empty lines */
871 if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
872 if (!return_values && !key->value) continue; /* Skip lines w.o. '=' */
873 lstrcpynW( buffer, key->name, len - 1 );
874 len -= lstrlenW(buffer) + 1;
875 buffer += lstrlenW(buffer) + 1;
876 if (len < 2)
877 break;
878 if (return_values && key->value) {
879 buffer[-1] = '=';
880 lstrcpynW( buffer, key->value, len - 1 );
881 len -= lstrlenW(buffer) + 1;
882 buffer += lstrlenW(buffer) + 1;
885 *buffer = '\0';
887 LeaveCriticalSection( &PROFILE_CritSect );
889 if (len <= 1)
890 /*If either lpszSection or lpszKey is NULL and the supplied
891 destination buffer is too small to hold all the strings,
892 the last string is truncated and followed by two null characters.
893 In this case, the return value is equal to cchReturnBuffer
894 minus two. */
896 buffer[-1] = '\0';
897 return oldlen - 2;
899 return oldlen - len;
902 buffer[0] = buffer[1] = '\0';
904 LeaveCriticalSection( &PROFILE_CritSect );
906 return 0;
909 static BOOL PROFILE_DeleteSection( const WCHAR *filename, const WCHAR *name )
911 PROFILESECTION **section;
913 EnterCriticalSection( &PROFILE_CritSect );
915 if (!PROFILE_Open( filename, TRUE ))
917 LeaveCriticalSection( &PROFILE_CritSect );
918 return FALSE;
921 for (section = &CurProfile->section; *section; section = &(*section)->next)
923 if (!wcsicmp( (*section)->name, name ))
925 PROFILESECTION *to_del = *section;
926 *section = to_del->next;
927 to_del->next = NULL;
928 PROFILE_Free( to_del );
929 CurProfile->changed = TRUE;
930 PROFILE_FlushFile();
931 break;
935 LeaveCriticalSection( &PROFILE_CritSect );
936 return TRUE;
940 /* See GetPrivateProfileSectionNamesA for documentation */
941 static INT PROFILE_GetSectionNames( LPWSTR buffer, UINT len )
943 LPWSTR buf;
944 UINT buflen,tmplen;
945 PROFILESECTION *section;
947 TRACE("(%p, %d)\n", buffer, len);
949 if (!buffer || !len)
950 return 0;
951 if (len==1) {
952 *buffer='\0';
953 return 0;
956 buflen=len-1;
957 buf=buffer;
958 section = CurProfile->section;
959 while ((section!=NULL)) {
960 if (section->name[0]) {
961 tmplen = lstrlenW(section->name)+1;
962 if (tmplen >= buflen) {
963 if (buflen > 0) {
964 memcpy(buf, section->name, (buflen-1) * sizeof(WCHAR));
965 buf += buflen-1;
966 *buf++='\0';
968 *buf='\0';
969 return len-2;
971 memcpy(buf, section->name, tmplen * sizeof(WCHAR));
972 buf += tmplen;
973 buflen -= tmplen;
975 section = section->next;
977 *buf='\0';
978 return buf-buffer;
981 /***********************************************************************
982 * PROFILE_SetString
984 * Set a profile string.
986 static BOOL PROFILE_SetString( LPCWSTR section_name, LPCWSTR key_name,
987 LPCWSTR value, BOOL create_always )
989 if (!value) /* Delete a key */
991 TRACE("(%s,%s)\n", debugstr_w(section_name), debugstr_w(key_name) );
992 CurProfile->changed |= PROFILE_DeleteKey( &CurProfile->section,
993 section_name, key_name );
994 return TRUE; /* same error handling as above */
996 else /* Set the key value */
998 PROFILEKEY *key = PROFILE_Find(&CurProfile->section, section_name,
999 key_name, TRUE, create_always );
1000 TRACE("(%s,%s,%s):\n",
1001 debugstr_w(section_name), debugstr_w(key_name), debugstr_w(value) );
1002 if (!key) return FALSE;
1004 /* strip the leading spaces. We can safely strip \n\r and
1005 * friends too, they should not happen here anyway. */
1006 while (PROFILE_isspaceW(*value)) value++;
1008 if (key->value)
1010 if (!wcscmp( key->value, value ))
1012 TRACE(" no change needed\n" );
1013 return TRUE; /* No change needed */
1015 TRACE(" replacing %s\n", debugstr_w(key->value) );
1016 HeapFree( GetProcessHeap(), 0, key->value );
1018 else TRACE(" creating key\n" );
1019 key->value = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(value)+1) * sizeof(WCHAR) );
1020 lstrcpyW( key->value, value );
1021 CurProfile->changed = TRUE;
1023 return TRUE;
1026 static HKEY open_file_mapping_key( const WCHAR *filename )
1028 static HKEY mapping_key;
1029 HKEY key;
1031 EnterCriticalSection( &PROFILE_CritSect );
1033 if (!mapping_key && RegOpenKeyExW( HKEY_LOCAL_MACHINE,
1034 L"Software\\Microsoft\\Windows NT\\CurrentVersion\\IniFileMapping",
1035 0, KEY_WOW64_64KEY, &mapping_key ))
1036 mapping_key = NULL;
1038 LeaveCriticalSection( &PROFILE_CritSect );
1040 if (mapping_key && !RegOpenKeyExW( mapping_key, PathFindFileNameW( filename ), 0, KEY_READ, &key ))
1041 return key;
1042 return NULL;
1045 static WCHAR *enum_key( HKEY key, DWORD i )
1047 WCHAR *value, *new_value;
1048 DWORD max = 256, len;
1049 LSTATUS res;
1051 if (!(value = HeapAlloc( GetProcessHeap(), 0, max * sizeof(WCHAR) ))) return NULL;
1052 len = max;
1053 while ((res = RegEnumValueW( key, i, value, &len, NULL, NULL, NULL, NULL )) == ERROR_MORE_DATA)
1055 max *= 2;
1056 if (!(new_value = HeapReAlloc( GetProcessHeap(), 0, value, max * sizeof(WCHAR) )))
1058 HeapFree( GetProcessHeap(), 0, value );
1059 return NULL;
1061 value = new_value;
1062 len = max;
1064 if (!res) return value;
1065 HeapFree( GetProcessHeap(), 0, value );
1066 return NULL;
1069 static WCHAR *get_key_value( HKEY key, const WCHAR *value )
1071 DWORD size = 0;
1072 WCHAR *data;
1074 if (RegGetValueW( key, NULL, value, RRF_RT_REG_SZ | RRF_NOEXPAND, NULL, NULL, &size )) return NULL;
1075 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
1076 if (!RegGetValueW( key, NULL, value, RRF_RT_REG_SZ | RRF_NOEXPAND, NULL, (BYTE *)data, &size )) return data;
1077 HeapFree( GetProcessHeap(), 0, data );
1078 return NULL;
1081 static HKEY open_mapped_key( const WCHAR *path, BOOL write )
1083 static const WCHAR usrW[] = {'U','S','R',':'};
1084 static const WCHAR sysW[] = {'S','Y','S',':'};
1085 WCHAR *combined_path;
1086 const WCHAR *p;
1087 LSTATUS res;
1088 HKEY key;
1090 TRACE("%s\n", debugstr_w( path ));
1092 for (p = path; strchr("!#@", *p); p++)
1093 FIXME("ignoring %c modifier\n", *p);
1095 if (!wcsncmp( p, usrW, ARRAY_SIZE( usrW ) ))
1097 if (write)
1098 res = RegCreateKeyExW( HKEY_CURRENT_USER, p + 4, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, NULL );
1099 else
1100 res = RegOpenKeyExW( HKEY_CURRENT_USER, p + 4, 0, KEY_READ, &key );
1101 return res ? NULL : key;
1104 if (!wcsncmp( p, sysW, ARRAY_SIZE( sysW ) ))
1106 p += 4;
1107 if (!(combined_path = HeapAlloc( GetProcessHeap(), 0,
1108 (ARRAY_SIZE( L"Software\\" ) + lstrlenW( p )) * sizeof(WCHAR) )))
1109 return NULL;
1110 lstrcpyW( combined_path, L"Software\\" );
1111 lstrcatW( combined_path, p );
1112 if (write)
1113 res = RegCreateKeyExW( HKEY_LOCAL_MACHINE, combined_path, 0, NULL,
1114 0, KEY_READ | KEY_WRITE, NULL, &key, NULL );
1115 else
1116 res = RegOpenKeyExW( HKEY_LOCAL_MACHINE, combined_path, 0, KEY_READ, &key );
1117 HeapFree( GetProcessHeap(), 0, combined_path );
1118 return res ? NULL : key;
1121 FIXME("unhandled path syntax %s\n", debugstr_w( path ));
1122 return NULL;
1125 /* returns TRUE if the given section + name is mapped */
1126 static BOOL get_mapped_section_key( const WCHAR *filename, const WCHAR *section,
1127 const WCHAR *name, BOOL write, HKEY *ret_key )
1129 WCHAR *path = NULL, *combined_path;
1130 HKEY key, subkey = NULL;
1132 if (!(key = open_file_mapping_key( filename )))
1133 return FALSE;
1135 if (!RegOpenKeyExW( key, section, 0, KEY_READ, &subkey ))
1137 if (!(path = get_key_value( subkey, name )))
1138 path = get_key_value( subkey, NULL );
1139 RegCloseKey( subkey );
1140 RegCloseKey( key );
1141 if (!path) return FALSE;
1143 else
1145 if (!(path = get_key_value( key, section )))
1147 if ((path = get_key_value( key, NULL )))
1149 if ((combined_path = HeapAlloc( GetProcessHeap(), 0,
1150 (lstrlenW( path ) + lstrlenW( section ) + 2) * sizeof(WCHAR) )))
1152 lstrcpyW( combined_path, path );
1153 lstrcatW( combined_path, L"\\" );
1154 lstrcatW( combined_path, section );
1156 HeapFree( GetProcessHeap(), 0, path );
1157 path = combined_path;
1160 RegCloseKey( key );
1161 if (!path) return FALSE;
1164 *ret_key = open_mapped_key( path, write );
1165 HeapFree( GetProcessHeap(), 0, path );
1166 return TRUE;
1169 static DWORD get_mapped_section( HKEY key, WCHAR *buffer, DWORD size, BOOL return_values )
1171 WCHAR *entry, *value;
1172 DWORD i, ret = 0;
1174 for (i = 0; (entry = enum_key( key, i )); ++i)
1176 lstrcpynW( buffer + ret, entry, size - ret - 1 );
1177 ret = min( ret + lstrlenW( entry ) + 1, size - 1 );
1178 if (return_values && ret < size - 1 && (value = get_key_value( key, entry )))
1180 buffer[ret - 1] = '=';
1181 lstrcpynW( buffer + ret, value, size - ret - 1 );
1182 ret = min( ret + lstrlenW( value ) + 1, size - 1 );
1183 HeapFree( GetProcessHeap(), 0, value );
1185 HeapFree( GetProcessHeap(), 0, entry );
1188 return ret;
1191 static DWORD get_section( const WCHAR *filename, const WCHAR *section,
1192 WCHAR *buffer, DWORD size, BOOL return_values )
1194 HKEY key, subkey, section_key;
1195 BOOL use_ini = TRUE;
1196 DWORD ret = 0;
1197 WCHAR *path;
1199 if ((key = open_file_mapping_key( filename )))
1201 if (!RegOpenKeyExW( key, section, 0, KEY_READ, &subkey ))
1203 WCHAR *entry, *value;
1204 HKEY entry_key;
1205 DWORD i;
1207 for (i = 0; (entry = enum_key( subkey, i )); ++i)
1209 if (!(path = get_key_value( subkey, entry )))
1211 HeapFree( GetProcessHeap(), 0, entry );
1212 continue;
1215 entry_key = open_mapped_key( path, FALSE );
1216 HeapFree( GetProcessHeap(), 0, path );
1217 if (!entry_key)
1219 HeapFree( GetProcessHeap(), 0, entry );
1220 continue;
1223 if (entry[0])
1225 if ((value = get_key_value( entry_key, entry )))
1227 lstrcpynW( buffer + ret, entry, size - ret - 1 );
1228 ret = min( ret + lstrlenW( entry ) + 1, size - 1 );
1229 if (return_values && ret < size - 1)
1231 buffer[ret - 1] = '=';
1232 lstrcpynW( buffer + ret, value, size - ret - 1 );
1233 ret = min( ret + lstrlenW( value ) + 1, size - 1 );
1235 HeapFree( GetProcessHeap(), 0, value );
1238 else
1240 ret = get_mapped_section( entry_key, buffer, size, return_values );
1241 use_ini = FALSE;
1244 HeapFree( GetProcessHeap(), 0, entry );
1245 RegCloseKey( entry_key );
1248 RegCloseKey( subkey );
1250 else if (get_mapped_section_key( filename, section, NULL, FALSE, &section_key ))
1252 ret = get_mapped_section( section_key, buffer, size, return_values );
1253 use_ini = FALSE;
1254 RegCloseKey( section_key );
1257 RegCloseKey( key );
1260 if (use_ini)
1261 ret += PROFILE_GetSection( filename, section, buffer + ret, size - ret, return_values );
1263 return ret;
1266 static void delete_key_values( HKEY key )
1268 WCHAR *entry;
1270 while ((entry = enum_key( key, 0 )))
1272 RegDeleteValueW( key, entry );
1273 HeapFree( GetProcessHeap(), 0, entry );
1277 static BOOL delete_section( const WCHAR *filename, const WCHAR *section )
1279 HKEY key, subkey, section_key;
1281 if ((key = open_file_mapping_key( filename )))
1283 if (!RegOpenKeyExW( key, section, 0, KEY_READ, &subkey ))
1285 WCHAR *entry, *path;
1286 HKEY entry_key;
1287 DWORD i;
1289 for (i = 0; (entry = enum_key( subkey, i )); ++i)
1291 if (!(path = get_key_value( subkey, entry )))
1293 HeapFree( GetProcessHeap(), 0, entry );
1294 continue;
1297 entry_key = open_mapped_key( path, TRUE );
1298 HeapFree( GetProcessHeap(), 0, path );
1299 if (!entry_key)
1301 HeapFree( GetProcessHeap(), 0, entry );
1302 continue;
1305 if (entry[0])
1306 RegDeleteValueW( entry_key, entry );
1307 else
1308 delete_key_values( entry_key );
1310 HeapFree( GetProcessHeap(), 0, entry );
1311 RegCloseKey( entry_key );
1314 RegCloseKey( subkey );
1316 else if (get_mapped_section_key( filename, section, NULL, TRUE, &section_key ))
1318 delete_key_values( section_key );
1319 RegCloseKey( section_key );
1322 RegCloseKey( key );
1325 return PROFILE_DeleteSection( filename, section );
1328 /********************* API functions **********************************/
1331 /***********************************************************************
1332 * GetProfileIntA (KERNEL32.@)
1334 UINT WINAPI GetProfileIntA( LPCSTR section, LPCSTR entry, INT def_val )
1336 return GetPrivateProfileIntA( section, entry, def_val, "win.ini" );
1339 /***********************************************************************
1340 * GetProfileIntW (KERNEL32.@)
1342 UINT WINAPI GetProfileIntW( LPCWSTR section, LPCWSTR entry, INT def_val )
1344 return GetPrivateProfileIntW( section, entry, def_val, L"win.ini" );
1347 /***********************************************************************
1348 * GetPrivateProfileStringW (KERNEL32.@)
1350 INT WINAPI GetPrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
1351 LPCWSTR def_val, LPWSTR buffer,
1352 UINT len, LPCWSTR filename )
1354 int ret;
1355 LPWSTR defval_tmp = NULL;
1356 const WCHAR *p;
1357 HKEY key;
1359 TRACE("%s,%s,%s,%p,%u,%s\n", debugstr_w(section), debugstr_w(entry),
1360 debugstr_w(def_val), buffer, len, debugstr_w(filename));
1362 if (!buffer || !len) return 0;
1363 if (!def_val) def_val = L"";
1364 if (!section) return GetPrivateProfileSectionNamesW( buffer, len, filename );
1365 if (!entry)
1367 ret = get_section( filename, section, buffer, len, FALSE );
1368 if (!buffer[0])
1370 PROFILE_CopyEntry( buffer, def_val, len );
1371 ret = lstrlenW( buffer );
1373 return ret;
1376 /* strip any trailing ' ' of def_val. */
1377 p = def_val + lstrlenW(def_val) - 1;
1379 while (p > def_val && *p == ' ') p--;
1381 if (p >= def_val)
1383 int vlen = (int)(p - def_val) + 1;
1385 defval_tmp = HeapAlloc(GetProcessHeap(), 0, (vlen + 1) * sizeof(WCHAR));
1386 memcpy(defval_tmp, def_val, vlen * sizeof(WCHAR));
1387 defval_tmp[vlen] = '\0';
1388 def_val = defval_tmp;
1391 if (get_mapped_section_key( filename, section, entry, FALSE, &key ))
1393 if (key)
1395 WCHAR *value;
1397 if ((value = get_key_value( key, entry )))
1399 lstrcpynW( buffer, value, len );
1400 HeapFree( GetProcessHeap(), 0, value );
1402 else
1403 lstrcpynW( buffer, def_val, len );
1405 RegCloseKey( key );
1407 else
1408 lstrcpynW( buffer, def_val, len );
1410 ret = lstrlenW( buffer );
1412 else
1414 EnterCriticalSection( &PROFILE_CritSect );
1416 if (PROFILE_Open( filename, FALSE ))
1418 PROFILEKEY *key = PROFILE_Find( &CurProfile->section, section, entry, FALSE, FALSE );
1419 PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val, len );
1420 TRACE("-> %s\n", debugstr_w( buffer ));
1421 ret = lstrlenW( buffer );
1423 else
1425 lstrcpynW( buffer, def_val, len );
1426 ret = lstrlenW( buffer );
1429 LeaveCriticalSection( &PROFILE_CritSect );
1432 HeapFree(GetProcessHeap(), 0, defval_tmp);
1434 TRACE("returning %s, %d\n", debugstr_w(buffer), ret);
1436 return ret;
1439 /***********************************************************************
1440 * GetPrivateProfileStringA (KERNEL32.@)
1442 INT WINAPI GetPrivateProfileStringA( LPCSTR section, LPCSTR entry,
1443 LPCSTR def_val, LPSTR buffer,
1444 UINT len, LPCSTR filename )
1446 UNICODE_STRING sectionW, entryW, def_valW, filenameW;
1447 LPWSTR bufferW;
1448 INT retW, ret = 0;
1450 bufferW = buffer ? HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)) : NULL;
1451 if (section) RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
1452 else sectionW.Buffer = NULL;
1453 if (entry) RtlCreateUnicodeStringFromAsciiz(&entryW, entry);
1454 else entryW.Buffer = NULL;
1455 if (def_val) RtlCreateUnicodeStringFromAsciiz(&def_valW, def_val);
1456 else def_valW.Buffer = NULL;
1457 if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
1458 else filenameW.Buffer = NULL;
1460 retW = GetPrivateProfileStringW( sectionW.Buffer, entryW.Buffer,
1461 def_valW.Buffer, bufferW, len,
1462 filenameW.Buffer);
1463 if (len && buffer)
1465 if (retW)
1467 ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW, buffer, len - 1, NULL, NULL);
1468 if (!ret)
1469 ret = len - 1;
1471 buffer[ret] = 0;
1474 RtlFreeUnicodeString(&sectionW);
1475 RtlFreeUnicodeString(&entryW);
1476 RtlFreeUnicodeString(&def_valW);
1477 RtlFreeUnicodeString(&filenameW);
1478 HeapFree(GetProcessHeap(), 0, bufferW);
1479 return ret;
1482 /***********************************************************************
1483 * GetProfileStringA (KERNEL32.@)
1485 INT WINAPI GetProfileStringA( LPCSTR section, LPCSTR entry, LPCSTR def_val,
1486 LPSTR buffer, UINT len )
1488 return GetPrivateProfileStringA( section, entry, def_val,
1489 buffer, len, "win.ini" );
1492 /***********************************************************************
1493 * GetProfileStringW (KERNEL32.@)
1495 INT WINAPI GetProfileStringW( LPCWSTR section, LPCWSTR entry,
1496 LPCWSTR def_val, LPWSTR buffer, UINT len )
1498 return GetPrivateProfileStringW( section, entry, def_val, buffer, len, L"win.ini" );
1501 /***********************************************************************
1502 * WriteProfileStringA (KERNEL32.@)
1504 BOOL WINAPI WriteProfileStringA( LPCSTR section, LPCSTR entry,
1505 LPCSTR string )
1507 return WritePrivateProfileStringA( section, entry, string, "win.ini" );
1510 /***********************************************************************
1511 * WriteProfileStringW (KERNEL32.@)
1513 BOOL WINAPI WriteProfileStringW( LPCWSTR section, LPCWSTR entry,
1514 LPCWSTR string )
1516 return WritePrivateProfileStringW( section, entry, string, L"win.ini" );
1520 /***********************************************************************
1521 * GetPrivateProfileIntW (KERNEL32.@)
1523 UINT WINAPI GetPrivateProfileIntW( LPCWSTR section, LPCWSTR entry,
1524 INT def_val, LPCWSTR filename )
1526 WCHAR buffer[30];
1527 UNICODE_STRING bufferW;
1528 ULONG result;
1530 if (GetPrivateProfileStringW( section, entry, L"", buffer, ARRAY_SIZE( buffer ),
1531 filename ) == 0)
1532 return def_val;
1534 /* FIXME: if entry can be found but it's empty, then Win16 is
1535 * supposed to return 0 instead of def_val ! Difficult/problematic
1536 * to implement (every other failure also returns zero buffer),
1537 * thus wait until testing framework avail for making sure nothing
1538 * else gets broken that way. */
1539 if (!buffer[0]) return (UINT)def_val;
1541 RtlInitUnicodeString( &bufferW, buffer );
1542 RtlUnicodeStringToInteger( &bufferW, 0, &result);
1543 return result;
1546 /***********************************************************************
1547 * GetPrivateProfileIntA (KERNEL32.@)
1549 UINT WINAPI GetPrivateProfileIntA( LPCSTR section, LPCSTR entry,
1550 INT def_val, LPCSTR filename )
1552 UNICODE_STRING entryW, filenameW, sectionW;
1553 UINT res;
1554 if(entry) RtlCreateUnicodeStringFromAsciiz(&entryW, entry);
1555 else entryW.Buffer = NULL;
1556 if(filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
1557 else filenameW.Buffer = NULL;
1558 if(section) RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
1559 else sectionW.Buffer = NULL;
1560 res = GetPrivateProfileIntW(sectionW.Buffer, entryW.Buffer, def_val,
1561 filenameW.Buffer);
1562 RtlFreeUnicodeString(&sectionW);
1563 RtlFreeUnicodeString(&filenameW);
1564 RtlFreeUnicodeString(&entryW);
1565 return res;
1568 /***********************************************************************
1569 * GetPrivateProfileSectionW (KERNEL32.@)
1571 INT WINAPI GetPrivateProfileSectionW( LPCWSTR section, LPWSTR buffer,
1572 DWORD len, LPCWSTR filename )
1574 if (!section || !buffer)
1576 SetLastError(ERROR_INVALID_PARAMETER);
1577 return 0;
1580 TRACE("(%s, %p, %ld, %s)\n", debugstr_w(section), buffer, len, debugstr_w(filename));
1582 return get_section( filename, section, buffer, len, TRUE );
1585 /***********************************************************************
1586 * GetPrivateProfileSectionA (KERNEL32.@)
1588 INT WINAPI GetPrivateProfileSectionA( LPCSTR section, LPSTR buffer,
1589 DWORD len, LPCSTR filename )
1591 UNICODE_STRING sectionW, filenameW;
1592 LPWSTR bufferW;
1593 INT retW, ret = 0;
1595 if (!section || !buffer)
1597 SetLastError(ERROR_INVALID_PARAMETER);
1598 return 0;
1601 bufferW = HeapAlloc(GetProcessHeap(), 0, len * 2 * sizeof(WCHAR));
1602 RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
1603 if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
1604 else filenameW.Buffer = NULL;
1606 retW = GetPrivateProfileSectionW(sectionW.Buffer, bufferW, len * 2, filenameW.Buffer);
1607 if (retW)
1609 if (retW == len * 2 - 2) retW++; /* overflow */
1610 ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 1, buffer, len, NULL, NULL);
1611 if (!ret || ret == len) /* overflow */
1613 ret = len - 2;
1614 buffer[len-2] = 0;
1615 buffer[len-1] = 0;
1617 else ret--;
1619 else
1621 buffer[0] = 0;
1622 buffer[1] = 0;
1625 RtlFreeUnicodeString(&sectionW);
1626 RtlFreeUnicodeString(&filenameW);
1627 HeapFree(GetProcessHeap(), 0, bufferW);
1628 return ret;
1631 /***********************************************************************
1632 * GetProfileSectionA (KERNEL32.@)
1634 INT WINAPI GetProfileSectionA( LPCSTR section, LPSTR buffer, DWORD len )
1636 return GetPrivateProfileSectionA( section, buffer, len, "win.ini" );
1639 /***********************************************************************
1640 * GetProfileSectionW (KERNEL32.@)
1642 INT WINAPI GetProfileSectionW( LPCWSTR section, LPWSTR buffer, DWORD len )
1644 return GetPrivateProfileSectionW( section, buffer, len, L"win.ini" );
1648 /***********************************************************************
1649 * WritePrivateProfileStringW (KERNEL32.@)
1651 BOOL WINAPI WritePrivateProfileStringW( LPCWSTR section, LPCWSTR entry,
1652 LPCWSTR string, LPCWSTR filename )
1654 BOOL ret = FALSE;
1655 HKEY key;
1657 TRACE("(%s, %s, %s, %s)\n", debugstr_w(section), debugstr_w(entry), debugstr_w(string), debugstr_w(filename));
1659 if (!section && !entry && !string) /* documented "file flush" case */
1661 EnterCriticalSection( &PROFILE_CritSect );
1662 if (!filename || PROFILE_Open( filename, TRUE ))
1664 if (CurProfile) PROFILE_ReleaseFile();
1666 LeaveCriticalSection( &PROFILE_CritSect );
1667 return FALSE;
1669 if (!entry) return delete_section( filename, section );
1671 if (get_mapped_section_key( filename, section, entry, TRUE, &key ))
1673 LSTATUS res;
1675 if (string)
1676 res = RegSetValueExW( key, entry, 0, REG_SZ, (const BYTE *)string,
1677 (lstrlenW( string ) + 1) * sizeof(WCHAR) );
1678 else
1679 res = RegDeleteValueW( key, entry );
1680 RegCloseKey( key );
1681 if (res) SetLastError( res );
1682 return !res;
1685 EnterCriticalSection( &PROFILE_CritSect );
1687 if (PROFILE_Open( filename, TRUE ))
1689 if (!section)
1690 SetLastError(ERROR_FILE_NOT_FOUND);
1691 else
1692 ret = PROFILE_SetString( section, entry, string, FALSE);
1693 if (ret) ret = PROFILE_FlushFile();
1696 LeaveCriticalSection( &PROFILE_CritSect );
1697 return ret;
1700 /***********************************************************************
1701 * WritePrivateProfileStringA (KERNEL32.@)
1703 BOOL WINAPI DECLSPEC_HOTPATCH WritePrivateProfileStringA( LPCSTR section, LPCSTR entry,
1704 LPCSTR string, LPCSTR filename )
1706 UNICODE_STRING sectionW, entryW, stringW, filenameW;
1707 BOOL ret;
1709 if (section) RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
1710 else sectionW.Buffer = NULL;
1711 if (entry) RtlCreateUnicodeStringFromAsciiz(&entryW, entry);
1712 else entryW.Buffer = NULL;
1713 if (string) RtlCreateUnicodeStringFromAsciiz(&stringW, string);
1714 else stringW.Buffer = NULL;
1715 if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
1716 else filenameW.Buffer = NULL;
1718 ret = WritePrivateProfileStringW(sectionW.Buffer, entryW.Buffer,
1719 stringW.Buffer, filenameW.Buffer);
1720 RtlFreeUnicodeString(&sectionW);
1721 RtlFreeUnicodeString(&entryW);
1722 RtlFreeUnicodeString(&stringW);
1723 RtlFreeUnicodeString(&filenameW);
1724 return ret;
1727 /***********************************************************************
1728 * WritePrivateProfileSectionW (KERNEL32.@)
1730 BOOL WINAPI WritePrivateProfileSectionW( LPCWSTR section,
1731 LPCWSTR string, LPCWSTR filename )
1733 BOOL ret = FALSE;
1734 LPWSTR p;
1735 HKEY key, section_key;
1737 if (!section && !string)
1739 EnterCriticalSection( &PROFILE_CritSect );
1740 if (!filename || PROFILE_Open( filename, TRUE ))
1742 if (CurProfile) PROFILE_ReleaseFile();
1744 LeaveCriticalSection( &PROFILE_CritSect );
1745 return FALSE;
1747 if (!string) return delete_section( filename, section );
1749 if ((key = open_file_mapping_key( filename )))
1751 /* replace existing entries, but only if they are mapped, and do not
1752 * delete any keys */
1754 const WCHAR *entry, *p;
1756 for (entry = string; *entry; entry += lstrlenW( entry ) + 1)
1758 if ((p = wcschr( entry, '=' )))
1760 WCHAR *entry_copy;
1761 p++;
1762 if (!(entry_copy = HeapAlloc( GetProcessHeap(), 0, (p - entry) * sizeof(WCHAR) )))
1764 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1765 RegCloseKey( key );
1766 return FALSE;
1768 lstrcpynW( entry_copy, entry, p - entry );
1769 if (get_mapped_section_key( filename, section, entry_copy, TRUE, &section_key ))
1771 LSTATUS res = RegSetValueExW( section_key, entry_copy, 0, REG_SZ, (const BYTE *)p,
1772 (lstrlenW( p ) + 1) * sizeof(WCHAR) );
1773 RegCloseKey( section_key );
1774 if (res)
1776 HeapFree( GetProcessHeap(), 0, entry_copy );
1777 SetLastError( res );
1778 RegCloseKey( key );
1779 return FALSE;
1782 HeapFree( GetProcessHeap(), 0, entry_copy );
1785 RegCloseKey( key );
1786 return TRUE;
1789 EnterCriticalSection( &PROFILE_CritSect );
1791 if (PROFILE_Open( filename, TRUE ))
1793 PROFILE_DeleteAllKeys(section);
1794 ret = TRUE;
1795 while (*string && ret)
1797 WCHAR *buf = HeapAlloc( GetProcessHeap(), 0, (lstrlenW( string ) + 1) * sizeof(WCHAR) );
1798 lstrcpyW( buf, string );
1799 if ((p = wcschr( buf, '=')))
1801 *p = '\0';
1802 ret = PROFILE_SetString( section, buf, p+1, TRUE );
1804 HeapFree( GetProcessHeap(), 0, buf );
1805 string += lstrlenW( string ) + 1;
1807 if (ret) ret = PROFILE_FlushFile();
1810 LeaveCriticalSection( &PROFILE_CritSect );
1811 return ret;
1814 /***********************************************************************
1815 * WritePrivateProfileSectionA (KERNEL32.@)
1817 BOOL WINAPI WritePrivateProfileSectionA( LPCSTR section,
1818 LPCSTR string, LPCSTR filename)
1821 UNICODE_STRING sectionW, filenameW;
1822 LPWSTR stringW;
1823 BOOL ret;
1825 if (string)
1827 INT lenA, lenW;
1828 LPCSTR p = string;
1830 while(*p) p += strlen(p) + 1;
1831 lenA = p - string + 1;
1832 lenW = MultiByteToWideChar(CP_ACP, 0, string, lenA, NULL, 0);
1833 if ((stringW = HeapAlloc(GetProcessHeap(), 0, lenW * sizeof(WCHAR))))
1834 MultiByteToWideChar(CP_ACP, 0, string, lenA, stringW, lenW);
1836 else stringW = NULL;
1837 if (section) RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
1838 else sectionW.Buffer = NULL;
1839 if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
1840 else filenameW.Buffer = NULL;
1842 ret = WritePrivateProfileSectionW(sectionW.Buffer, stringW, filenameW.Buffer);
1844 HeapFree(GetProcessHeap(), 0, stringW);
1845 RtlFreeUnicodeString(&sectionW);
1846 RtlFreeUnicodeString(&filenameW);
1847 return ret;
1850 /***********************************************************************
1851 * WriteProfileSectionA (KERNEL32.@)
1853 BOOL WINAPI WriteProfileSectionA( LPCSTR section, LPCSTR keys_n_values)
1856 return WritePrivateProfileSectionA( section, keys_n_values, "win.ini");
1859 /***********************************************************************
1860 * WriteProfileSectionW (KERNEL32.@)
1862 BOOL WINAPI WriteProfileSectionW( LPCWSTR section, LPCWSTR keys_n_values)
1864 return WritePrivateProfileSectionW(section, keys_n_values, L"win.ini");
1868 /***********************************************************************
1869 * GetPrivateProfileSectionNamesW (KERNEL32.@)
1871 * Returns the section names contained in the specified file.
1872 * FIXME: Where do we find this file when the path is relative?
1873 * The section names are returned as a list of strings with an extra
1874 * '\0' to mark the end of the list. Except for that the behavior
1875 * depends on the Windows version.
1877 * Win95:
1878 * - if the buffer is 0 or 1 character long then it is as if it was of
1879 * infinite length.
1880 * - otherwise, if the buffer is too small only the section names that fit
1881 * are returned.
1882 * - note that this means if the buffer was too small to return even just
1883 * the first section name then a single '\0' will be returned.
1884 * - the return value is the number of characters written in the buffer,
1885 * except if the buffer was too small in which case len-2 is returned
1887 * Win2000:
1888 * - if the buffer is 0, 1 or 2 characters long then it is filled with
1889 * '\0' and the return value is 0
1890 * - otherwise if the buffer is too small then the first section name that
1891 * does not fit is truncated so that the string list can be terminated
1892 * correctly (double '\0')
1893 * - the return value is the number of characters written in the buffer
1894 * except for the trailing '\0'. If the buffer is too small, then the
1895 * return value is len-2
1896 * - Win2000 has a bug that triggers when the section names and the
1897 * trailing '\0' fit exactly in the buffer. In that case the trailing
1898 * '\0' is missing.
1900 * Wine implements the observed Win2000 behavior (except for the bug).
1902 * Note that when the buffer is big enough then the return value may be any
1903 * value between 1 and len-1 (or len in Win95), including len-2.
1905 DWORD WINAPI GetPrivateProfileSectionNamesW( LPWSTR buffer, DWORD size,
1906 LPCWSTR filename)
1908 DWORD ret = 0;
1909 HKEY key;
1911 if ((key = open_file_mapping_key( filename )))
1913 WCHAR *section;
1914 DWORD i;
1916 for (i = 0; (section = enum_key( key, i )); ++i)
1918 lstrcpynW( buffer + ret, section, size - ret - 1 );
1919 ret = min( ret + lstrlenW( section ) + 1, size - 1 );
1920 HeapFree( GetProcessHeap(), 0, section );
1923 RegCloseKey( key );
1926 RtlEnterCriticalSection( &PROFILE_CritSect );
1928 if (PROFILE_Open( filename, FALSE ))
1929 ret += PROFILE_GetSectionNames( buffer + ret, size - ret );
1931 RtlLeaveCriticalSection( &PROFILE_CritSect );
1933 return ret;
1937 /***********************************************************************
1938 * GetPrivateProfileSectionNamesA (KERNEL32.@)
1940 DWORD WINAPI GetPrivateProfileSectionNamesA( LPSTR buffer, DWORD size,
1941 LPCSTR filename)
1943 UNICODE_STRING filenameW;
1944 LPWSTR bufferW;
1945 INT retW, ret = 0;
1947 bufferW = buffer ? HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)) : NULL;
1948 if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
1949 else filenameW.Buffer = NULL;
1951 retW = GetPrivateProfileSectionNamesW(bufferW, size, filenameW.Buffer);
1952 if (retW && size)
1954 ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW+1, buffer, size-1, NULL, NULL);
1955 if (!ret)
1957 ret = size-2;
1958 buffer[size-1] = 0;
1960 else
1961 ret = ret-1;
1963 else if(size)
1964 buffer[0] = '\0';
1966 RtlFreeUnicodeString(&filenameW);
1967 HeapFree(GetProcessHeap(), 0, bufferW);
1968 return ret;
1971 static int get_hex_byte( const WCHAR *p )
1973 int val;
1975 if (*p >= '0' && *p <= '9') val = *p - '0';
1976 else if (*p >= 'A' && *p <= 'Z') val = *p - 'A' + 10;
1977 else if (*p >= 'a' && *p <= 'z') val = *p - 'a' + 10;
1978 else return -1;
1979 val <<= 4;
1980 p++;
1981 if (*p >= '0' && *p <= '9') val += *p - '0';
1982 else if (*p >= 'A' && *p <= 'Z') val += *p - 'A' + 10;
1983 else if (*p >= 'a' && *p <= 'z') val += *p - 'a' + 10;
1984 else return -1;
1985 return val;
1988 /***********************************************************************
1989 * GetPrivateProfileStructW (KERNEL32.@)
1991 * Should match Win95's behaviour pretty much
1993 BOOL WINAPI GetPrivateProfileStructW (LPCWSTR section, LPCWSTR key,
1994 LPVOID buf, UINT len, LPCWSTR filename)
1996 BOOL ret = FALSE;
1997 LPBYTE data = buf;
1998 BYTE chksum = 0;
1999 int val;
2000 WCHAR *p, *buffer;
2002 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (2 * len + 3) * sizeof(WCHAR) ))) return FALSE;
2004 if (GetPrivateProfileStringW( section, key, NULL, buffer, 2 * len + 3, filename ) != 2 * len + 2)
2005 goto done;
2007 for (p = buffer; len; p += 2, len--)
2009 if ((val = get_hex_byte( p )) == -1) goto done;
2010 *data++ = val;
2011 chksum += val;
2013 /* retrieve stored checksum value */
2014 if ((val = get_hex_byte( p )) == -1) goto done;
2015 ret = ((BYTE)val == chksum);
2017 done:
2018 HeapFree( GetProcessHeap(), 0, buffer );
2019 return ret;
2022 /***********************************************************************
2023 * GetPrivateProfileStructA (KERNEL32.@)
2025 BOOL WINAPI GetPrivateProfileStructA (LPCSTR section, LPCSTR key,
2026 LPVOID buffer, UINT len, LPCSTR filename)
2028 UNICODE_STRING sectionW, keyW, filenameW;
2029 INT ret;
2031 if (section) RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
2032 else sectionW.Buffer = NULL;
2033 if (key) RtlCreateUnicodeStringFromAsciiz(&keyW, key);
2034 else keyW.Buffer = NULL;
2035 if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
2036 else filenameW.Buffer = NULL;
2038 ret = GetPrivateProfileStructW(sectionW.Buffer, keyW.Buffer, buffer, len,
2039 filenameW.Buffer);
2040 /* Do not translate binary data. */
2042 RtlFreeUnicodeString(&sectionW);
2043 RtlFreeUnicodeString(&keyW);
2044 RtlFreeUnicodeString(&filenameW);
2045 return ret;
2050 /***********************************************************************
2051 * WritePrivateProfileStructW (KERNEL32.@)
2053 BOOL WINAPI WritePrivateProfileStructW (LPCWSTR section, LPCWSTR key,
2054 LPVOID buf, UINT bufsize, LPCWSTR filename)
2056 BOOL ret = FALSE;
2057 LPBYTE binbuf;
2058 LPWSTR outstring, p;
2059 DWORD sum = 0;
2061 TRACE("(%s %s %p %u %s)\n", debugstr_w(section), debugstr_w(key), buf, bufsize, debugstr_w(filename));
2063 if (!section && !key && !buf) /* flush the cache */
2064 return WritePrivateProfileStringW( NULL, NULL, NULL, filename );
2066 if (!buf)
2067 return WritePrivateProfileStringW(section, key, NULL, filename);
2069 /* allocate string buffer for hex chars + checksum hex char + '\0' */
2070 outstring = HeapAlloc( GetProcessHeap(), 0, (bufsize*2 + 2 + 1) * sizeof(WCHAR) );
2071 p = outstring;
2072 for (binbuf = (LPBYTE)buf; binbuf < (LPBYTE)buf+bufsize; binbuf++) {
2073 *p++ = hex[*binbuf >> 4];
2074 *p++ = hex[*binbuf & 0xf];
2075 sum += *binbuf;
2077 /* checksum is sum & 0xff */
2078 *p++ = hex[(sum & 0xf0) >> 4];
2079 *p++ = hex[sum & 0xf];
2080 *p++ = '\0';
2082 ret = WritePrivateProfileStringW( section, key, outstring, filename );
2083 HeapFree( GetProcessHeap(), 0, outstring );
2084 return ret;
2087 /***********************************************************************
2088 * WritePrivateProfileStructA (KERNEL32.@)
2090 BOOL WINAPI WritePrivateProfileStructA (LPCSTR section, LPCSTR key,
2091 LPVOID buf, UINT bufsize, LPCSTR filename)
2093 UNICODE_STRING sectionW, keyW, filenameW;
2094 INT ret;
2096 if (section) RtlCreateUnicodeStringFromAsciiz(&sectionW, section);
2097 else sectionW.Buffer = NULL;
2098 if (key) RtlCreateUnicodeStringFromAsciiz(&keyW, key);
2099 else keyW.Buffer = NULL;
2100 if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
2101 else filenameW.Buffer = NULL;
2103 /* Do not translate binary data. */
2104 ret = WritePrivateProfileStructW(sectionW.Buffer, keyW.Buffer, buf, bufsize,
2105 filenameW.Buffer);
2107 RtlFreeUnicodeString(&sectionW);
2108 RtlFreeUnicodeString(&keyW);
2109 RtlFreeUnicodeString(&filenameW);
2110 return ret;
2114 /***********************************************************************
2115 * OpenProfileUserMapping (KERNEL32.@)
2117 BOOL WINAPI OpenProfileUserMapping(void) {
2118 FIXME("(), stub!\n");
2119 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2120 return FALSE;
2123 /***********************************************************************
2124 * CloseProfileUserMapping (KERNEL32.@)
2126 BOOL WINAPI CloseProfileUserMapping(void) {
2127 FIXME("(), stub!\n");
2128 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2129 return FALSE;