- struct string dir;
-
- /* Do tilde expansion. */
- ds_init_substring (&dir, dir_);
- if (ds_first (&dir) == '~')
- {
- char *tmp_str = fn_tilde_expand (ds_cstr (&dir));
- ds_assign_cstr (&dir, tmp_str);
- free (tmp_str);
- }
-
- /* Construct file name. */
- ds_clear (&file);
- ds_put_cstr (&file, ds_cstr (&dir));
- if (!ds_is_empty (&file) && ds_last (&file) != '/')
- ds_put_char (&file, '/');
- ds_put_cstr (&file, base_name);
- ds_destroy (&dir);
-
- /* Check whether file exists. */
- if (fn_exists (ds_cstr (&file)))
- {
- verbose_msg (2, _("...found \"%s\""), ds_cstr (&file));
- ds_destroy (&path);
- return ds_cstr (&file);
- }
- }
-
- /* Failure. */
- verbose_msg (2, _("...not found"));
- ds_destroy (&path);
- ds_destroy (&file);
- return NULL;
-}
-
-/* fn_normalize(): This very OS-dependent routine canonicalizes
- file name FN1. The file name should not need to be the name of an
- existing file. Returns a malloc()'d copy of the canonical name.
- This function must always succeed; if it needs to bail out then it
- should return xstrdup(FN1). */
-#ifdef unix
-char *
-fn_normalize (const char *file_name)
-{
- const char *src;
- char *fn1, *fn2, *dest;
- int maxlen;
-
- if (fn_is_special (file_name))
- return xstrdup (file_name);
-
- fn1 = fn_tilde_expand (file_name);
-
- /* Follow symbolic links. */
- for (;;)
- {
- fn2 = fn1;
- fn1 = fn_readlink (fn1);
- if (!fn1)
- {
- fn1 = fn2;
- break;
- }
- free (fn2);
- }