]> sjero.net Git - wget/blobdiff - src/init.c
Adds build information to the --version command line option.
[wget] / src / init.c
index ab86c781eb86b2857303d6bf16b750e4ae155ac4..cf13eacd5521868201900d516f1011f3ac81ec66 100644 (file)
@@ -369,19 +369,14 @@ home_dir (void)
   return home ? xstrdup (home) : NULL;
 }
 
-/* Return the path to the user's .wgetrc.  This is either the value of
-   `WGETRC' environment variable, or `$HOME/.wgetrc'.
-
+/* Check the 'WGETRC' environment variable and return the file name 
+   if  'WGETRC' is set and is a valid file.  
    If the `WGETRC' variable exists but the file does not exist, the
    function will exit().  */
-static char *
-wgetrc_file_name (void)
+char *
+wgetrc_env_file_name (void) 
 {
-  char *env, *home;
-  char *file = NULL;
-
-  /* Try the environment.  */
-  env = getenv ("WGETRC");
+  char *env = getenv ("WGETRC");
   if (env && *env)
     {
       if (!file_exists_p (env))
@@ -392,12 +387,40 @@ wgetrc_file_name (void)
         }
       return xstrdup (env);
     }
-
-  /* If that failed, try $HOME/.wgetrc.  */
-  home = home_dir ();
+  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 *file = NULL;
   if (home)
     file = aprintf ("%s/.wgetrc", home);
   xfree_null (home);
+  if (!file)
+    return NULL;
+  if (!file_exists_p (file))
+    {
+      xfree (file);
+      return NULL;
+    }
+  return file;
+}
+/* Return the path to the user's .wgetrc.  This is either the value of
+   `WGETRC' environment variable, or `$HOME/.wgetrc'.
+
+   Additionally, for windows, look in the directory where wget.exe 
+   resides.  */
+char *
+wgetrc_file_name (void)
+{
+  char *file = wgetrc_env_file_name ();
+  if (file && *file)
+    return file;
+
+  file = wgetrc_user_file_name ();
 
 #ifdef WINDOWS
   /* Under Windows, if we still haven't found .wgetrc, look for the file
@@ -538,7 +561,7 @@ initialize (void)
   xfree (file);
   return;
 }
-\f
+
 /* Remove dashes and underscores from S, modifying S in the
    process. */