# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <vlc_common.h>
#include "../libvlc.h"
#if 0
-#include <stdio.h>
#include <assert.h>
#include <pthread.h>
+#include <limits.h>
static void set_libvlc_path (void)
{
assert (strlen (LIBDIR) < sizeof (libvlc_path));
strcpy (libvlc_path, LIBDIR); /* fail safe */
- vlc_global ()->psz_vlcpath = libvlc_path;
+ psz_vlcpath = libvlc_path;
/* Find the path to libvlc (i.e. ourselves) */
FILE *maps = fopen ("/proc/self/maps", "rt");
if (maps == NULL)
return;
+ char *line = NULL;
+ size_t linelen = 0;
+ uintptr_t needle = (uintptr_t)set_libvlc_path;
+
for (;;)
{
- char buf[5000], *dir, *end;
-
- if (fgets (buf, sizeof (buf), maps) == NULL)
+ ssize_t len = getline (&line, &linelen, maps);
+ if (len == -1)
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)
continue;
- end = strrchr (dir, '/');
+ char *file = strrchr (line, '/');
if (end == NULL)
continue;
- if (strncmp (end + 1, "libvlc.so.", 10))
- continue;
-
- *end = '\0';
+ *file = '\0';
printf ("libvlc at %s\n", dir);
if (strlen (dir) < sizeof (libvlc_path))
strcpy (libvlc_path, dir);
break;
}
-
+ free (line);
fclose (maps);
}
#endif
+#ifdef __GLIBC__
+# include <gnu/libc-version.h>
+# include <stdlib.h>
+#endif
+
void system_Init (libvlc_int_t *libvlc, int *argc, const char *argv[])
{
+#ifdef __GLIBC__
+ const char *glcv = gnu_get_libc_version ();
+
+ /* gettext in glibc 2.5-2.7 is not thread-safe. LibVLC keeps crashing,
+ * especially in sterror_r(). Even if we have NLS disabled, the calling
+ * process might have called setlocale(). */
+ if (strverscmp (glcv, "2.5") >= 0 && strverscmp (glcv, "2.8") < 0)
+ {
+ fputs ("LibVLC has detected an unusable buggy GNU/libc version.\n"
+ "Please update to version 2.8 or newer.\n", stderr);
+ fflush (stderr);
+#ifndef DISABLE_BUGGY_GLIBC_CHECK
+ abort ();
+#endif
+ }
+#endif
+
#if 0
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once (&once, set_libvlc_path);