1 /*****************************************************************************
2 * linux_specific.c: Linux-specific initialization
3 *****************************************************************************
4 * Copyright © 2008-2012 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
28 #include <vlc_common.h>
30 #include "config/configuration.h"
32 char *config_GetLibDir (void)
36 /* Find the path to libvlc (i.e. ourselves) */
37 FILE *maps
= fopen ("/proc/self/maps", "rte");
43 uintptr_t needle
= (uintptr_t)config_GetLibDir
;
47 ssize_t len
= getline (&line
, &linelen
, maps
);
52 if (sscanf (line
, "%p-%p", &start
, &end
) < 2)
54 /* This mapping contains the address of this function. */
55 if (needle
< (uintptr_t)start
|| (uintptr_t)end
<= needle
)
58 char *dir
= strchr (line
, '/');
62 char *file
= strrchr (line
, '/');
67 if (asprintf (&path
, "%s/"PACKAGE
, dir
) == -1)
75 return (path
!= NULL
) ? path
: strdup (PKGLIBDIR
);
78 char *config_GetDataDir (void)
80 const char *path
= getenv ("VLC_DATA_PATH");
84 char *libdir
= config_GetLibDir ();
86 return NULL
; /* OOM */
90 /* There are no clean ways to do this, are there?
91 * Due to multilibs, we cannot simply append ../share/. */
92 char *p
= strstr (libdir
, "/lib/");
96 /* Deal with nested "lib" directories. Grmbl. */
97 while ((p2
= strstr (p
+ 4, "/lib/")) != NULL
)
101 if (unlikely(asprintf (&datadir
, "%s/share/"PACKAGE
, libdir
) == -1))
105 return (datadir
!= NULL
) ? datadir
: strdup (PKGDATADIR
);