From 7ab2607f97e5deaeae91018edf3ef5b4255a842c Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 13 Apr 2022 17:31:02 -0400 Subject: gdbsupport: make gdb_abspath return an std::string I'm trying to switch these functions to use std::string instead of char arrays, as much as possible. Some callers benefit from it (can avoid doing a copy of the result), while others suffer (have to make one more copy). Change-Id: Iced49b8ee2f189744c5072a3b217aab5af17a993 --- gdbsupport/pathstuff.cc | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'gdbsupport/pathstuff.cc') diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc index a347123..dd6ffa4 100644 --- a/gdbsupport/pathstuff.cc +++ b/gdbsupport/pathstuff.cc @@ -130,23 +130,23 @@ gdb_realpath_keepfile (const char *filename) /* See gdbsupport/pathstuff.h. */ -gdb::unique_xmalloc_ptr +std::string gdb_abspath (const char *path) { gdb_assert (path != NULL && path[0] != '\0'); if (path[0] == '~') - return gdb_tilde_expand_up (path); + return gdb_tilde_expand (path); if (IS_ABSOLUTE_PATH (path) || current_directory == NULL) - return make_unique_xstrdup (path); + return path; /* Beware the // my son, the Emacs barfs, the botch that catch... */ - return gdb::unique_xmalloc_ptr - (concat (current_directory, - IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) - ? "" : SLASH_STRING, - path, (char *) NULL)); + return string_printf + ("%s%s%s", current_directory, + (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]) + ? "" : SLASH_STRING), + path); } /* See gdbsupport/pathstuff.h. */ @@ -229,8 +229,8 @@ get_standard_cache_dir () if (xdg_cache_home != NULL && xdg_cache_home[0] != '\0') { /* Make sure the path is absolute and tilde-expanded. */ - gdb::unique_xmalloc_ptr abs (gdb_abspath (xdg_cache_home)); - return string_printf ("%s/gdb", abs.get ()); + std::string abs = gdb_abspath (xdg_cache_home); + return string_printf ("%s/gdb", abs.c_str ()); } #endif @@ -238,8 +238,8 @@ get_standard_cache_dir () if (home != NULL && home[0] != '\0') { /* Make sure the path is absolute and tilde-expanded. */ - gdb::unique_xmalloc_ptr abs (gdb_abspath (home)); - return string_printf ("%s/" HOME_CACHE_DIR "/gdb", abs.get ()); + std::string abs = gdb_abspath (home); + return string_printf ("%s/" HOME_CACHE_DIR "/gdb", abs.c_str ()); } #ifdef WIN32 @@ -247,8 +247,8 @@ get_standard_cache_dir () if (win_home != NULL && win_home[0] != '\0') { /* Make sure the path is absolute and tilde-expanded. */ - gdb::unique_xmalloc_ptr abs (gdb_abspath (win_home)); - return string_printf ("%s/gdb", abs.get ()); + std::string abs = gdb_abspath (win_home); + return string_printf ("%s/gdb", abs.c_str ()); } #endif @@ -296,8 +296,8 @@ get_standard_config_dir () if (xdg_config_home != NULL && xdg_config_home[0] != '\0') { /* Make sure the path is absolute and tilde-expanded. */ - gdb::unique_xmalloc_ptr abs (gdb_abspath (xdg_config_home)); - return string_printf ("%s/gdb", abs.get ()); + std::string abs = gdb_abspath (xdg_config_home); + return string_printf ("%s/gdb", abs.c_str ()); } #endif @@ -305,8 +305,8 @@ get_standard_config_dir () if (home != NULL && home[0] != '\0') { /* Make sure the path is absolute and tilde-expanded. */ - gdb::unique_xmalloc_ptr abs (gdb_abspath (home)); - return string_printf ("%s/" HOME_CONFIG_DIR "/gdb", abs.get ()); + std::string abs = gdb_abspath (home); + return string_printf ("%s/" HOME_CONFIG_DIR "/gdb", abs.c_str ()); } return {}; @@ -347,9 +347,8 @@ find_gdb_home_config_file (const char *name, struct stat *buf) if (homedir != nullptr && homedir[0] != '\0') { /* Make sure the path is absolute and tilde-expanded. */ - gdb::unique_xmalloc_ptr abs (gdb_abspath (homedir)); - std::string path = (std::string (abs.get ()) + SLASH_STRING - + std::string (name)); + std::string abs = gdb_abspath (homedir); + std::string path = string_printf ("%s/%s", abs.c_str (), name); if (stat (path.c_str (), buf) == 0) return path; } -- cgit v1.1