Release 970509
[wine/multimedia.git] / files / profile.c
blob06b8b70783ecbf48b8f51a59c9244a69d9ecec12
1 /*
2 * Profile functions
4 * Copyright 1993 Miguel de Icaza
5 * Copyright 1996 Alexandre Julliard
6 */
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include "windows.h"
14 #include "file.h"
15 #include "heap.h"
16 #include "stddebug.h"
17 #include "debug.h"
19 typedef struct tagPROFILEKEY
21 char *name;
22 char *value;
23 struct tagPROFILEKEY *next;
24 } PROFILEKEY;
26 typedef struct tagPROFILESECTION
28 char *name;
29 struct tagPROFILEKEY *key;
30 struct tagPROFILESECTION *next;
31 } PROFILESECTION;
34 typedef struct
36 BOOL32 changed;
37 PROFILESECTION *section;
38 char *dos_name;
39 char *unix_name;
40 char *filename;
41 } PROFILE;
44 /* Cached profile file */
45 static PROFILE CurProfile = { FALSE, NULL, NULL };
47 /* wine.ini profile content */
48 static PROFILESECTION *WineProfile;
50 #define PROFILE_MAX_LINE_LEN 1024
52 /* Wine profile name in $HOME directory; must begin with slash */
53 static const char PROFILE_WineIniName[] = "/.winerc";
55 /* Check for comments in profile */
56 #define IS_ENTRY_COMMENT(str) ((str)[0] == ';')
58 #define WINE_INI_GLOBAL ETCDIR "/wine.conf"
60 static LPCWSTR wininiW = NULL;
62 /***********************************************************************
63 * PROFILE_CopyEntry
65 * Copy the content of an entry into a buffer, removing quotes, and possibly
66 * translating environment variables.
68 static void PROFILE_CopyEntry( char *buffer, const char *value, int len,
69 int handle_env )
71 char quote = '\0';
72 const char *p;
74 if ((*value == '\'') || (*value == '\"'))
76 if (value[1] && (value[strlen(value)-1] == *value)) quote = *value++;
79 if (!handle_env)
81 lstrcpyn32A( buffer, value, len );
82 if (quote && (len >= strlen(value))) buffer[strlen(buffer)-1] = '\0';
83 return;
86 for (p = value; (*p && (len > 1)); *buffer++ = *p++, len-- )
88 if ((*p == '$') && (p[1] == '{'))
90 char env_val[1024];
91 const char *env_p;
92 const char *p2 = strchr( p, '}' );
93 if (!p2) continue; /* ignore it */
94 lstrcpyn32A(env_val, p + 2, MIN( sizeof(env_val), (int)(p2-p)-1 ));
95 if ((env_p = getenv( env_val )) != NULL)
97 lstrcpyn32A( buffer, env_p, len );
98 buffer += strlen( buffer );
99 len -= strlen( buffer );
101 p = p2 + 1;
104 *buffer = '\0';
108 /***********************************************************************
109 * PROFILE_Save
111 * Save a profile tree to a file.
113 static void PROFILE_Save( FILE *file, PROFILESECTION *section )
115 PROFILEKEY *key;
117 for ( ; section; section = section->next)
119 if (section->name) fprintf( file, "[%s]\r\n", section->name );
120 for (key = section->key; key; key = key->next)
122 fprintf( file, "%s", key->name );
123 if (key->value) fprintf( file, "=%s", key->value );
124 fprintf( file, "\r\n" );
130 /***********************************************************************
131 * PROFILE_Free
133 * Free a profile tree.
135 static void PROFILE_Free( PROFILESECTION *section )
137 PROFILESECTION *next_section;
138 PROFILEKEY *key, *next_key;
140 for ( ; section; section = next_section)
142 if (section->name) HeapFree( SystemHeap, 0, section->name );
143 for (key = section->key; key; key = next_key)
145 next_key = key->next;
146 if (key->name) HeapFree( SystemHeap, 0, key->name );
147 if (key->value) HeapFree( SystemHeap, 0, key->value );
148 HeapFree( SystemHeap, 0, key );
150 next_section = section->next;
151 HeapFree( SystemHeap, 0, section );
156 /***********************************************************************
157 * PROFILE_Load
159 * Load a profile tree from a file.
161 static PROFILESECTION *PROFILE_Load( FILE *file )
163 char buffer[PROFILE_MAX_LINE_LEN];
164 char *p, *p2;
165 int line = 0;
166 PROFILESECTION *section, *first_section;
167 PROFILESECTION **prev_section;
168 PROFILEKEY *key, **prev_key;
170 first_section = HEAP_xalloc( SystemHeap, 0, sizeof(*section) );
171 first_section->name = NULL;
172 first_section->key = NULL;
173 first_section->next = NULL;
174 prev_section = &first_section->next;
175 prev_key = &first_section->key;
177 while (fgets( buffer, PROFILE_MAX_LINE_LEN, file ))
179 line++;
180 p = buffer + strlen(buffer) - 1;
181 while ((p > buffer) && ((*p == '\n') || isspace(*p))) *p-- = '\0';
182 p = buffer;
183 while (*p && isspace(*p)) p++;
184 if (*p == '[') /* section start */
186 if (!(p2 = strrchr( p, ']' )))
188 fprintf( stderr, "PROFILE_Load: Invalid section header at line %d: '%s'\n",
189 line, p );
191 else
193 *p2 = '\0';
194 p++;
195 section = HEAP_xalloc( SystemHeap, 0, sizeof(*section) );
196 section->name = HEAP_strdupA( SystemHeap, 0, p );
197 section->key = NULL;
198 section->next = NULL;
199 *prev_section = section;
200 prev_section = &section->next;
201 prev_key = &section->key;
202 continue;
205 if ((p2 = strchr( p, '=' )) != NULL)
207 char *p3 = p2 - 1;
208 while ((p3 > p) && isspace(*p3)) *p3-- = '\0';
209 *p2++ = '\0';
210 while (*p2 && isspace(*p2)) p2++;
212 key = HEAP_xalloc( SystemHeap, 0, sizeof(*key) );
213 key->name = HEAP_strdupA( SystemHeap, 0, p );
214 key->value = HEAP_strdupA( SystemHeap, 0, p2 );
215 key->next = NULL;
216 *prev_key = key;
217 prev_key = &key->next;
219 if (debugging_profile)
221 fprintf( stddeb, "PROFILE_Load:\n" );
222 PROFILE_Save( stddeb, first_section );
223 fprintf( stddeb, "PROFILE_Load finished.\n" );
225 return first_section;
229 /***********************************************************************
230 * PROFILE_DeleteSection
232 * Delete a section from a profile tree.
234 static BOOL32 PROFILE_DeleteSection( PROFILESECTION **section, LPCSTR name )
236 while (*section)
238 if ((*section)->name && !lstrcmpi32A( (*section)->name, name ))
240 PROFILESECTION *to_del = *section;
241 *section = to_del->next;
242 to_del->next = NULL;
243 PROFILE_Free( to_del );
244 return TRUE;
246 section = &(*section)->next;
248 return FALSE;
252 /***********************************************************************
253 * PROFILE_DeleteKey
255 * Delete a key from a profile tree.
257 static BOOL32 PROFILE_DeleteKey( PROFILESECTION **section,
258 LPCSTR section_name, LPCSTR key_name )
260 while (*section)
262 if ((*section)->name && !lstrcmpi32A( (*section)->name, section_name ))
264 PROFILEKEY **key = &(*section)->key;
265 while (*key)
267 if (!lstrcmpi32A( (*key)->name, key_name ))
269 PROFILEKEY *to_del = *key;
270 *key = to_del->next;
271 if (to_del->name) HeapFree( SystemHeap, 0, to_del->name );
272 if (to_del->value) HeapFree( SystemHeap, 0, to_del->value);
273 HeapFree( SystemHeap, 0, to_del );
274 return TRUE;
276 key = &(*key)->next;
279 section = &(*section)->next;
281 return FALSE;
285 /***********************************************************************
286 * PROFILE_Find
288 * Find a key in a profile tree, optionally creating it.
290 static PROFILEKEY *PROFILE_Find( PROFILESECTION **section,
291 const char *section_name,
292 const char *key_name, int create )
294 while (*section)
296 if ((*section)->name && !lstrcmpi32A( (*section)->name, section_name ))
298 PROFILEKEY **key = &(*section)->key;
299 while (*key)
301 if (!lstrcmpi32A( (*key)->name, key_name )) return *key;
302 key = &(*key)->next;
304 if (!create) return NULL;
305 *key = HEAP_xalloc( SystemHeap, 0, sizeof(PROFILEKEY) );
306 (*key)->name = HEAP_strdupA( SystemHeap, 0, key_name );
307 (*key)->value = NULL;
308 (*key)->next = NULL;
309 return *key;
311 section = &(*section)->next;
313 if (!create) return NULL;
314 *section = HEAP_xalloc( SystemHeap, 0, sizeof(PROFILESECTION) );
315 (*section)->name = HEAP_strdupA( SystemHeap, 0, section_name );
316 (*section)->next = NULL;
317 (*section)->key = HEAP_xalloc( SystemHeap, 0, sizeof(PROFILEKEY) );
318 (*section)->key->name = HEAP_strdupA( SystemHeap, 0, key_name );
319 (*section)->key->value = NULL;
320 (*section)->key->next = NULL;
321 return (*section)->key;
325 /***********************************************************************
326 * PROFILE_FlushFile
328 * Flush the current profile to disk if changed.
330 static BOOL32 PROFILE_FlushFile(void)
332 char *p, buffer[MAX_PATHNAME_LEN];
333 const char *unix_name;
334 FILE *file = NULL;
336 if (!CurProfile.changed || !CurProfile.dos_name) return TRUE;
337 if (!(unix_name = CurProfile.unix_name) || !(file = fopen(unix_name, "w")))
339 /* Try to create it in $HOME/.wine */
340 /* FIXME: this will need a more general solution */
341 if ((p = getenv( "HOME" )) != NULL)
343 strcpy( buffer, p );
344 strcat( buffer, "/.wine/" );
345 p = buffer + strlen(buffer);
346 strcpy( p, strrchr( CurProfile.dos_name, '\\' ) + 1 );
347 CharLower32A( p );
348 file = fopen( buffer, "w" );
349 unix_name = buffer;
353 if (!file)
355 fprintf( stderr, "Warning: could not save profile file %s\n",
356 CurProfile.dos_name );
357 return FALSE;
360 dprintf_profile( stddeb, "Saving '%s' into '%s'\n",
361 CurProfile.dos_name, unix_name );
362 PROFILE_Save( file, CurProfile.section );
363 fclose( file );
364 CurProfile.changed = FALSE;
365 return TRUE;
369 /***********************************************************************
370 * PROFILE_Open
372 * Open a profile file, checking the cached file first.
374 static BOOL32 PROFILE_Open( LPCSTR filename )
376 DOS_FULL_NAME full_name;
377 char buffer[MAX_PATHNAME_LEN];
378 char *newdos_name, *p;
379 FILE *file = NULL;
381 if (CurProfile.filename && !strcmp( filename, CurProfile.filename ))
383 dprintf_profile( stddeb, "PROFILE_Open(%s): already opened\n",
384 filename );
385 return TRUE;
388 if (strchr( filename, '/' ) || strchr( filename, '\\' ) ||
389 strchr( filename, ':' ))
391 if (!DOSFS_GetFullName( filename, FALSE, &full_name )) return FALSE;
393 else
395 GetWindowsDirectory32A( buffer, sizeof(buffer) );
396 strcat( buffer, "\\" );
397 strcat( buffer, filename );
398 if (!DOSFS_GetFullName( buffer, FALSE, &full_name )) return FALSE;
400 if (CurProfile.dos_name &&
401 !strcmp( full_name.short_name, CurProfile.dos_name ))
403 dprintf_profile( stddeb, "PROFILE_Open(%s): already opened\n",
404 filename );
405 return TRUE;
408 /* Flush the previous profile */
410 newdos_name = HEAP_strdupA( SystemHeap, 0, full_name.short_name );
411 PROFILE_FlushFile();
412 PROFILE_Free( CurProfile.section );
413 if (CurProfile.dos_name) HeapFree( SystemHeap, 0, CurProfile.dos_name );
414 if (CurProfile.unix_name) HeapFree( SystemHeap, 0, CurProfile.unix_name );
415 if (CurProfile.filename) HeapFree( SystemHeap, 0, CurProfile.filename );
416 CurProfile.section = NULL;
417 CurProfile.dos_name = newdos_name;
418 CurProfile.filename = HEAP_strdupA( SystemHeap, 0, filename );
420 /* Try to open the profile file, first in $HOME/.wine */
422 /* FIXME: this will need a more general solution */
423 if ((p = getenv( "HOME" )) != NULL)
425 strcpy( buffer, p );
426 strcat( buffer, "/.wine/" );
427 p = buffer + strlen(buffer);
428 strcpy( p, strrchr( newdos_name, '\\' ) + 1 );
429 CharLower32A( p );
430 if ((file = fopen( buffer, "r" )))
432 dprintf_profile( stddeb, "PROFILE_Open(%s): found it in %s\n",
433 filename, buffer );
434 CurProfile.unix_name = HEAP_strdupA( SystemHeap, 0, buffer );
438 if (!file)
440 CurProfile.unix_name = HEAP_strdupA( SystemHeap, 0,
441 full_name.long_name );
442 if ((file = fopen( full_name.long_name, "r" )))
443 dprintf_profile( stddeb, "PROFILE_Open(%s): found it in %s\n",
444 filename, full_name.long_name );
447 if (file)
449 CurProfile.section = PROFILE_Load( file );
450 fclose( file );
452 else
454 /* Does not exist yet, we will create it in PROFILE_FlushFile */
455 fprintf( stderr, "Warning: profile file %s not found\n", newdos_name );
457 return TRUE;
461 /***********************************************************************
462 * PROFILE_GetSection
464 * Enumerate all the keys of a section.
466 static INT32 PROFILE_GetSection( PROFILESECTION *section, LPCSTR section_name,
467 LPSTR buffer, INT32 len, BOOL32 handle_env )
469 PROFILEKEY *key;
470 while (section)
472 if (section->name && !lstrcmpi32A( section->name, section_name ))
474 INT32 oldlen = len;
475 for (key = section->key; key; key = key->next)
477 if (len <= 2) break;
478 if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
479 PROFILE_CopyEntry( buffer, key->name, len - 1, handle_env );
480 len -= strlen(buffer) + 1;
481 buffer += strlen(buffer) + 1;
483 *buffer = '\0';
484 return oldlen - len + 1;
486 section = section->next;
488 buffer[0] = buffer[1] = '\0';
489 return 2;
493 /***********************************************************************
494 * PROFILE_GetString
496 * Get a profile string.
498 static INT32 PROFILE_GetString( LPCSTR section, LPCSTR key_name,
499 LPCSTR def_val, LPSTR buffer, INT32 len )
501 PROFILEKEY *key = NULL;
503 if (!def_val) def_val = "";
504 if (key_name)
506 key = PROFILE_Find( &CurProfile.section, section, key_name, FALSE );
507 PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def_val,
508 len, FALSE );
509 dprintf_profile( stddeb, "PROFILE_GetString('%s','%s','%s'): returning '%s'\n",
510 section, key_name, def_val, buffer );
511 return strlen( buffer );
513 return PROFILE_GetSection(CurProfile.section, section, buffer, len, FALSE);
517 /***********************************************************************
518 * PROFILE_SetString
520 * Set a profile string.
522 static BOOL32 PROFILE_SetString( LPCSTR section_name, LPCSTR key_name,
523 LPCSTR value )
525 if (!key_name) /* Delete a whole section */
527 dprintf_profile(stddeb, "PROFILE_DeleteSection('%s')\n", section_name);
528 CurProfile.changed |= PROFILE_DeleteSection( &CurProfile.section,
529 section_name );
530 return TRUE; /* Even if PROFILE_DeleteSection() has failed,
531 this is not an error on application's level.*/
533 else if (!value) /* Delete a key */
535 dprintf_profile( stddeb, "PROFILE_DeleteKey('%s','%s')\n",
536 section_name, key_name );
537 CurProfile.changed |= PROFILE_DeleteKey( &CurProfile.section,
538 section_name, key_name );
539 return TRUE; /* same error handling as above */
541 else /* Set the key value */
543 PROFILEKEY *key = PROFILE_Find( &CurProfile.section, section_name,
544 key_name, TRUE );
545 dprintf_profile( stddeb, "PROFILE_SetString('%s','%s','%s'): ",
546 section_name, key_name, value );
547 if (!key) return FALSE;
548 if (key->value)
550 if (!strcmp( key->value, value ))
552 dprintf_profile( stddeb, "no change needed\n" );
553 return TRUE; /* No change needed */
555 dprintf_profile( stddeb, "replacing '%s'\n", key->value );
556 HeapFree( SystemHeap, 0, key->value );
558 else dprintf_profile( stddeb, "creating key\n" );
559 key->value = HEAP_strdupA( SystemHeap, 0, value );
560 CurProfile.changed = TRUE;
562 return TRUE;
566 /***********************************************************************
567 * PROFILE_GetWineIniString
569 * Get a config string from the wine.ini file.
571 int PROFILE_GetWineIniString( const char *section, const char *key_name,
572 const char *def, char *buffer, int len )
574 if (key_name)
576 PROFILEKEY *key = PROFILE_Find(&WineProfile, section, key_name, FALSE);
577 PROFILE_CopyEntry( buffer, (key && key->value) ? key->value : def,
578 len, TRUE );
579 dprintf_profile( stddeb, "PROFILE_GetWineIniString('%s','%s','%s'): returning '%s'\n",
580 section, key_name, def, buffer );
581 return strlen( buffer );
583 return PROFILE_GetSection( WineProfile, section, buffer, len, TRUE );
587 /***********************************************************************
588 * PROFILE_GetWineIniInt
590 * Get a config integer from the wine.ini file.
592 int PROFILE_GetWineIniInt( const char *section, const char *key_name, int def )
594 char buffer[20];
595 char *p;
596 long result;
598 PROFILEKEY *key = PROFILE_Find( &WineProfile, section, key_name, FALSE );
599 if (!key || !key->value) return def;
600 PROFILE_CopyEntry( buffer, key->value, sizeof(buffer), TRUE );
601 result = strtol( buffer, &p, 0 );
602 if (p == buffer) return 0; /* No digits at all */
603 return (int)result;
607 /***********************************************************************
608 * PROFILE_LoadWineIni
610 * Load the wine.ini file.
612 int PROFILE_LoadWineIni(void)
614 char buffer[MAX_PATHNAME_LEN];
615 const char *p;
616 FILE *f;
618 if ((p = getenv( "HOME" )) != NULL)
620 lstrcpyn32A(buffer, p, MAX_PATHNAME_LEN - sizeof(PROFILE_WineIniName));
621 strcat( buffer, PROFILE_WineIniName );
622 if ((f = fopen( buffer, "r" )) != NULL)
624 WineProfile = PROFILE_Load( f );
625 fclose( f );
626 return 1;
629 else fprintf( stderr, "Warning: could not get $HOME value for config file.\n" );
631 /* Try global file */
633 if ((f = fopen( WINE_INI_GLOBAL, "r" )) != NULL)
635 WineProfile = PROFILE_Load( f );
636 fclose( f );
637 return 1;
639 fprintf( stderr, "Can't open configuration file %s or $HOME%s\n",
640 WINE_INI_GLOBAL, PROFILE_WineIniName );
641 return 0;
645 /********************* API functions **********************************/
647 /***********************************************************************
648 * GetProfileInt16 (KERNEL.57)
650 UINT16 GetProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val )
652 return GetPrivateProfileInt16( section, entry, def_val, "win.ini" );
656 /***********************************************************************
657 * GetProfileInt32A (KERNEL32.264)
659 UINT32 GetProfileInt32A( LPCSTR section, LPCSTR entry, INT32 def_val )
661 return GetPrivateProfileInt32A( section, entry, def_val, "win.ini" );
664 /***********************************************************************
665 * GetProfileInt32W (KERNEL32.264)
667 UINT32 GetProfileInt32W( LPCWSTR section, LPCWSTR entry, INT32 def_val )
669 if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
670 return GetPrivateProfileInt32W( section, entry, def_val, wininiW );
673 /***********************************************************************
674 * GetProfileString16 (KERNEL.58)
676 INT16 GetProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
677 LPSTR buffer, INT16 len )
679 return GetPrivateProfileString16( section, entry, def_val,
680 buffer, len, "win.ini" );
683 /***********************************************************************
684 * GetProfileString32A (KERNEL32.268)
686 INT32 GetProfileString32A( LPCSTR section, LPCSTR entry, LPCSTR def_val,
687 LPSTR buffer, INT32 len )
689 return GetPrivateProfileString32A( section, entry, def_val,
690 buffer, len, "win.ini" );
693 /***********************************************************************
694 * GetProfileString32W (KERNEL32.269)
696 INT32 GetProfileString32W( LPCWSTR section,LPCWSTR entry,LPCWSTR def_val,
697 LPWSTR buffer, INT32 len )
699 if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
700 return GetPrivateProfileString32W( section, entry, def_val,
701 buffer, len, wininiW );
705 /***********************************************************************
706 * WriteProfileString16 (KERNEL.59)
708 BOOL16 WriteProfileString16( LPCSTR section, LPCSTR entry, LPCSTR string )
710 return WritePrivateProfileString16( section, entry, string, "win.ini" );
713 /***********************************************************************
714 * WriteProfileString32A (KERNEL32.587)
716 BOOL32 WriteProfileString32A( LPCSTR section, LPCSTR entry, LPCSTR string )
718 return WritePrivateProfileString32A( section, entry, string, "win.ini" );
721 /***********************************************************************
722 * WriteProfileString32W (KERNEL32.588)
724 BOOL32 WriteProfileString32W( LPCWSTR section, LPCWSTR entry, LPCWSTR string )
726 if (!wininiW) wininiW = HEAP_strdupAtoW( SystemHeap, 0, "win.ini" );
727 return WritePrivateProfileString32W( section, entry, string, wininiW );
731 /***********************************************************************
732 * GetPrivateProfileInt16 (KERNEL.127)
734 UINT16 GetPrivateProfileInt16( LPCSTR section, LPCSTR entry, INT16 def_val,
735 LPCSTR filename )
737 long result=(long)GetPrivateProfileInt32A(section,entry,def_val,filename);
739 if (result > 65535) return 65535;
740 if (result >= 0) return (UINT16)result;
741 if (result < -32768) return -32768;
742 return (UINT16)(INT16)result;
745 /***********************************************************************
746 * GetPrivateProfileInt32A (KERNEL32.251)
748 UINT32 GetPrivateProfileInt32A( LPCSTR section, LPCSTR entry, INT32 def_val,
749 LPCSTR filename )
751 char buffer[20];
752 char *p;
753 long result;
755 GetPrivateProfileString32A( section, entry, "",
756 buffer, sizeof(buffer), filename );
757 if (!buffer[0]) return (UINT32)def_val;
758 result = strtol( buffer, &p, 0 );
759 if (p == buffer) return 0; /* No digits at all */
760 return (UINT32)result;
763 /***********************************************************************
764 * GetPrivateProfileInt32W (KERNEL32.252)
766 UINT32 GetPrivateProfileInt32W( LPCWSTR section, LPCWSTR entry, INT32 def_val,
767 LPCWSTR filename )
769 LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section );
770 LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry );
771 LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
772 UINT32 res = GetPrivateProfileInt32A(sectionA, entryA, def_val, filenameA);
773 HeapFree( GetProcessHeap(), 0, sectionA );
774 HeapFree( GetProcessHeap(), 0, filenameA );
775 HeapFree( GetProcessHeap(), 0, entryA );
776 return res;
779 /***********************************************************************
780 * GetPrivateProfileString16 (KERNEL.128)
782 INT16 GetPrivateProfileString16( LPCSTR section, LPCSTR entry, LPCSTR def_val,
783 LPSTR buffer, INT16 len, LPCSTR filename )
785 return GetPrivateProfileString32A(section,entry,def_val,buffer,len,filename);
788 /***********************************************************************
789 * GetPrivateProfileString32A (KERNEL32.255)
791 INT32 GetPrivateProfileString32A( LPCSTR section, LPCSTR entry, LPCSTR def_val,
792 LPSTR buffer, INT32 len, LPCSTR filename )
794 if (PROFILE_Open( filename ))
795 return PROFILE_GetString( section, entry, def_val, buffer, len );
796 lstrcpyn32A( buffer, def_val, len );
797 return strlen( buffer );
800 /***********************************************************************
801 * GetPrivateProfileString32W (KERNEL32.256)
803 INT32 GetPrivateProfileString32W( LPCWSTR section, LPCWSTR entry,
804 LPCWSTR def_val, LPWSTR buffer,
805 INT32 len, LPCWSTR filename )
807 LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section );
808 LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry );
809 LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
810 LPSTR def_valA = HEAP_strdupWtoA( GetProcessHeap(), 0, def_val );
811 LPSTR bufferA = HeapAlloc( GetProcessHeap(), 0, len );
812 INT32 ret = GetPrivateProfileString32A( sectionA, entryA, def_valA,
813 bufferA, len, filenameA );
814 lstrcpynAtoW( buffer, bufferA, len );
815 HeapFree( GetProcessHeap(), 0, sectionA );
816 HeapFree( GetProcessHeap(), 0, entryA );
817 HeapFree( GetProcessHeap(), 0, filenameA );
818 HeapFree( GetProcessHeap(), 0, def_valA );
819 HeapFree( GetProcessHeap(), 0, bufferA);
820 return ret;
825 /***********************************************************************
826 * WritePrivateProfileString16 (KERNEL.129)
828 BOOL16 WritePrivateProfileString16(LPCSTR section,LPCSTR entry,LPCSTR string,
829 LPCSTR filename)
831 return WritePrivateProfileString32A(section,entry,string,filename);
834 /***********************************************************************
835 * WritePrivateProfileString32A (KERNEL32.582)
837 BOOL32 WritePrivateProfileString32A(LPCSTR section,LPCSTR entry,LPCSTR string,
838 LPCSTR filename )
840 if (!PROFILE_Open( filename )) return FALSE;
841 if (!section) return PROFILE_FlushFile();
842 return PROFILE_SetString( section, entry, string );
845 /***********************************************************************
846 * WritePrivateProfileString32W (KERNEL32.583)
848 BOOL32 WritePrivateProfileString32W( LPCWSTR section, LPCWSTR entry,
849 LPCWSTR string, LPCWSTR filename )
851 LPSTR sectionA = HEAP_strdupWtoA( GetProcessHeap(), 0, section );
852 LPSTR entryA = HEAP_strdupWtoA( GetProcessHeap(), 0, entry );
853 LPSTR stringA = HEAP_strdupWtoA( GetProcessHeap(), 0, string );
854 LPSTR filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename );
855 BOOL32 res = WritePrivateProfileString32A( sectionA, entryA,
856 stringA, filenameA );
857 HeapFree( GetProcessHeap(), 0, sectionA );
858 HeapFree( GetProcessHeap(), 0, entryA );
859 HeapFree( GetProcessHeap(), 0, stringA );
860 HeapFree( GetProcessHeap(), 0, filenameA );
861 return res;
865 /***********************************************************************
866 * WriteOutProfiles (KERNEL.315)
868 void WriteOutProfiles(void)
870 PROFILE_FlushFile();