- char* map_basename = xbt_basename(pathname);
-
- regmatch_t match;
- if (regexec(&res->so_re, map_basename, 1, &match, 0)) {
- free(map_basename);
- return nullptr;
- }
-
- char* libname = strndup(map_basename, match.rm_so);
- free(map_basename);
- map_basename = nullptr;
-
- // Strip the version suffix:
- if (libname && not regexec(&res->version_re, libname, 1, &match, 0)) {
- char* temp = libname;
- libname = strndup(temp, match.rm_so);
- free(temp);
+ std::string map_basename = simgrid::xbt::Path(pathname).get_base_name();
+ std::string libname;
+
+ size_t pos = map_basename.rfind(".so");
+ if (pos != std::string::npos) {
+ // strip the extension (matching regex "\.so.*$")
+ libname.assign(map_basename, 0, pos);
+
+ // strip the version suffix (matching regex "-[.0-9-]*$")
+ while (true) {
+ pos = libname.rfind('-');
+ if (pos == std::string::npos || libname.find_first_not_of(".0123456789", pos + 1) != std::string::npos)
+ break;
+ libname.erase(pos);
+ }