Commit de1d5ad4 authored by Alexandre Julliard's avatar Alexandre Julliard

Added support for WINEPREFIX environment variable.

parent 54fe8380
......@@ -25,7 +25,6 @@
#include "file.h"
#include "heap.h"
#include "debugtools.h"
#include "xmalloc.h"
#include "options.h"
#include "server.h"
......@@ -79,7 +78,6 @@ 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 const WCHAR wininiW[] = { 'w','i','n','.','i','n','i',0 };
......@@ -88,36 +86,6 @@ static CRITICAL_SECTION PROFILE_CritSect;
static const char hex[16] = "0123456789ABCDEF";
/***********************************************************************
* 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
*
* Copy the content of an entry into a buffer, removing quotes, and possibly
......@@ -501,7 +469,7 @@ static BOOL PROFILE_FlushFile(void)
{
/* Try to create it in $HOME/.wine */
/* FIXME: this will need a more general solution */
strcpy( buffer, PROFILE_GetConfigDir() );
strcpy( buffer, get_config_dir() );
p = buffer + strlen(buffer);
*p++ = '/';
strcpy( p, strrchr( CurProfile->dos_name, '\\' ) + 1 );
......@@ -635,7 +603,7 @@ static BOOL PROFILE_Open( LPCSTR filename )
/* Try to open the profile file, first in $HOME/.wine */
/* FIXME: this will need a more general solution */
strcpy( buffer, PROFILE_GetConfigDir() );
strcpy( buffer, get_config_dir() );
p = buffer + strlen(buffer);
*p++ = '/';
strcpy( p, strrchr( newdos_name, '\\' ) + 1 );
......
......@@ -75,7 +75,6 @@ extern void OPTIONS_ParseOptions( int argc, char *argv[] );
/* 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,
......
......@@ -1227,6 +1227,7 @@ enum request
extern unsigned int server_call_noerr( enum request req );
extern unsigned int server_call_fd( enum request req, int fd_out, int *fd_in );
extern void server_protocol_error( const char *err, ... ) WINE_NORETURN;
extern const char *get_config_dir(void);
/* get a pointer to the request buffer */
static inline void * WINE_UNUSED get_req_buffer(void)
......
......@@ -10,6 +10,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
......@@ -36,6 +37,7 @@
#define SCM_RIGHTS 1
#endif
#define CONFDIR "/.wine" /* directory for Wine config relative to $HOME */
#define SERVERDIR "/wineserver-" /* server socket directory (hostname appended) */
#define SOCKETNAME "socket" /* name of the socket file */
......@@ -286,6 +288,43 @@ unsigned int server_call_fd( enum request req, int fd_out, int *fd_in )
/***********************************************************************
* get_config_dir
*
* Return the configuration directory ($WINEPREFIX or $HOME/.wine)
*/
const char *get_config_dir(void)
{
static char *confdir;
if (!confdir)
{
const char *prefix = getenv( "WINEPREFIX" );
if (prefix)
{
int len = strlen(prefix);
if (!(confdir = strdup( prefix ))) fatal_error( "out of memory\n" );
if (len > 1 && confdir[len-1] == '/') confdir[len-1] = 0;
}
else
{
const char *home = getenv( "HOME" );
if (!home)
{
struct passwd *pwd = getpwuid( getuid() );
if (!pwd) fatal_error( "could not find your home directory\n" );
home = pwd->pw_dir;
}
if (!(confdir = malloc( strlen(home) + strlen(CONFDIR) + 1 )))
fatal_error( "out of memory\n" );
strcpy( confdir, home );
strcat( confdir, CONFDIR );
}
mkdir( confdir, 0755 ); /* just in case */
}
return confdir;
}
/***********************************************************************
* start_server
*
* Start a new wine server.
......@@ -406,7 +445,7 @@ int CLIENT_InitServer(void)
/* get the server directory name */
if (gethostname( hostname, sizeof(hostname) ) == -1) fatal_perror( "gethostname" );
configdir = PROFILE_GetConfigDir();
configdir = get_config_dir();
serverdir = malloc( strlen(configdir) + strlen(SERVERDIR) + strlen(hostname) + 1 );
if (!serverdir) fatal_error( "out of memory\n" );
strcpy( serverdir, configdir );
......
......@@ -302,23 +302,33 @@ static void master_socket_destroy( struct object *obj )
socket_cleanup();
}
/* return the configuration directory ($HOME/.wine) */
/* return the configuration directory ($WINEPREFIX or $HOME/.wine) */
static const char *get_config_dir(void)
{
static char *confdir;
if (!confdir)
{
const char *home = getenv( "HOME" );
if (!home)
const char *prefix = getenv( "WINEPREFIX" );
if (prefix)
{
struct passwd *pwd = getpwuid( getuid() );
if (!pwd) fatal_error( "could not find your home directory\n" );
home = pwd->pw_dir;
int len = strlen(prefix);
if (!(confdir = strdup( prefix ))) fatal_error( "out of memory\n" );
if (len > 1 && confdir[len-1] == '/') confdir[len-1] = 0;
}
else
{
const char *home = getenv( "HOME" );
if (!home)
{
struct passwd *pwd = getpwuid( getuid() );
if (!pwd) fatal_error( "could not find your home directory\n" );
home = pwd->pw_dir;
}
if (!(confdir = malloc( strlen(home) + strlen(CONFDIR) + 1 )))
fatal_error( "out of memory\n" );
strcpy( confdir, home );
strcat( confdir, CONFDIR );
}
if (!(confdir = malloc( strlen(home) + strlen(CONFDIR) + 1 )))
fatal_error( "out of memory\n" );
strcpy( confdir, home );
strcat( confdir, CONFDIR );
mkdir( confdir, 0755 ); /* just in case */
}
return confdir;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment