From: Micah Cowan Date: Tue, 9 Sep 2008 17:20:21 +0000 (-0700) Subject: Avoid unnecessary vars, and make wgetrc_file_name build properly on Windows. X-Git-Tag: v1.13~405 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=a38d9e7e7a35d7d6ddfb3be4f2191eebc3f04a38 Avoid unnecessary vars, and make wgetrc_file_name build properly on Windows. --- diff --git a/src/ChangeLog b/src/ChangeLog index 015be198..74f3653a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2008-09-09 Micah Cowan + * 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 diff --git a/src/build_info.c b/src/build_info.c index ee843ce9..551b7d94 100644 --- a/src/build_info.c +++ b/src/build_info.c @@ -33,9 +33,6 @@ as that of the covered work. */ #include "wget.h" #include -char *system_wgetrc = SYSTEM_WGETRC; -char *locale_dir = LOCALEDIR; - const char* (compiled_features[]) = { diff --git a/src/init.c b/src/init.c index a774061b..768bebd1 100644 --- a/src/init.c +++ b/src/init.c @@ -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) diff --git a/src/main.c b/src/main.c index b30fc3f2..268a603f 100644 --- a/src/main.c +++ b/src/main.c @@ -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),