- struct string output = DS_EMPTY_INITIALIZER;
- if (input[0] == '~')
- {
- const char *home = NULL;
- const char *remainder = NULL;
- if (input[1] == '/' || input[1] == '\0')
- {
- home = fn_getenv ("HOME");
- remainder = input + 1;
- }
- else
- {
- struct string user_name = DS_EMPTY_INITIALIZER;
- struct passwd *pwd;
-
- ds_assign_substring (&user_name,
- ss_buffer (input + 1,
- strcspn (input + 1, "/")));
- pwd = getpwnam (ds_cstr (&user_name));
- if (pwd != NULL && pwd->pw_dir[0] != '\0')
- {
- home = pwd->pw_dir;
- remainder = input + 1 + ds_length (&user_name);
- }
- ds_destroy (&user_name);
- }
-
- if (home != NULL)
- {
- ds_put_cstr (&output, home);
- if (*remainder != '\0')
- ds_put_cstr (&output, remainder);
- }
- }
- if (ds_is_empty (&output))
- ds_put_cstr (&output, input);
- return ds_cstr (&output);
-}
-#else /* !unix */
-char *
-fn_tilde_expand (const char *input)
-{
- return xstrdup (input);
-}
-#endif /* !unix */
-
-/* Searches for a configuration file with name NAME in the path
- given by PATH, which is tilde- and environment-interpolated.
- Directories in PATH are delimited by ':'. Returns the
- malloc'd full name of the first file found, or NULL if none is
- found.
-
- If PREFIX is non-NULL, then it is prefixed to each file name;
- i.e., it looks like PREFIX/PATH_COMPONENT/NAME. This is not
- done with absolute directories in the path. */
-char *
-fn_search_path (const char *base_name, const char *path_, const char *prefix)
-{
- struct string path;
- struct substring dir_;
- struct string file = DS_EMPTY_INITIALIZER;
- size_t save_idx = 0;