From 647876e5986afdb2d6e03c5d9f12de5a3f1215c5 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 25 Jan 2000 01:35:01 +0000 Subject: [PATCH] Added PROFILE_GetConfigDir function. --- files/profile.c | 75 ++++++++++++++++++++++++++++++++++++++----------------- include/options.h | 1 + 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/files/profile.c b/files/profile.c index f14abdc3640..bf46d4dac3d 100644 --- a/files/profile.c +++ b/files/profile.c @@ -8,8 +8,10 @@ #include #include #include - #include +#include +#include +#include #include "winbase.h" #include "winerror.h" @@ -19,6 +21,7 @@ #include "file.h" #include "heap.h" #include "debugtools.h" +#include "xmalloc.h" #include "options.h" DEFAULT_DEBUG_CHANNEL(profile) @@ -71,11 +74,43 @@ static char PROFILE_WineIniUsed[MAX_PATHNAME_LEN] = ""; #define IS_ENTRY_COMMENT(str) ((str)[0] == ';') #define WINE_INI_GLOBAL ETCDIR "/wine.conf" +#define WINE_CONFIG_DIR "/.wine" /* config dir inside $HOME */ static LPCWSTR wininiW = NULL; static CRITICAL_SECTION PROFILE_CritSect; + +/*********************************************************************** + * PROFILE_GetConfigDir + * + * Return the name of the configuration directory ($HOME/.wine) + */ +const char *PROFILE_GetConfigDir(void) +{ + static char *confdir; + if (!confdir) + { + const char *home = getenv( "HOME" ); + if (!home) + { + struct passwd *pwd = getpwuid( getuid() ); + if (!pwd) + { + fprintf( stderr, "wine: could not find your home directory\n" ); + exit(1); + } + home = pwd->pw_dir; + } + confdir = xmalloc( strlen(home) + strlen(WINE_CONFIG_DIR) + 1 ); + strcpy( confdir, home ); + strcat( confdir, WINE_CONFIG_DIR ); + mkdir( confdir, 0755 ); /* create it just in case */ + } + return confdir; +} + + /*********************************************************************** * PROFILE_CopyEntry * @@ -379,16 +414,13 @@ static BOOL PROFILE_FlushFile(void) { /* Try to create it in $HOME/.wine */ /* FIXME: this will need a more general solution */ - if ((p = getenv( "HOME" )) != NULL) - { - strcpy( buffer, p ); - strcat( buffer, "/.wine/" ); - p = buffer + strlen(buffer); - strcpy( p, strrchr( CurProfile->dos_name, '\\' ) + 1 ); - CharLowerA( p ); - file = fopen( buffer, "w" ); - unix_name = buffer; - } + strcpy( buffer, PROFILE_GetConfigDir() ); + p = buffer + strlen(buffer); + *p++ = '/'; + strcpy( p, strrchr( CurProfile->dos_name, '\\' ) + 1 ); + CharLowerA( p ); + file = fopen( buffer, "w" ); + unix_name = buffer; } if (!file) @@ -516,19 +548,16 @@ static BOOL PROFILE_Open( LPCSTR filename ) /* Try to open the profile file, first in $HOME/.wine */ /* FIXME: this will need a more general solution */ - if ((p = getenv( "HOME" )) != NULL) + strcpy( buffer, PROFILE_GetConfigDir() ); + p = buffer + strlen(buffer); + *p++ = '/'; + strcpy( p, strrchr( newdos_name, '\\' ) + 1 ); + CharLowerA( p ); + if ((file = fopen( buffer, "r" ))) { - strcpy( buffer, p ); - strcat( buffer, "/.wine/" ); - p = buffer + strlen(buffer); - strcpy( p, strrchr( newdos_name, '\\' ) + 1 ); - CharLowerA( p ); - if ((file = fopen( buffer, "r" ))) - { - TRACE("(%s): found it in %s\n", - filename, buffer ); - CurProfile->unix_name = HEAP_strdupA( SystemHeap, 0, buffer ); - } + TRACE("(%s): found it in %s\n", + filename, buffer ); + CurProfile->unix_name = HEAP_strdupA( SystemHeap, 0, buffer ); } if (!file) diff --git a/include/options.h b/include/options.h index c6278ec70fd..edd49c21eb4 100644 --- a/include/options.h +++ b/include/options.h @@ -84,6 +84,7 @@ extern struct options Options; /* Profile functions */ +extern const char *PROFILE_GetConfigDir(void); extern int PROFILE_LoadWineIni(void); extern void PROFILE_UsageWineIni(void); extern int PROFILE_GetWineIniString( const char *section, const char *key_name, -- 2.11.4.GIT