X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Finit.c;h=cf13eacd5521868201900d516f1011f3ac81ec66;hp=ab86c781eb86b2857303d6bf16b750e4ae155ac4;hb=5e7f976fa1be6af7b5698972289107747fe37d0e;hpb=54097c0e2867e48f9246624eaabe56eb5f279d1f diff --git a/src/init.c b/src/init.c index ab86c781..cf13eacd 100644 --- a/src/init.c +++ b/src/init.c @@ -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; } - + /* Remove dashes and underscores from S, modifying S in the process. */