4 * Copyright 1993 Miguel de Icaza
5 * Copyright 1996 Alexandre Julliard
19 typedef struct tagPROFILEKEY
23 struct tagPROFILEKEY
*next
;
26 typedef struct tagPROFILESECTION
29 struct tagPROFILEKEY
*key
;
30 struct tagPROFILESECTION
*next
;
37 PROFILESECTION
*section
;
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 /***********************************************************************
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
,
74 if ((*value
== '\'') || (*value
== '\"'))
76 if (value
[1] && (value
[strlen(value
)-1] == *value
)) quote
= *value
++;
81 lstrcpyn32A( buffer
, value
, len
);
82 if (quote
&& (len
>= strlen(value
))) buffer
[strlen(buffer
)-1] = '\0';
86 for (p
= value
; (*p
&& (len
> 1)); *buffer
++ = *p
++, len
-- )
88 if ((*p
== '$') && (p
[1] == '{'))
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
);
108 /***********************************************************************
111 * Save a profile tree to a file.
113 static void PROFILE_Save( FILE *file
, PROFILESECTION
*section
)
117 for ( ; section
; section
= section
->next
)
119 if (section
->name
) fprintf( file
, "\r\n[%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 /***********************************************************************
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 /***********************************************************************
159 * Load a profile tree from a file.
161 static PROFILESECTION
*PROFILE_Load( FILE *file
)
163 char buffer
[PROFILE_MAX_LINE_LEN
];
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
))
180 p
= buffer
+ strlen(buffer
) - 1;
181 while ((p
> buffer
) && ((*p
== '\n') || isspace(*p
))) *p
-- = '\0';
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",
195 section
= HEAP_xalloc( SystemHeap
, 0, sizeof(*section
) );
196 section
->name
= HEAP_strdupA( SystemHeap
, 0, p
);
198 section
->next
= NULL
;
199 *prev_section
= section
;
200 prev_section
= §ion
->next
;
201 prev_key
= §ion
->key
;
205 if ((p2
= strchr( p
, '=' )) != NULL
)
208 while ((p3
> p
) && isspace(*p3
)) *p3
-- = '\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
= p2
? HEAP_strdupA( SystemHeap
, 0, p2
) : NULL
;
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
)
238 if ((*section
)->name
&& !lstrcmpi32A( (*section
)->name
, name
))
240 PROFILESECTION
*to_del
= *section
;
241 *section
= to_del
->next
;
243 PROFILE_Free( to_del
);
246 section
= &(*section
)->next
;
252 /***********************************************************************
255 * Delete a key from a profile tree.
257 static BOOL32
PROFILE_DeleteKey( PROFILESECTION
**section
,
258 LPCSTR section_name
, LPCSTR key_name
)
262 if ((*section
)->name
&& !lstrcmpi32A( (*section
)->name
, section_name
))
264 PROFILEKEY
**key
= &(*section
)->key
;
267 if (!lstrcmpi32A( (*key
)->name
, key_name
))
269 PROFILEKEY
*to_del
= *key
;
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
);
279 section
= &(*section
)->next
;
285 /***********************************************************************
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
)
296 if ((*section
)->name
&& !lstrcmpi32A( (*section
)->name
, section_name
))
298 PROFILEKEY
**key
= &(*section
)->key
;
301 if (!lstrcmpi32A( (*key
)->name
, key_name
)) return *key
;
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
;
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 /***********************************************************************
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
;
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
)
344 strcat( buffer
, "/.wine/" );
345 p
= buffer
+ strlen(buffer
);
346 strcpy( p
, strrchr( CurProfile
.dos_name
, '\\' ) + 1 );
348 file
= fopen( buffer
, "w" );
355 fprintf( stderr
, "Warning: could not save profile file %s\n",
356 CurProfile
.dos_name
);
360 dprintf_profile( stddeb
, "Saving '%s' into '%s'\n",
361 CurProfile
.dos_name
, unix_name
);
362 PROFILE_Save( file
, CurProfile
.section
);
364 CurProfile
.changed
= FALSE
;
369 /***********************************************************************
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
;
381 if (CurProfile
.filename
&& !strcmp( filename
, CurProfile
.filename
))
383 dprintf_profile( stddeb
, "PROFILE_Open(%s): already opened\n",
388 if (strchr( filename
, '/' ) || strchr( filename
, '\\' ) ||
389 strchr( filename
, ':' ))
391 if (!DOSFS_GetFullName( filename
, FALSE
, &full_name
)) return FALSE
;
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",
408 /* Flush the previous profile */
410 newdos_name
= HEAP_strdupA( SystemHeap
, 0, full_name
.short_name
);
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
)
426 strcat( buffer
, "/.wine/" );
427 p
= buffer
+ strlen(buffer
);
428 strcpy( p
, strrchr( newdos_name
, '\\' ) + 1 );
430 if ((file
= fopen( buffer
, "r" )))
432 dprintf_profile( stddeb
, "PROFILE_Open(%s): found it in %s\n",
434 CurProfile
.unix_name
= HEAP_strdupA( SystemHeap
, 0, buffer
);
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
);
449 CurProfile
.section
= PROFILE_Load( file
);
454 /* Does not exist yet, we will create it in PROFILE_FlushFile */
455 fprintf( stderr
, "Warning: profile file %s not found\n", newdos_name
);
461 /***********************************************************************
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
)
472 if (section
->name
&& !lstrcmpi32A( section
->name
, section_name
))
475 for (key
= section
->key
; key
; key
= key
->next
)
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;
484 return oldlen
- len
+ 1;
486 section
= section
->next
;
488 buffer
[0] = buffer
[1] = '\0';
493 /***********************************************************************
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
&& key_name
[0])
506 key
= PROFILE_Find( &CurProfile
.section
, section
, key_name
, FALSE
);
507 PROFILE_CopyEntry( buffer
, (key
&& key
->value
) ? key
->value
: def_val
,
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 /***********************************************************************
520 * Set a profile string.
522 static BOOL32
PROFILE_SetString( LPCSTR section_name
, LPCSTR key_name
,
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
,
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
,
545 dprintf_profile( stddeb
, "PROFILE_SetString('%s','%s','%s'): ",
546 section_name
, key_name
, value
);
547 if (!key
) return FALSE
;
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
;
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
)
576 PROFILEKEY
*key
= PROFILE_Find(&WineProfile
, section
, key_name
, FALSE
);
577 PROFILE_CopyEntry( buffer
, (key
&& key
->value
) ? key
->value
: def
,
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
)
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 */
607 /******************************************************************************
609 * int PROFILE_EnumerateWineIniSection(
610 * char const *section, // Name of the section to enumerate
611 * void (*cbfn)(char const *key, char const *value, void *user),
612 // Address of the callback function
613 * void *user ) // User-specified pointer.
615 * For each entry in a section in the wine.conf file, this function will
616 * call the specified callback function, informing it of each key and
617 * value. An optional user pointer may be passed to it (if this is not
618 * needed, pass NULL through it and ignore the value in the callback
621 * The callback function must accept three parameters:
622 * The name of the key (char const *)
623 * The value of the key (char const *)
624 * A user-specified parameter (void *)
625 * Note that the first two are char CONST *'s, not char *'s! The callback
626 * MUST not modify these strings!
628 * The return value indicates the number of times the callback function
631 int PROFILE_EnumerateWineIniSection(
633 void (*cbfn
)(char const *, char const *, void *),
636 PROFILESECTION
*scansect
;
640 /* Search for the correct section */
641 for(scansect
= WineProfile
; scansect
; scansect
= scansect
->next
) {
642 if(scansect
->name
&& !lstrcmpi32A(scansect
->name
, section
)) {
644 /* Enumerate each key with the callback */
645 for(scankey
= scansect
->key
; scankey
; scankey
= scankey
->next
) {
647 /* Ignore blank entries -- these shouldn't exist, but let's
649 if(scankey
->name
[0]) {
650 cbfn(scankey
->name
, scankey
->value
, userptr
);
663 /******************************************************************************
665 * int PROFILE_GetWineIniBool(
666 * char const *section,
667 * char const *key_name,
670 * Reads a boolean value from the wine.ini file. This function attempts to
671 * be user-friendly by accepting 'n', 'N' (no), 'f', 'F' (false), or '0'
672 * (zero) for false, 'y', 'Y' (yes), 't', 'T' (true), or '1' (one) for
673 * true. Anything else results in the return of the default value.
675 * This function uses 1 to indicate true, and 0 for false. You can check
676 * for existence by setting def to something other than 0 or 1 and
677 * examining the return value.
679 int PROFILE_GetWineIniBool(
681 char const *key_name
,
687 PROFILE_GetWineIniString(section
, key_name
, "~", key_value
, 2);
689 switch(key_value
[0]) {
710 dprintf_profile(stddeb
, "PROFILE_GetWineIniBool(\"%s\", \"%s\", %s), "
711 "[%c], ret %s.\n", section
, key_name
,
712 def
? "TRUE" : "FALSE", key_value
[0],
713 retval
? "TRUE" : "FALSE");
719 /***********************************************************************
720 * PROFILE_LoadWineIni
722 * Load the wine.ini file.
724 int PROFILE_LoadWineIni(void)
726 char buffer
[MAX_PATHNAME_LEN
];
730 if ((p
= getenv( "HOME" )) != NULL
)
732 lstrcpyn32A(buffer
, p
, MAX_PATHNAME_LEN
- sizeof(PROFILE_WineIniName
));
733 strcat( buffer
, PROFILE_WineIniName
);
734 if ((f
= fopen( buffer
, "r" )) != NULL
)
736 WineProfile
= PROFILE_Load( f
);
741 else fprintf( stderr
, "Warning: could not get $HOME value for config file.\n" );
743 /* Try global file */
745 if ((f
= fopen( WINE_INI_GLOBAL
, "r" )) != NULL
)
747 WineProfile
= PROFILE_Load( f
);
751 fprintf( stderr
, "Can't open configuration file %s or $HOME%s\n",
752 WINE_INI_GLOBAL
, PROFILE_WineIniName
);
757 /***********************************************************************
758 * PROFILE_GetStringItem
760 * Convenience function that turns a string 'xxx, yyy, zzz' into
761 * the 'xxx\0 yyy, zzz' and returns a pointer to the 'yyy, zzz'.
763 char* PROFILE_GetStringItem( char* start
)
767 for (lpchX
= start
, lpch
= NULL
; *lpchX
!= '\0'; lpchX
++ )
771 if( lpch
) *lpch
= '\0'; else *lpchX
= '\0';
773 if( !isspace(*lpchX
) ) return lpchX
;
775 else if( isspace( *lpchX
) && !lpch
) lpch
= lpchX
;
778 if( lpch
) *lpch
= '\0';
783 /********************* API functions **********************************/
785 /***********************************************************************
786 * GetProfileInt16 (KERNEL.57)
788 UINT16 WINAPI
GetProfileInt16( LPCSTR section
, LPCSTR entry
, INT16 def_val
)
790 return GetPrivateProfileInt16( section
, entry
, def_val
, "win.ini" );
794 /***********************************************************************
795 * GetProfileInt32A (KERNEL32.264)
797 UINT32 WINAPI
GetProfileInt32A( LPCSTR section
, LPCSTR entry
, INT32 def_val
)
799 return GetPrivateProfileInt32A( section
, entry
, def_val
, "win.ini" );
802 /***********************************************************************
803 * GetProfileInt32W (KERNEL32.264)
805 UINT32 WINAPI
GetProfileInt32W( LPCWSTR section
, LPCWSTR entry
, INT32 def_val
)
807 if (!wininiW
) wininiW
= HEAP_strdupAtoW( SystemHeap
, 0, "win.ini" );
808 return GetPrivateProfileInt32W( section
, entry
, def_val
, wininiW
);
811 /***********************************************************************
812 * GetProfileString16 (KERNEL.58)
814 INT16 WINAPI
GetProfileString16( LPCSTR section
, LPCSTR entry
, LPCSTR def_val
,
815 LPSTR buffer
, INT16 len
)
817 return GetPrivateProfileString16( section
, entry
, def_val
,
818 buffer
, len
, "win.ini" );
821 /***********************************************************************
822 * GetProfileString32A (KERNEL32.268)
824 INT32 WINAPI
GetProfileString32A( LPCSTR section
, LPCSTR entry
, LPCSTR def_val
,
825 LPSTR buffer
, INT32 len
)
827 return GetPrivateProfileString32A( section
, entry
, def_val
,
828 buffer
, len
, "win.ini" );
831 /***********************************************************************
832 * GetProfileString32W (KERNEL32.269)
834 INT32 WINAPI
GetProfileString32W( LPCWSTR section
, LPCWSTR entry
,
835 LPCWSTR def_val
, LPWSTR buffer
, INT32 len
)
837 if (!wininiW
) wininiW
= HEAP_strdupAtoW( SystemHeap
, 0, "win.ini" );
838 return GetPrivateProfileString32W( section
, entry
, def_val
,
839 buffer
, len
, wininiW
);
842 /***********************************************************************
843 * GetProfileSection32A (KERNEL32.268)
845 INT32 WINAPI
GetProfileSection32A( LPCSTR section
, LPSTR buffer
, INT32 len
)
847 return GetPrivateProfileSection32A( section
, buffer
, len
, "win.ini" );
851 /***********************************************************************
852 * WriteProfileString16 (KERNEL.59)
854 BOOL16 WINAPI
WriteProfileString16( LPCSTR section
, LPCSTR entry
,
857 return WritePrivateProfileString16( section
, entry
, string
, "win.ini" );
860 /***********************************************************************
861 * WriteProfileString32A (KERNEL32.587)
863 BOOL32 WINAPI
WriteProfileString32A( LPCSTR section
, LPCSTR entry
,
866 return WritePrivateProfileString32A( section
, entry
, string
, "win.ini" );
869 /***********************************************************************
870 * WriteProfileString32W (KERNEL32.588)
872 BOOL32 WINAPI
WriteProfileString32W( LPCWSTR section
, LPCWSTR entry
,
875 if (!wininiW
) wininiW
= HEAP_strdupAtoW( SystemHeap
, 0, "win.ini" );
876 return WritePrivateProfileString32W( section
, entry
, string
, wininiW
);
880 /***********************************************************************
881 * GetPrivateProfileInt16 (KERNEL.127)
883 UINT16 WINAPI
GetPrivateProfileInt16( LPCSTR section
, LPCSTR entry
,
884 INT16 def_val
, LPCSTR filename
)
886 long result
=(long)GetPrivateProfileInt32A(section
,entry
,def_val
,filename
);
888 if (result
> 65535) return 65535;
889 if (result
>= 0) return (UINT16
)result
;
890 if (result
< -32768) return -32768;
891 return (UINT16
)(INT16
)result
;
894 /***********************************************************************
895 * GetPrivateProfileInt32A (KERNEL32.251)
897 UINT32 WINAPI
GetPrivateProfileInt32A( LPCSTR section
, LPCSTR entry
,
898 INT32 def_val
, LPCSTR filename
)
904 GetPrivateProfileString32A( section
, entry
, "",
905 buffer
, sizeof(buffer
), filename
);
906 if (!buffer
[0]) return (UINT32
)def_val
;
907 result
= strtol( buffer
, &p
, 0 );
908 if (p
== buffer
) return 0; /* No digits at all */
909 return (UINT32
)result
;
912 /***********************************************************************
913 * GetPrivateProfileInt32W (KERNEL32.252)
915 UINT32 WINAPI
GetPrivateProfileInt32W( LPCWSTR section
, LPCWSTR entry
,
916 INT32 def_val
, LPCWSTR filename
)
918 LPSTR sectionA
= HEAP_strdupWtoA( GetProcessHeap(), 0, section
);
919 LPSTR entryA
= HEAP_strdupWtoA( GetProcessHeap(), 0, entry
);
920 LPSTR filenameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
921 UINT32 res
= GetPrivateProfileInt32A(sectionA
, entryA
, def_val
, filenameA
);
922 HeapFree( GetProcessHeap(), 0, sectionA
);
923 HeapFree( GetProcessHeap(), 0, filenameA
);
924 HeapFree( GetProcessHeap(), 0, entryA
);
928 /***********************************************************************
929 * GetPrivateProfileString16 (KERNEL.128)
931 INT16 WINAPI
GetPrivateProfileString16( LPCSTR section
, LPCSTR entry
,
932 LPCSTR def_val
, LPSTR buffer
,
933 INT16 len
, LPCSTR filename
)
935 return GetPrivateProfileString32A(section
,entry
,def_val
,buffer
,len
,filename
);
938 /***********************************************************************
939 * GetPrivateProfileString32A (KERNEL32.255)
941 INT32 WINAPI
GetPrivateProfileString32A( LPCSTR section
, LPCSTR entry
,
942 LPCSTR def_val
, LPSTR buffer
,
943 INT32 len
, LPCSTR filename
)
946 filename
= "win.ini";
947 if (PROFILE_Open( filename
))
948 return PROFILE_GetString( section
, entry
, def_val
, buffer
, len
);
949 lstrcpyn32A( buffer
, def_val
, len
);
950 return strlen( buffer
);
953 /***********************************************************************
954 * GetPrivateProfileString32W (KERNEL32.256)
956 INT32 WINAPI
GetPrivateProfileString32W( LPCWSTR section
, LPCWSTR entry
,
957 LPCWSTR def_val
, LPWSTR buffer
,
958 INT32 len
, LPCWSTR filename
)
960 LPSTR sectionA
= HEAP_strdupWtoA( GetProcessHeap(), 0, section
);
961 LPSTR entryA
= HEAP_strdupWtoA( GetProcessHeap(), 0, entry
);
962 LPSTR filenameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
963 LPSTR def_valA
= HEAP_strdupWtoA( GetProcessHeap(), 0, def_val
);
964 LPSTR bufferA
= HeapAlloc( GetProcessHeap(), 0, len
);
965 INT32 ret
= GetPrivateProfileString32A( sectionA
, entryA
, def_valA
,
966 bufferA
, len
, filenameA
);
967 lstrcpynAtoW( buffer
, bufferA
, len
);
968 HeapFree( GetProcessHeap(), 0, sectionA
);
969 HeapFree( GetProcessHeap(), 0, entryA
);
970 HeapFree( GetProcessHeap(), 0, filenameA
);
971 HeapFree( GetProcessHeap(), 0, def_valA
);
972 HeapFree( GetProcessHeap(), 0, bufferA
);
976 /***********************************************************************
977 * GetPrivateProfileSection32A (KERNEL32.255)
979 INT32 WINAPI
GetPrivateProfileSection32A( LPCSTR section
, LPSTR buffer
,
980 INT32 len
, LPCSTR filename
)
982 if (PROFILE_Open( filename
))
983 return PROFILE_GetString( section
, NULL
, NULL
, buffer
, len
);
987 /***********************************************************************
988 * WritePrivateProfileString16 (KERNEL.129)
990 BOOL16 WINAPI
WritePrivateProfileString16( LPCSTR section
, LPCSTR entry
,
991 LPCSTR string
, LPCSTR filename
)
993 return WritePrivateProfileString32A(section
,entry
,string
,filename
);
996 /***********************************************************************
997 * WritePrivateProfileString32A (KERNEL32.582)
999 BOOL32 WINAPI
WritePrivateProfileString32A( LPCSTR section
, LPCSTR entry
,
1000 LPCSTR string
, LPCSTR filename
)
1002 if (!PROFILE_Open( filename
)) return FALSE
;
1003 if (!section
) return PROFILE_FlushFile();
1004 return PROFILE_SetString( section
, entry
, string
);
1007 /***********************************************************************
1008 * WritePrivateProfileString32W (KERNEL32.583)
1010 BOOL32 WINAPI
WritePrivateProfileString32W( LPCWSTR section
, LPCWSTR entry
,
1011 LPCWSTR string
, LPCWSTR filename
)
1013 LPSTR sectionA
= HEAP_strdupWtoA( GetProcessHeap(), 0, section
);
1014 LPSTR entryA
= HEAP_strdupWtoA( GetProcessHeap(), 0, entry
);
1015 LPSTR stringA
= HEAP_strdupWtoA( GetProcessHeap(), 0, string
);
1016 LPSTR filenameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
1017 BOOL32 res
= WritePrivateProfileString32A( sectionA
, entryA
,
1018 stringA
, filenameA
);
1019 HeapFree( GetProcessHeap(), 0, sectionA
);
1020 HeapFree( GetProcessHeap(), 0, entryA
);
1021 HeapFree( GetProcessHeap(), 0, stringA
);
1022 HeapFree( GetProcessHeap(), 0, filenameA
);
1026 /***********************************************************************
1027 * WritePrivateProfileSection32A (KERNEL32)
1029 BOOL32 WINAPI
WritePrivateProfileSection32A( LPCSTR section
,
1030 LPCSTR string
, LPCSTR filename
)
1032 char *p
=(char*)string
;
1034 fprintf( stdnimp
,"WritePrivateProfileSection32A empty stup\n");
1035 if (debugging_profile
) {
1036 fprintf(stddeb
,"file(%s) => [%s]\n", filename
,section
);
1038 fprintf(stddeb
,"%s\n",p
);
1048 /***********************************************************************
1049 * WriteOutProfiles (KERNEL.315)
1051 void WINAPI
WriteOutProfiles(void)
1053 PROFILE_FlushFile();