]> sjero.net Git - wget/blobdiff - src/init.c
Merge with mainline.
[wget] / src / init.c
index fd71a3628edd8169f95d352d9bbd1b0d3447df77..991f570fda727480284e09319aeb1a1651d02f17 100644 (file)
@@ -349,35 +349,41 @@ defaults (void)
 char *
 home_dir (void)
 {
-  char *home = getenv ("HOME");
+  static char buf[PATH_MAX];
+  static char *home;
 
   if (!home)
     {
+      home = getenv ("HOME");
+      if (!home)
+        {
 #if defined(MSDOS)
-      /* Under MSDOS, if $HOME isn't defined, use the directory where
-         `wget.exe' resides.  */
-      const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */
-      char *p, buf[PATH_MAX];
-
-      strcpy (buf, _w32_get_argv0 ());
-      p = strrchr (buf, '/');            /* djgpp */
-      if (!p)
-        p = strrchr (buf, '\\');          /* others */
-      assert (p);
-      *p = '\0';
-      home = buf;
+          /* Under MSDOS, if $HOME isn't defined, use the directory where
+             `wget.exe' resides.  */
+          const char *_w32_get_argv0 (void); /* in libwatt.a/pcconfig.c */
+          char *p;
+
+          strcpy (buf, _w32_get_argv0 ());
+          p = strrchr (buf, '/');            /* djgpp */
+          if (!p)
+            p = strrchr (buf, '\\');          /* others */
+          assert (p);
+          *p = '\0';
+          home = buf;
 #elif !defined(WINDOWS)
-      /* If HOME is not defined, try getting it from the password
-         file.  */
-      struct passwd *pwd = getpwuid (getuid ());
-      if (!pwd || !pwd->pw_dir)
-        return NULL;
-      home = pwd->pw_dir;
+          /* If HOME is not defined, try getting it from the password
+             file.  */
+          struct passwd *pwd = getpwuid (getuid ());
+          if (!pwd || !pwd->pw_dir)
+            return NULL;
+          strcpy (buf, pwd->pw_dir);
+          home = buf;
 #else  /* !WINDOWS */
-      /* Under Windows, if $HOME isn't defined, use the directory where
-         `wget.exe' resides.  */
-      home = ws_mypath ();
+          /* Under Windows, if $HOME isn't defined, use the directory where
+             `wget.exe' resides.  */
+          home = ws_mypath ();
 #endif /* WINDOWS */
+        }
     }
 
   return home ? xstrdup (home) : NULL;
@@ -403,12 +409,13 @@ wgetrc_env_file_name (void)
     }
   return NULL;
 }
+
 /* Check for the existance of '$HOME/.wgetrc' and return it's path
    if it exists and is set.  */
 char *
 wgetrc_user_file_name (void) 
 {
-  char *home = home_dir();
+  char *home = home_dir ();
   char *file = NULL;
   if (home)
     file = aprintf ("%s/.wgetrc", home);
@@ -422,6 +429,7 @@ wgetrc_user_file_name (void)
     }
   return file;
 }
+
 /* Return the path to the user's .wgetrc.  This is either the value of
    `WGETRC' environment variable, or `$HOME/.wgetrc'.
 
@@ -430,10 +438,11 @@ wgetrc_user_file_name (void)
 char *
 wgetrc_file_name (void)
 {
+  char *home = NULL;
   char *file = wgetrc_env_file_name ();
   if (file && *file)
     return file;
-
+  
   file = wgetrc_user_file_name ();
 
 #ifdef WINDOWS
@@ -441,6 +450,7 @@ wgetrc_file_name (void)
      `wget.ini' in the directory where `wget.exe' resides; we do this for
      backward compatibility with previous versions of Wget.
      SYSTEM_WGETRC should not be defined under WINDOWS.  */
+  home = home_dir ();
   if (!file || !file_exists_p (file))
     {
       xfree_null (file);
@@ -449,6 +459,7 @@ wgetrc_file_name (void)
       if (home)
         file = aprintf ("%s/wget.ini", home);
     }
+  xfree_null (home);
 #endif /* WINDOWS */
 
   if (!file)