]> git.sesse.net Git - vlc/commitdiff
* moved GetConfigurationFromCmdLine() into configuration.c and renamed it
authorGildas Bazin <gbazin@videolan.org>
Thu, 21 Mar 2002 07:11:57 +0000 (07:11 +0000)
committerGildas Bazin <gbazin@videolan.org>
Thu, 21 Mar 2002 07:11:57 +0000 (07:11 +0000)
   into config_LoadCmdLine()
* config_GetHomeDir doesn't use getpwuid_r anymore as this was creating
   some problems on solaris. This function now uses getpwuid and is called
   only once to store the home directory into the p_main structure.

configure
configure.in
include/configuration.h
include/defs.h.in
include/main.h
src/interface/main.c
src/misc/configuration.c

index 31f19a43c9362517670e6a617b7d5190893f20e5..7781d05633c6b2983eb707b7281788f510cf905f 100755 (executable)
--- a/configure
+++ b/configure
@@ -3958,7 +3958,7 @@ else
 fi
 done
 
-for ac_func in getpwuid_r getpwuid
+for ac_func in getpwuid
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:3965: checking for $ac_func" >&5
index 6bbdebf4f0c88b01558ab0fc2274ad3996db919a..79cd14d10a5c6cd2f05ac429b8eee0798c6acf78 100644 (file)
@@ -108,7 +108,7 @@ AC_CHECK_FUNCS(swab)
 AC_CHECK_FUNCS([memalign valloc])
 
 AC_CHECK_FUNCS(sigrelse)
-AC_CHECK_FUNCS(getpwuid_r getpwuid)
+AC_CHECK_FUNCS(getpwuid)
 
 dnl Check for getopt
 NEED_GETOPT=0
index f2e7e385126f4d84b530ecb91b213ac9e2933bd0..052a9fdaf3955293b5664faaf46999381274fd50 100644 (file)
@@ -4,7 +4,7 @@
  * It includes functions allowing to declare, get or set configuration options.
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: configuration.h,v 1.3 2002/03/16 01:40:58 gbazin Exp $
+ * $Id: configuration.h,v 1.4 2002/03/21 07:11:57 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -73,6 +73,9 @@ int config_LoadConfigFile( const char *psz_module_name );
 int config_SaveConfigFile( const char *psz_module_name );
 module_config_t *config_FindConfig( const char *psz_name );
 module_config_t *config_Duplicate ( module_t *p_module );
+char *config_GetHomeDir( void );
+int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
+                        boolean_t b_ignore_errors );
 
 #else
 #   define config_GetIntVariable p_symbols->config_GetIntVariable
index 2e5805bbe7b86d015a616818416c87b29f927d0d..f9f060fc4223617921f728edc8c1921107128ab5 100644 (file)
@@ -91,9 +91,6 @@
 /* Define if you have the getpwuid function.  */
 #undef HAVE_GETPWUID
 
-/* Define if you have the getpwuid_r function.  */
-#undef HAVE_GETPWUID_R
-
 /* Define if you have the gettimeofday function.  */
 #undef HAVE_GETTIMEOFDAY
 
index d3092ad5818d50c2a04817e066a2092d407f8e50..70d79203acc272168becbc3846938e23a994a85f 100644 (file)
@@ -3,7 +3,7 @@
  * Declaration and extern access to global program object.
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: main.h,v 1.32 2002/03/16 01:40:58 gbazin Exp $
+ * $Id: main.h,v 1.33 2002/03/21 07:11:57 gbazin Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *
@@ -39,6 +39,7 @@ typedef struct main_s
     int                    i_argc;           /* command line arguments count */
     char **                ppsz_argv;              /* command line arguments */
     char *                 psz_arg0;         /* program name (whithout path) */
+    char *                 psz_homedir;             /* user's home directory */
 
     u32                    i_cpu_capabilities;             /* CPU extensions */
     int                    i_warning_level;        /* warning messages level */
index a05b490754bed0aa3794bf97bfa261c9f3ac8178..9ef46add7343170036435b80ab918062d5c10ac1 100644 (file)
@@ -4,7 +4,7 @@
  * and spawn threads.
  *****************************************************************************
  * Copyright (C) 1998-2001 VideoLAN
- * $Id: main.c,v 1.165 2002/03/19 00:30:44 sam Exp $
+ * $Id: main.c,v 1.166 2002/03/21 07:11:57 gbazin Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -401,8 +401,6 @@ vout_bank_t   *p_vout_bank;
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  GetConfigurationFromCmdLine ( int *pi_argc, char *ppsz_argv[],
-                                          boolean_t b_ignore_errors );
 static int  GetFilenames                ( int i_argc, char *ppsz_argv[] );
 static void Usage                       ( const char *psz_module_name );
 static void ListModules                 ( void );
@@ -529,7 +527,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
     p_module_bank->first = &help_module;
     /* end hack */
 
-    if( GetConfigurationFromCmdLine( &i_argc, ppsz_argv, 1 ) )
+    if( config_LoadCmdLine( &i_argc, ppsz_argv, 1 ) )
     {
         intf_MsgDestroy();
         return( errno );
@@ -559,7 +557,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
 
     /*
      * Load the builtins and plugins into the module_bank.
-     * We have to do it before GetConfiguration() because this also gets the
+     * We have to do it before config_Load*() because this also gets the
      * list of configuration options exported by each plugin and loads their
      * default values.
      */
@@ -604,13 +602,21 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
      * Override default configuration with config file settings
      */
     vlc_mutex_init( &p_main->config_lock );
+    p_main->psz_homedir = config_GetHomeDir();
     config_LoadConfigFile( NULL );
 
     /*
      * Override configuration with command line settings
      */
-    if( GetConfigurationFromCmdLine( &i_argc, ppsz_argv, 0 ) )
+    if( config_LoadCmdLine( &i_argc, ppsz_argv, 0 ) )
     {
+#ifdef WIN32
+        ShowConsole();
+        /* Pause the console because it's destroyed when we exit */
+        intf_Msg( "The command line options couldn't be loaded, check that "
+                  "they are valid.\nPress the RETURN key to continue..." );
+        getchar();
+#endif
         intf_MsgDestroy();
         return( errno );
     }
@@ -799,188 +805,6 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
 
 /* following functions are local */
 
-/*****************************************************************************
- * GetConfigurationFromCmdLine: parse command line
- *****************************************************************************
- * Parse command line for configuration. If the inline help is requested, the
- * function Usage() is called and the function returns -1 (causing main() to
- * exit).
- * Now that the module_bank has been initialized, we can dynamically
- * generate the longopts structure used by getops. We have to do it this way
- * because we don't know (and don't want to know) in advance the configuration
- * options used (ie. exported) by each module.
- *****************************************************************************/
-static int GetConfigurationFromCmdLine( int *pi_argc, char *ppsz_argv[],
-                                        boolean_t b_ignore_errors )
-{
-    int i_cmd, i, i_index, i_longopts_size;
-    module_t *p_module;
-    struct option *p_longopts;
-
-    /* Short options */
-    const char *psz_shortopts = "hHvlp:";
-
-    /* Set default configuration and copy arguments */
-    p_main->i_argc    = *pi_argc;
-    p_main->ppsz_argv = ppsz_argv;
-
-    p_main->p_channel = NULL;
-
-#ifdef SYS_DARWIN
-    /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
-     * is the PSN - process serial number (a unique PID-ish thingie)
-     * still ok for real Darwin & when run from command line */
-    if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
-                                        /* for example -psn_0_9306113 */
-    {
-        /* GDMF!... I can't do this or else the MacOSX window server will
-         * not pick up the PSN and not register the app and we crash...
-         * hence the following kludge otherwise we'll get confused w/ argv[1]
-         * being an input file name */
-#if 0
-        ppsz_argv[ 1 ] = NULL;
-#endif
-        *pi_argc = *pi_argc - 1;
-        pi_argc--;
-        return( 0 );
-    }
-#endif
-
-
-    /*
-     * Generate the longopts structure used by getopt_long
-     */
-    i_longopts_size = 0;
-    for( p_module = p_module_bank->first;
-         p_module != NULL ;
-         p_module = p_module->next )
-    {
-        /* count the number of exported configuration options (to allocate
-         * longopts). */
-        i_longopts_size += p_module->i_config_items;
-    }
-
-    p_longopts = (struct option *)malloc( sizeof(struct option)
-                                          * (i_longopts_size + 1) );
-    if( p_longopts == NULL )
-    {
-        intf_ErrMsg( "GetConfigurationFromCmdLine error: "
-                     "can't allocate p_longopts" );
-        return( -1 );
-    }
-
-    /* Fill the longopts structure */
-    i_index = 0;
-    for( p_module = p_module_bank->first ;
-         p_module != NULL ;
-         p_module = p_module->next )
-    {
-        for( i = 0; i < p_module->i_config_lines; i++ )
-        {
-            if( p_module->p_config[i].i_type & MODULE_CONFIG_HINT )
-                /* ignore hints */
-                continue;
-            p_longopts[i_index].name = p_module->p_config[i].psz_name;
-            p_longopts[i_index].has_arg =
-                (p_module->p_config[i].i_type == MODULE_CONFIG_ITEM_BOOL)?
-                                               no_argument : required_argument;
-            p_longopts[i_index].flag = 0;
-            p_longopts[i_index].val = 0;
-            i_index++;
-        }
-    }
-    /* Close the longopts structure */
-    memset( &p_longopts[i_index], 0, sizeof(struct option) );
-
-
-    /*
-     * Parse the command line options
-     */
-    opterr = 0;
-    optind = 1;
-    while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts,
-                                  p_longopts, &i_index ) ) != EOF )
-    {
-
-        if( i_cmd == 0 )
-        {
-            /* A long option has been recognized */
-
-            module_config_t *p_conf;
-
-            /* Store the configuration option */
-            p_conf = config_FindConfig( p_longopts[i_index].name );
-
-            switch( p_conf->i_type )
-            {
-            case MODULE_CONFIG_ITEM_STRING:
-            case MODULE_CONFIG_ITEM_FILE:
-            case MODULE_CONFIG_ITEM_PLUGIN:
-                config_PutPszVariable( p_longopts[i_index].name, optarg );
-                break;
-            case MODULE_CONFIG_ITEM_INTEGER:
-                config_PutIntVariable( p_longopts[i_index].name, atoi(optarg));
-                break;
-            case MODULE_CONFIG_ITEM_BOOL:
-                config_PutIntVariable( p_longopts[i_index].name, 1 );
-                break;
-            }
-
-            continue;
-        }
-
-        /* short options handled here for now */
-        switch( i_cmd )
-        {
-
-        /* General/common options */
-        case 'h':                                              /* -h, --help */
-            config_PutIntVariable( "help", 1 );
-            break;
-        case 'H':                                          /* -H, --longhelp */
-            config_PutIntVariable( "longhelp", 1 );
-            break;
-        case 'l':                                              /* -l, --list */
-            config_PutIntVariable( "list", 1 );
-            break;
-        case 'p':                                            /* -p, --plugin */
-            config_PutPszVariable( "plugin", optarg );
-            break;
-        case 'v':                                           /* -v, --verbose */
-            p_main->i_warning_level++;
-            break;
-
-        /* Internal error: unknown option */
-        case '?':
-        default:
-
-            if( !b_ignore_errors )
-            {
-                intf_ErrMsg( "intf error: unknown option `%s'",
-                             ppsz_argv[optind-1] );
-                intf_Msg( "Try `%s --help' for more information.\n",
-                          p_main->psz_arg0 );
-
-#ifdef WIN32        /* Pause the console because it's destroyed when we exit */
-                intf_Msg( "\nPress the RETURN key to continue..." );
-                getchar();
-#endif
-                free( p_longopts );
-                return( EINVAL );
-            }
-        }
-
-    }
-
-    if( p_main->i_warning_level < 0 )
-    {
-        p_main->i_warning_level = 0;
-    }
-
-    free( p_longopts );
-    return( 0 );
-}
-
 /*****************************************************************************
  * GetFilenames: parse command line options which are not flags
  *****************************************************************************
@@ -1170,11 +994,13 @@ static void Version( void )
 #ifdef WIN32
     ShowConsole();
 #endif
+
     intf_Msg( VERSION_MESSAGE
-        "This program comes with NO WARRANTY, to the extent permitted by law.\n"
-        "You may redistribute it under the terms of the GNU General Public License;\n"
-        "see the file named COPYING for details.\n"
+        "This program comes with NO WARRANTY, to the extent permitted by "
+        "law.\nYou may redistribute it under the terms of the GNU General "
+        "Public License;\nsee the file named COPYING for details.\n"
         "Written by the VideoLAN team at Ecole Centrale, Paris." );
+
 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
         intf_Msg( "\nPress the RETURN key to continue..." );
         getchar();
index 9f7c194f61d148eda711071c43d054acef13e4a1..94a82931041cd32686e4ea80081be2bb08d0f038 100644 (file)
@@ -2,7 +2,7 @@
  * configuration.c management of the modules configuration
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: configuration.c,v 1.7 2002/03/19 14:00:50 sam Exp $
+ * $Id: configuration.c,v 1.8 2002/03/21 07:11:57 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
 
 #include <videolan/vlc.h>
 
-#if defined(HAVE_GETPWUID) || defined(HAVE_GETPWUID_R)
+#ifdef HAVE_GETOPT_LONG
+#   ifdef HAVE_GETOPT_H
+#       include <getopt.h>                                       /* getopt() */
+#   endif
+#else
+#   include "GNUgetopt/getopt.h"
+#endif
+
+#if defined(HAVE_GETPWUID)
 #include <pwd.h>                                               /* getpwuid() */
 #endif
 
 #include <sys/stat.h>
 #include <sys/types.h>
 
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static char *GetHomeDir( void );
-
 /*****************************************************************************
  * config_GetIntVariable: get the value of an int variable
  *****************************************************************************
@@ -280,10 +283,10 @@ int config_LoadConfigFile( const char *psz_module_name )
     /* Acquire config file lock */
     vlc_mutex_lock( &p_main->config_lock );
 
-    psz_homedir = GetHomeDir();
+    psz_homedir = p_main->psz_homedir;
     if( !psz_homedir )
     {
-        intf_ErrMsg( "config error: GetHomeDir failed" );
+        intf_ErrMsg( "config error: p_main->psz_homedir is null" );
         vlc_mutex_unlock( &p_main->config_lock );
         return -1;
     }
@@ -292,12 +295,10 @@ int config_LoadConfigFile( const char *psz_module_name )
     if( !psz_filename )
     {
         intf_ErrMsg( "config error: couldn't malloc psz_filename" );
-        free( psz_homedir );
         vlc_mutex_unlock( &p_main->config_lock );
         return -1;
     }
     sprintf( psz_filename, "%s/" CONFIG_DIR "/" CONFIG_FILE, psz_homedir );
-    free( psz_homedir );
 
     intf_WarnMsg( 5, "config: opening config file %s", psz_filename );
 
@@ -444,10 +445,10 @@ int config_SaveConfigFile( const char *psz_module_name )
     /* Acquire config file lock */
     vlc_mutex_lock( &p_main->config_lock );
 
-    psz_homedir = GetHomeDir();
+    psz_homedir = p_main->psz_homedir;
     if( !psz_homedir )
     {
-        intf_ErrMsg( "config error: GetHomeDir failed" );
+        intf_ErrMsg( "config error: p_main->psz_homedir is null" );
         vlc_mutex_unlock( &p_main->config_lock );
         return -1;
     }
@@ -456,12 +457,10 @@ int config_SaveConfigFile( const char *psz_module_name )
     if( !psz_filename )
     {
         intf_ErrMsg( "config error: couldn't malloc psz_filename" );
-        free( psz_homedir );
         vlc_mutex_unlock( &p_main->config_lock );
         return -1;
     }
     sprintf( psz_filename, "%s/" CONFIG_DIR, psz_homedir );
-    free( psz_homedir );
 #ifndef WIN32
     mkdir( psz_filename, 0755 );
 #else
@@ -628,52 +627,220 @@ int config_SaveConfigFile( const char *psz_module_name )
     return 0;
 }
 
-/* Following functions are local. */
+/*****************************************************************************
+ * config_LoadCmdLine: parse command line
+ *****************************************************************************
+ * Parse command line for configuration options.
+ * Now that the module_bank has been initialized, we can dynamically
+ * generate the longopts structure used by getops. We have to do it this way
+ * because we don't know (and don't want to know) in advance the configuration
+ * options used (ie. exported) by each module.
+ *****************************************************************************/
+int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
+                       boolean_t b_ignore_errors )
+{
+    int i_cmd, i, i_index, i_longopts_size;
+    module_t *p_module;
+    struct option *p_longopts;
+
+    /* Short options */
+    const char *psz_shortopts = "hHvlp:";
+
+    /* Set default configuration and copy arguments */
+    p_main->i_argc    = *pi_argc;
+    p_main->ppsz_argv = ppsz_argv;
+
+    p_main->p_channel = NULL;
+
+#ifdef SYS_DARWIN
+    /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
+     * is the PSN - process serial number (a unique PID-ish thingie)
+     * still ok for real Darwin & when run from command line */
+    if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
+                                        /* for example -psn_0_9306113 */
+    {
+        /* GDMF!... I can't do this or else the MacOSX window server will
+         * not pick up the PSN and not register the app and we crash...
+         * hence the following kludge otherwise we'll get confused w/ argv[1]
+         * being an input file name */
+#if 0
+        ppsz_argv[ 1 ] = NULL;
+#endif
+        *pi_argc = *pi_argc - 1;
+        pi_argc--;
+        return( 0 );
+    }
+#endif
+
+
+    /*
+     * Generate the longopts structure used by getopt_long
+     */
+    i_longopts_size = 0;
+    for( p_module = p_module_bank->first;
+         p_module != NULL ;
+         p_module = p_module->next )
+    {
+        /* count the number of exported configuration options (to allocate
+         * longopts). */
+        i_longopts_size += p_module->i_config_items;
+    }
+
+    p_longopts = (struct option *)malloc( sizeof(struct option)
+                                          * (i_longopts_size + 1) );
+    if( p_longopts == NULL )
+    {
+        intf_ErrMsg( "config error: couldn't allocate p_longopts" );
+        return( -1 );
+    }
+
+    /* Fill the longopts structure */
+    i_index = 0;
+    for( p_module = p_module_bank->first ;
+         p_module != NULL ;
+         p_module = p_module->next )
+    {
+        for( i = 0; i < p_module->i_config_lines; i++ )
+        {
+            if( p_module->p_config[i].i_type & MODULE_CONFIG_HINT )
+                /* ignore hints */
+                continue;
+            p_longopts[i_index].name = p_module->p_config[i].psz_name;
+            p_longopts[i_index].has_arg =
+                (p_module->p_config[i].i_type == MODULE_CONFIG_ITEM_BOOL)?
+                                               no_argument : required_argument;
+            p_longopts[i_index].flag = 0;
+            p_longopts[i_index].val = 0;
+            i_index++;
+        }
+    }
+    /* Close the longopts structure */
+    memset( &p_longopts[i_index], 0, sizeof(struct option) );
+
+
+    /*
+     * Parse the command line options
+     */
+    opterr = 0;
+    optind = 1;
+    while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv, psz_shortopts,
+                                  p_longopts, &i_index ) ) != EOF )
+    {
+
+        if( i_cmd == 0 )
+        {
+            /* A long option has been recognized */
+
+            module_config_t *p_conf;
+
+            /* Store the configuration option */
+            p_conf = config_FindConfig( p_longopts[i_index].name );
+
+            switch( p_conf->i_type )
+            {
+            case MODULE_CONFIG_ITEM_STRING:
+            case MODULE_CONFIG_ITEM_FILE:
+            case MODULE_CONFIG_ITEM_PLUGIN:
+                config_PutPszVariable( p_longopts[i_index].name, optarg );
+                break;
+            case MODULE_CONFIG_ITEM_INTEGER:
+                config_PutIntVariable( p_longopts[i_index].name, atoi(optarg));
+                break;
+            case MODULE_CONFIG_ITEM_BOOL:
+                config_PutIntVariable( p_longopts[i_index].name, 1 );
+                break;
+            }
+
+            continue;
+        }
+
+        /* short options handled here for now */
+        switch( i_cmd )
+        {
+
+        /* General/common options */
+        case 'h':                                              /* -h, --help */
+            config_PutIntVariable( "help", 1 );
+            break;
+        case 'H':                                          /* -H, --longhelp */
+            config_PutIntVariable( "longhelp", 1 );
+            break;
+        case 'l':                                              /* -l, --list */
+            config_PutIntVariable( "list", 1 );
+            break;
+        case 'p':                                            /* -p, --plugin */
+            config_PutPszVariable( "plugin", optarg );
+            break;
+        case 'v':                                           /* -v, --verbose */
+            p_main->i_warning_level++;
+            break;
+
+        /* Internal error: unknown option */
+        case '?':
+        default:
+
+            if( !b_ignore_errors )
+            {
+                intf_ErrMsg( "config error: unknown option `%s'",
+                             ppsz_argv[optind-1] );
+                intf_Msg( "Try `%s --help' for more information.\n",
+                          p_main->psz_arg0 );
+
+                free( p_longopts );
+                return( -1 );
+            }
+        }
+
+    }
+
+    if( p_main->i_warning_level < 0 )
+    {
+        p_main->i_warning_level = 0;
+    }
+
+    free( p_longopts );
+    return( 0 );
+}
 
 /*****************************************************************************
- * GetHomeDir: find the user's home directory.
+ * config_GetHomeDir: find the user's home directory.
  *****************************************************************************
  * This function will try by different ways to find the user's home path.
+ * Note that this function is not reentrant, it should be called only once
+ * at the beginning of main where the result will be stored for later use.
  *****************************************************************************/
-static char *GetHomeDir( void )
+char *config_GetHomeDir( void )
 {
     char *p_tmp, *p_homedir = NULL;
 
-#if defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWUID)
+#if defined(HAVE_GETPWUID)
     struct passwd *p_pw = NULL;
 #endif
 
 #if defined(HAVE_GETPWUID)
     if( ( p_pw = getpwuid( getuid() ) ) == NULL )
-#elif defined(HAVE_GETPWUID_R)
-    int ret;
-    struct passwd pwd;
-    char *p_buffer = NULL;
-    int bufsize = 128;
-
-    p_buffer = (char *)malloc( bufsize );
-
-    if( ( ret = getpwuid_r( getuid(), &pwd, p_buffer, bufsize, &p_pw ) ) < 0 )
 #endif
     {
         if( ( p_tmp = getenv( "HOME" ) ) == NULL )
         {
+            if( ( p_tmp = getenv( "TMP" ) ) == NULL )
+            {
+                p_homedir = strdup( "/tmp" );
+           }
+            else p_homedir = strdup( p_tmp );
+
             intf_ErrMsg( "config error: unable to get home directory, "
-                         "using /tmp instead" );
-            p_homedir = strdup( "/tmp" );
+                         "using %s instead", p_homedir );
+
         }
         else p_homedir = strdup( p_tmp );
     }
-#if defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWUID)
+#if defined(HAVE_GETPWUID)
     else
     {
-        if( p_pw ) p_homedir = strdup( p_pw->pw_dir );
+        p_homedir = strdup( p_pw->pw_dir );
     }
 #endif
 
-#if !defined(HAVE_GETPWUID) && defined(HAVE_GETPWUID_R)
-    if( p_buffer ) free( p_buffer );
-#endif
-
     return p_homedir;
 }