-/* Return a copy of FILENAME, with its directory prefix canonicalized
- by gdb_realpath. */
-
-gdb::unique_xmalloc_ptr<char>
-gdb_realpath_keepfile (const char *filename)
-{
- const char *base_name = lbasename (filename);
- char *dir_name;
- char *result;
-
- /* Extract the basename of filename, and return immediately
- a copy of filename if it does not contain any directory prefix. */
- if (base_name == filename)
- return gdb::unique_xmalloc_ptr<char> (xstrdup (filename));
-
- dir_name = (char *) alloca ((size_t) (base_name - filename + 2));
- /* Allocate enough space to store the dir_name + plus one extra
- character sometimes needed under Windows (see below), and
- then the closing \000 character. */
- strncpy (dir_name, filename, base_name - filename);
- dir_name[base_name - filename] = '\000';
-
-#ifdef HAVE_DOS_BASED_FILE_SYSTEM
- /* We need to be careful when filename is of the form 'd:foo', which
- is equivalent of d:./foo, which is totally different from d:/foo. */
- if (strlen (dir_name) == 2 && isalpha (dir_name[0]) && dir_name[1] == ':')
- {
- dir_name[2] = '.';
- dir_name[3] = '\000';
- }
-#endif
-
- /* Canonicalize the directory prefix, and build the resulting
- filename. If the dirname realpath already contains an ending
- directory separator, avoid doubling it. */
- gdb::unique_xmalloc_ptr<char> path_storage = gdb_realpath (dir_name);
- const char *real_path = path_storage.get ();
- if (IS_DIR_SEPARATOR (real_path[strlen (real_path) - 1]))
- result = concat (real_path, base_name, (char *) NULL);
- else
- result = concat (real_path, SLASH_STRING, base_name, (char *) NULL);
-
- return gdb::unique_xmalloc_ptr<char> (result);
-}
-
-/* Return PATH in absolute form, performing tilde-expansion if necessary.
- PATH cannot be NULL or the empty string.
- This does not resolve symlinks however, use gdb_realpath for that. */
-
-gdb::unique_xmalloc_ptr<char>
-gdb_abspath (const char *path)
-{
- gdb_assert (path != NULL && path[0] != '\0');
-
- if (path[0] == '~')
- return gdb::unique_xmalloc_ptr<char> (tilde_expand (path));
-
- if (IS_ABSOLUTE_PATH (path))
- return gdb::unique_xmalloc_ptr<char> (xstrdup (path));
-
- /* Beware the // my son, the Emacs barfs, the botch that catch... */
- return gdb::unique_xmalloc_ptr<char>
- (concat (current_directory,
- IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1])
- ? "" : SLASH_STRING,
- path, (char *) NULL));
-}
-