/* 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 `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. */ if (!file) { char *home = home_dir (); xfree_null (file); file = NULL; home = ws_mypath (); if (home) { file = aprintf ("%s/wget.ini", home); if (!file_exists_p (file)) { xfree (file); file = NULL; } xfree (home); } } #endif /* WINDOWS */ return file; }
/* Return the user's home directory (strdup-ed), or NULL if none is found. */ char * home_dir (void) { static char *buf = NULL; static char *home, *ret; int len; 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; buff = _w32_get_argv0 (); p = strrchr (buf, '/'); /* djgpp */ if (!p) p = strrchr (buf, '\\'); /* others */ assert (p); len = p - buff + 1; buff = malloc (len + 1); if (buff == NULL) return NULL; strncpy (buff, _w32_get_argv0 (), len); buff[len] = '\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; #else /* !WINDOWS */ /* Under Windows, if $HOME isn't defined, use the directory where `wget.exe' resides. */ home = ws_mypath (); #endif /* WINDOWS */ } } ret = home ? xstrdup (home) : NULL; if (buf) free (buf); return ret; }
/* Return the path to the user's .wgetrc. This is either the value of `WGETRC' environment variable, or `$HOME/.wgetrc'. If the `WGETRC' variable exists but the file does not exist, the function will exit(). */ static char * wgetrc_file_name (void) { char *env, *home; char *file = NULL; /* Try the environment. */ env = getenv ("WGETRC"); if (env && *env) { if (!file_exists_p (env)) { fprintf (stderr, _("%s: WGETRC points to %s, which doesn't exist.\n"), exec_name, env); exit (1); } return xstrdup (env); } /* If that failed, try $HOME/.wgetrc. */ home = home_dir (); if (home) file = aprintf ("%s/.wgetrc", home); xfree_null (home); #ifdef WINDOWS /* Under Windows, if we still haven't found .wgetrc, look for the file `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. */ if (!file || !file_exists_p (file)) { xfree_null (file); file = NULL; home = ws_mypath (); if (home) file = aprintf ("%s/wget.ini", home); } #endif /* WINDOWS */ if (!file) return NULL; if (!file_exists_p (file)) { xfree (file); return NULL; } return file; }
void ws_help (const char *name) { char *mypath = ws_mypath (); if (mypath) { struct stat sbuf; char *buf = (char *)alloca (strlen (mypath) + strlen (name) + 4 + 1); sprintf (buf, "%s%s.HLP", mypath, name); if (stat (buf, &sbuf) == 0) { printf (_("Starting WinHelp %s\n"), buf); WinHelp (NULL, buf, HELP_INDEX, NULL); } else { printf ("%s: %s\n", buf, strerror (errno)); } } }
/* Return the user's home directory (strdup-ed), or NULL if none is found. */ char * home_dir (void) { char *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; #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; #else /* !WINDOWS */ /* Under Windows, if $HOME isn't defined, use the directory where `wget.exe' resides. */ home = ws_mypath (); #endif /* WINDOWS */ } return home ? xstrdup (home) : NULL; }