Don't use POSIX basename

This commit is contained in:
Jeremy 2023-09-12 18:08:24 -04:00
parent d714e70cf6
commit 5aadb58492
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
2 changed files with 12 additions and 7 deletions

View File

@ -430,6 +430,17 @@ static bool directory_exists(const std::string& path) {
#endif
}
CPPTRACE_MAYBE_UNUSED
static std::string basename(const std::string& path) {
// Assumes no trailing /'s
auto pos = path.rfind("/");
if(pos == std::string::npos) {
return path;
} else {
return path.substr(pos + 1);
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif

View File

@ -18,10 +18,6 @@
#include <libdwarf.h>
#include <dwarf.h>
#if IS_APPLE
#include <libgen.h>
#endif
// some stuff is based on https://github.com/davea42/libdwarf-addr2line/blob/master/addr2line.c, mainly line handling
// then much expanded for symbols and efficiency
// dwarf5_ranges and dwarf4_ranges utility functions are taken from there directly, also pc_in_die
@ -1010,9 +1006,7 @@ namespace cpptrace {
//char* dir = dirname(obj_path.data());
//std::string dsym =
if(directory_exists(obj_path + ".dSYM")) {
std::string obj_path_copy = frame_info.obj_path;
std::string base = basename(const_cast<char*>(obj_path_copy.data()));
obj_path += ".dSYM/Contents/Resources/DWARF/" + base;
obj_path += ".dSYM/Contents/Resources/DWARF/" + basename(frame_info.obj_path);
}
#endif
if(trace_dwarf) {