Commit dc57ec18 dc57ec1899b7ba2608ba0855b236704f1936b0a6 by Sergey Poznyakoff

(mh_expand_name): Correctly handle full and relative pathname specifications.

1 parent 7b5f1106
...@@ -67,7 +67,7 @@ mh_read_formfile (char *name, char **pformat) ...@@ -67,7 +67,7 @@ mh_read_formfile (char *name, char **pformat)
67 char *ptr; 67 char *ptr;
68 size_t off = 0; 68 size_t off = 0;
69 char *format_str; 69 char *format_str;
70 70
71 if (stat (name, &st)) 71 if (stat (name, &st))
72 { 72 {
73 mh_error (_("can't stat format file %s: %s"), name, strerror (errno)); 73 mh_error (_("can't stat format file %s: %s"), name, strerror (errno));
...@@ -342,15 +342,31 @@ mh_expand_name (const char *base, const char *name, int is_folder) ...@@ -342,15 +342,31 @@ mh_expand_name (const char *base, const char *name, int is_folder)
342 tmp = mu_tilde_expansion (name, "/", NULL); 342 tmp = mu_tilde_expansion (name, "/", NULL);
343 if (tmp[0] == '+') 343 if (tmp[0] == '+')
344 name = tmp + 1; 344 name = tmp + 1;
345 else if (strncmp (tmp, "../", 3) == 0 || strncmp (tmp, "./", 2) == 0)
346 {
347 char *cwd = mu_getcwd ();
348 asprintf (&name, "%s/%s", cwd, tmp);
349 free (cwd);
350 free (tmp);
351 tmp = NULL;
352 }
345 else 353 else
346 name = tmp; 354 name = tmp;
347 355
348 if (!base) 356 if (!base)
349 base = mu_path_folder_dir; 357 base = mu_path_folder_dir;
350 if (is_folder) 358 if (is_folder)
351 asprintf (&p, "mh:%s/%s", base, name); 359 {
352 else 360 if (name[0] == '/')
361 asprintf (&p, "mh:%s", name);
362 else
363 asprintf (&p, "mh:%s/%s", base, name);
364 }
365 else if (name[0] != '/')
353 asprintf (&p, "%s/%s", base, name); 366 asprintf (&p, "%s/%s", base, name);
367 else
368 return name;
369
354 free (tmp); 370 free (tmp);
355 return p; 371 return p;
356 } 372 }
......