Debian Codegraph @

ext/GOTCHA/src/library_filters.c

raw symbols SCIP
1 /*
2 This file is part of GOTCHA. For copyright information see the COPYRIGHT
3 file in the top level directory, or at
4 https://github.com/LLNL/gotcha/blob/master/COPYRIGHT
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU Lesser General Public License (as published by the Free
7 Software Foundation) version 2.1 dated February 1999. This program is
8 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 PURPOSE. See the terms and conditions of the GNU Lesser General Public License
11 for more details. You should have received a copy of the GNU Lesser General
12 Public License along with this program; if not, write to the Free Software
13 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14 */
15 #include "library_filters.h"
16
17 #include "gotcha/gotcha.h"
18 #include "libc_wrappers.h"
19
20 static const char *filter;
21 int (*libraryFilterFunc)(struct link_map *) = alwaysTrue;
22
23 int alwaysTrue(struct link_map *candidate KNOWN_UNUSED) { return 1; }
24
25 int trueIfNameMatches(struct link_map *target) {
26 int match =
27 (filter) && (target) && (gotcha_strstr(target->l_name, filter) != 0);
28 return match;
29 }
30 int trueIfLast(struct link_map *target) {
31 int ret = (target->l_next) ? 0 : 1;
32 return ret;
33 }
34 void gotcha_only_filter_last() { gotcha_set_library_filter_func(trueIfLast); }
35 void gotcha_set_library_filter_func(int (*new_func)(struct link_map *)) {
36 libraryFilterFunc = new_func;
37 }
38 void gotcha_restore_library_filter_func() {
39 gotcha_set_library_filter_func(alwaysTrue);
40 }
41
42 void gotcha_filter_libraries_by_name(const char *nameFilter) {
43 filter = nameFilter;
44 gotcha_set_library_filter_func(trueIfNameMatches);
45 }