+/* Like the above, but handles tilde-expansion when reading a user's
+ `.wgetrc'. In that case, and if VAL begins with `~', the tilde
+ gets expanded to the user's home directory. */
+static int
+cmd_file (const char *com, const char *val, void *closure)
+{
+ char **pstring = (char **)closure;
+
+ FREE_MAYBE (*pstring);
+ if (!enable_tilde_expansion || !(*val == '~' && *(val + 1) == '/'))
+ {
+ noexpand:
+ *pstring = xstrdup (val);
+ }
+ else
+ {
+ char *result;
+ int homelen;
+ char *home = home_dir ();
+ if (!home)
+ goto noexpand;
+
+ homelen = strlen (home);
+ while (homelen && home[homelen - 1] == '/')
+ home[--homelen] = '\0';
+
+ /* Skip the leading "~/". */
+ for (++val; *val == '/'; val++)
+ ;
+
+ result = xmalloc (homelen + 1 + strlen (val));
+ memcpy (result, home, homelen);
+ result[homelen] = '/';
+ strcpy (result + homelen + 1, val);
+
+ *pstring = result;
+ }
+ return 1;
+}
+