Skip to content
Snippets Groups Projects
Commit f1bfe93c authored by Simon McVittie's avatar Simon McVittie
Browse files

capture-libs: Use a more complete basename() implementation


Previously, we just used strrchr(), but that didn't actually return
the basename as in basename(1): we were comparing strings like
"/libc-2.17.so" or "/libglib-2.0.so.0.5600.0".

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 79cbb05c
Branches
Tags
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
...@@ -92,6 +92,19 @@ static struct option long_options[] = ...@@ -92,6 +92,19 @@ static struct option long_options[] =
static int dest_fd = -1; static int dest_fd = -1;
/* Equivalent to GNU basename(3) from string.h, but not POSIX
* basename(3) from libgen.h. */
static const char *my_basename (const char *path)
{
const char *ret = strrchr( path, '/' );
if( ret == NULL )
return path;
assert( ret[0] == '/' );
return ret + 1;
}
static void usage (int code) __attribute__((noreturn)); static void usage (int code) __attribute__((noreturn));
static void usage (int code) static void usage (int code)
{ {
...@@ -279,8 +292,8 @@ capture_one( const char *soname, capture_flags flags, ...@@ -279,8 +292,8 @@ capture_one( const char *soname, capture_flags flags,
// doesn't chase symlinks if the prefix is '/' or empty. // doesn't chase symlinks if the prefix is '/' or empty.
p_realpath = realpath( provider.needed[i].path, NULL ); p_realpath = realpath( provider.needed[i].path, NULL );
c_realpath = realpath( container.needed[0].path, NULL ); c_realpath = realpath( container.needed[0].path, NULL );
p_basename = strrchr( p_realpath, '/' ); p_basename = my_basename( p_realpath );
c_basename = strrchr( c_realpath, '/' ); c_basename = my_basename( c_realpath );
DEBUG( DEBUG_TOOL, DEBUG( DEBUG_TOOL,
"Comparing %s \"%s\" from \"%s\" with " "Comparing %s \"%s\" from \"%s\" with "
...@@ -288,9 +301,6 @@ capture_one( const char *soname, capture_flags flags, ...@@ -288,9 +301,6 @@ capture_one( const char *soname, capture_flags flags,
provider.needed[i].name, p_basename, option_provider, provider.needed[i].name, p_basename, option_provider,
c_basename, option_container ); c_basename, option_container );
assert( p_basename );
assert( c_basename );
/* If equal, we prefer the provider over the container */ /* If equal, we prefer the provider over the container */
if( strverscmp( c_basename, p_basename ) > 0 ) if( strverscmp( c_basename, p_basename ) > 0 )
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment