aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/pathstuff.cc
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2022-04-13 17:31:02 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2022-04-18 15:48:03 -0400
commit7ab2607f97e5deaeae91018edf3ef5b4255a842c (patch)
treef1fea75412b59b147691af35019eb6d940f062b0 /gdbsupport/pathstuff.cc
parente0c34637019b0a070780b57b50d9026c0aca16f4 (diff)
downloadgdb-7ab2607f97e5deaeae91018edf3ef5b4255a842c.zip
gdb-7ab2607f97e5deaeae91018edf3ef5b4255a842c.tar.gz
gdb-7ab2607f97e5deaeae91018edf3ef5b4255a842c.tar.bz2
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
Diffstat (limited to 'gdbsupport/pathstuff.cc')
-rw-r--r--gdbsupport/pathstuff.cc41
1 files changed, 20 insertions, 21 deletions
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<char>
+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<char>
- (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<char> 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<char> 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<char> 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<char> 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<char> 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<char> 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;
}