@ -81,11 +81,13 @@ char *
IceAuthFileName ( )
IceAuthFileName ( )
{
{
static char baseICEauthority [ ] = " ICEauthority " ;
# ifdef _WIN32
# ifdef _WIN32
static char slashDotICEauthority [ ] = " \\ .ICEauthority " ;
static char pathSep [ ] = " \\ " ;
# else
# else
static char slashDotICEauthority [ ] = " / .ICEauthority " ;
static char pathSep [ ] = " / " ;
# endif
# endif
char fileSep [ 2 ] ;
char * name ;
char * name ;
static char * buf ;
static char * buf ;
static int bsize ;
static int bsize ;
@ -95,37 +97,70 @@ IceAuthFileName ()
# endif
# endif
name = getenv ( " ICEAUTHORITY " ) ;
name = getenv ( " ICEAUTHORITY " ) ;
if ( name )
if ( name & & name [ 0 ] )
return ( name ) ;
return ( name ) ;
name = getenv ( " HOME " ) ;
name = getenv ( " XDG_RUNTIME_DIR " ) ;
if ( name & & name [ 0 ] )
{
char * testBuf ;
strcpy ( fileSep , " " ) ;
size = strlen ( name ) + strlen ( pathSep ) + strlen ( fileSep ) + strlen ( baseICEauthority ) + 1 ;
testBuf = malloc ( size ) ;
if ( ! testBuf )
{
return ( NULL ) ;
}
snprintf ( testBuf , size , " %s%s%s%s " , name , pathSep , fileSep , baseICEauthority ) ;
if ( access ( testBuf , F_OK ) )
{
name = NULL ;
}
free ( testBuf ) ;
}
if ( ! name )
if ( ! name | | ! name [ 0 ] )
{
{
name = getenv ( " HOME " ) ;
strcpy ( fileSep , " . " ) ;
# ifdef _WIN32
# ifdef _WIN32
if ( ! name | | ! name [ 0 ] )
{
if ( name = getenv ( " HOMEDRIVE " ) )
if ( name = getenv ( " HOMEDRIVE " ) )
{
{
strcpy ( dir , name ) ;
strcpy ( dir , name ) ;
if ( name = getenv ( " HOMEPATH " ) )
if ( name = getenv ( " HOMEPATH " ) )
{
strcat ( dir , name ) ;
strcat ( dir , name ) ;
}
}
name = dir ;
}
else
else
{
{
if ( name = getenv ( " USERPROFILE " ) )
name = getenv ( " USERPROFILE " ) ;
strcpy ( dir , name ) ;
}
}
}
name = dir ;
if ( ! name )
# endif
# endif
# ifdef __EMX__
# ifdef __EMX__
if ( ! name | | ! name [ 0 ] )
{
strcpy ( dir , " c: " ) ;
strcpy ( dir , " c: " ) ;
name = dir ;
name = dir ;
if ( ! name )
}
# endif
# endif
}
if ( ! name | | ! name [ 0 ] )
{
return ( NULL ) ;
return ( NULL ) ;
}
}
size = strlen ( name ) + strlen ( & slashDotICEauthority [ 1 ] ) + 2 ;
/* Special case for "/". We will add our own '/' later. */
if ( strcmp ( name , pathSep ) = = 0 )
{
name + + ;
}
size = strlen ( name ) + strlen ( pathSep ) + strlen ( fileSep ) + strlen ( baseICEauthority ) + 1 ;
if ( size > bsize )
if ( size > bsize )
{
{
@ -137,8 +172,7 @@ IceAuthFileName ()
bsize = size ;
bsize = size ;
}
}
strcpy ( buf , name ) ;
snprintf ( buf , bsize , " %s%s%s%s " , name , pathSep , fileSep , baseICEauthority ) ;
strcat ( buf , slashDotICEauthority + ( name [ 1 ] = = ' \0 ' ? 1 : 0 ) ) ;
return ( buf ) ;
return ( buf ) ;
}
}