aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2022-04-13 17:39:06 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2022-04-18 15:48:03 -0400
commit5f2491c300636a2091a2ca3db7773d52d04bf566 (patch)
treee85460da53174cd4de6c5b8aad0f8941f6b12f82 /gdbsupport
parent7ab2607f97e5deaeae91018edf3ef5b4255a842c (diff)
downloadbinutils-5f2491c300636a2091a2ca3db7773d52d04bf566.zip
binutils-5f2491c300636a2091a2ca3db7773d52d04bf566.tar.gz
binutils-5f2491c300636a2091a2ca3db7773d52d04bf566.tar.bz2
gdbsupport: make gdb_realpath_keepfile 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: I793aab17baaef8345488f4c40b9094e2695425bc
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/pathstuff.cc11
-rw-r--r--gdbsupport/pathstuff.h3
2 files changed, 5 insertions, 9 deletions
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index dd6ffa4..ac65651 100644
--- a/gdbsupport/pathstuff.cc
+++ b/gdbsupport/pathstuff.cc
@@ -86,17 +86,16 @@ gdb_realpath (const char *filename)
/* See gdbsupport/pathstuff.h. */
-gdb::unique_xmalloc_ptr<char>
+std::string
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 make_unique_xstrdup (filename);
+ return filename;
dir_name = (char *) alloca ((size_t) (base_name - filename + 2));
/* Allocate enough space to store the dir_name + plus one extra
@@ -121,11 +120,9 @@ gdb_realpath_keepfile (const char *filename)
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);
+ return string_printf ("%s%s", real_path, base_name);
else
- result = concat (real_path, SLASH_STRING, base_name, (char *) NULL);
-
- return gdb::unique_xmalloc_ptr<char> (result);
+ return string_printf ("%s/%s", real_path, base_name);
}
/* See gdbsupport/pathstuff.h. */
diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h
index 04d9bf9..f6c51e9 100644
--- a/gdbsupport/pathstuff.h
+++ b/gdbsupport/pathstuff.h
@@ -39,8 +39,7 @@ extern gdb::unique_xmalloc_ptr<char> gdb_realpath (const char *filename);
/* Return a copy of FILENAME, with its directory prefix canonicalized
by gdb_realpath. */
-extern gdb::unique_xmalloc_ptr<char>
- gdb_realpath_keepfile (const char *filename);
+extern std::string gdb_realpath_keepfile (const char *filename);
/* Return PATH in absolute form, performing tilde-expansion if necessary.
PATH cannot be NULL or the empty string.