]> sjero.net Git - wget/commitdiff
Avoid unnecessary vars, and make wgetrc_file_name build properly on Windows.
authorMicah Cowan <micah@cowan.name>
Tue, 9 Sep 2008 17:20:21 +0000 (10:20 -0700)
committerMicah Cowan <micah@cowan.name>
Tue, 9 Sep 2008 17:20:21 +0000 (10:20 -0700)
src/ChangeLog
src/build_info.c
src/init.c
src/main.c

index 015be198c422a28ba10f2399bd014986df35e845..74f3653a7903699bd88d048ec7168dbd5f4c1952 100644 (file)
@@ -1,5 +1,12 @@
 2008-09-09  Micah Cowan  <micah@cowan.name>
 
+       * init.c (home_dir): Save the calculated value for home,
+       to avoid duplicated work on repeated calls.
+       (wgetrc_file_name) [WINDOWS]: Define and initialize home var.
+
+       * build_info.c: Remove unnecessary extern vars system_wgetrc and
+       locale_dir.
+
        * main.c: Define program_name for lib/error.c.
 
 2008-09-02  Gisle Vanem  <gvanem@broadpark.no>
index ee843ce9ebb5426874253839316305835d89653b..551b7d944f5d0dff350903ad93a7a729a5c8daf6 100644 (file)
@@ -33,9 +33,6 @@ as that of the covered work.  */
 #include "wget.h"
 #include <stdio.h>
 
-char *system_wgetrc = SYSTEM_WGETRC;
-char *locale_dir = LOCALEDIR;
-
 const char* (compiled_features[]) =
 {
 
index a774061b413a4f1ecd1f98086b2ac4e14ae36238..768bebd13885866f1b6b27c21cf0fac597f27066 100644 (file)
@@ -338,35 +338,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;
@@ -392,12 +398,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);
@@ -411,6 +418,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'.
 
@@ -419,10 +427,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
@@ -430,6 +439,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);
@@ -438,6 +448,7 @@ wgetrc_file_name (void)
       if (home)
         file = aprintf ("%s/wget.ini", home);
     }
+  xfree_null (home);
 #endif /* WINDOWS */
 
   if (!file)
index b30fc3f2d9ab97104073deedb2282a7bfaed82b1..268a603ffbd144375520bd59e0ab59998976f2b3 100644 (file)
@@ -72,8 +72,6 @@ extern char *system_getrc;
 extern char *link_string;
 /* defined in build_info.c */
 extern char *compiled_features[];
-extern char *system_wgetrc;
-extern char *locale_dir;
 /* Used for --version output in print_version */
 static const int max_chars_per_line = 72;
 
@@ -743,6 +741,10 @@ format_and_print_line (char* prefix, char* line,
     }
 
   printf ("\n");
+
+  /* FIXME: Responsibility for deallocation should be handled by
+     whatever allocated it, wherever possible. These two lines result
+     in unnecessary strdup calls in the print_version function. */
   xfree (prefix);
   xfree (line);
 }
@@ -794,10 +796,12 @@ print_version (void)
       printf ("%s (user)\n%s", user_wgetrc, prefix_spaces);
       xfree (user_wgetrc);
     }
-  printf ("%s (system)\n", system_wgetrc);
+#ifdef SYSTEM_WGETRC
+  printf ("%s (system)\n", SYSTEM_WGETRC);
+#endif
 
   format_and_print_line (strdup (locale_title),
-                        strdup (locale_dir), 
+                        strdup (LOCALEDIR), 
                         max_chars_per_line);
   
   format_and_print_line (strdup (compile_title),