1 /*****************************************************************************
2 * override.c: overriden function calls for VLC media player
3 *****************************************************************************
4 * Copyright (C) 2010 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it 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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
27 void vlc_enable_override (void);
29 static bool override = false;
31 void vlc_enable_override (void)
36 #if defined (__GNUC__) /* typeof and statement-expression */ \
37 && (defined (__ELF__) && !defined (__sun__))
38 /* Solaris crashes on printf("%s", NULL); which is legal, but annoying. */
45 static void vlogbug (const char *level, const char *func, const char *fmt,
49 fprintf (stderr, "%s: call to %s(", level, func);
50 vfprintf (stderr, fmt, ap);
51 fputs (")\n", stderr);
55 static void logbug (const char *level, const char *func, const char *fmt, ...)
60 vlogbug (level, func, fmt, ap);
64 static void *getsym (const char *name)
66 void *sym = dlsym (RTLD_NEXT, name);
69 fprintf (stderr, "Cannot resolve symbol %s!\n", name);
75 #define LOG(level, ...) logbug(level, __func__, __VA_ARGS__)
76 #define CALL(func, ...) \
77 ({ typeof (func) *sym = getsym ( # func); sym (__VA_ARGS__); })
82 * "Conforming multi-threaded applications shall not use the environ variable
83 * to access or modify any environment variable while any other thread is
84 * concurrently modifying any environment variable." -- POSIX.
86 * Some evil libraries modify the environment. We currently ignore the calls as
87 * they could crash the process. This may cause funny behaviour though. */
88 int putenv (char *str)
92 LOG("Blocked", "\"%s\"", str);
95 return CALL(putenv, str);
98 int setenv (const char *name, const char *value, int overwrite)
102 LOG("Blocked", "\"%s\", \"%s\", %d", name, value, overwrite);
105 return CALL(setenv, name, value, overwrite);
108 int unsetenv (const char *name)
112 LOG("Blocked", "\"%s\"", name);
115 return CALL(unsetenv, name);