Commit 79399150 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Linux: do not hardcode libvlc.so, use address space match instead

parent fcf05b24
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#if 0 #if 0
#include <assert.h> #include <assert.h>
#include <pthread.h> #include <pthread.h>
#include <limits.h>
static void set_libvlc_path (void) static void set_libvlc_path (void)
{ {
...@@ -45,29 +46,34 @@ static void set_libvlc_path (void) ...@@ -45,29 +46,34 @@ static void set_libvlc_path (void)
if (maps == NULL) if (maps == NULL)
return; return;
char *line = NULL;
size_t linelen = 0;
uintptr_t needle = (uintptr_t)set_libvlc_path;
for (;;) for (;;)
{ {
char buf[5000], *dir, *end; ssize_t len = getline (&line, &linelen, maps);
if (len == -1)
if (fgets (buf, sizeof (buf), maps) == NULL)
break; break;
dir = strchr (buf, '/'); void *start, *end;
if (sscanf (line, "%p-%p", &start, &end) < 2)
continue;
if (needle < (uintptr_t)start || (uintptr_t)end <= needle)
continue;
char *dir = strchr (line, '/');
if (dir == NULL) if (dir == NULL)
continue; continue;
end = strrchr (dir, '/'); char *file = strrchr (line, '/');
if (end == NULL) if (end == NULL)
continue; continue;
if (strncmp (end + 1, "libvlc.so.", 10)) *file = '\0';
continue;
*end = '\0';
printf ("libvlc at %s\n", dir); printf ("libvlc at %s\n", dir);
if (strlen (dir) < sizeof (libvlc_path)) if (strlen (dir) < sizeof (libvlc_path))
strcpy (libvlc_path, dir); strcpy (libvlc_path, dir);
break; break;
} }
free (line);
fclose (maps); fclose (maps);
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment