13
13
14
14
#define _GNU_SOURCE
15
15
#include <elf.h>
16
+ #include <fnmatch.h>
16
17
#include <stdio.h>
17
18
#include <ctype.h>
18
19
#include <string.h>
@@ -710,29 +711,6 @@ static char *get_modinfo(struct elf_info *info, const char *tag)
710
711
return get_next_modinfo (info , tag , NULL );
711
712
}
712
713
713
- /**
714
- * Test if string s ends in string sub
715
- * return 0 if match
716
- **/
717
- static int strrcmp (const char * s , const char * sub )
718
- {
719
- int slen , sublen ;
720
-
721
- if (!s || !sub )
722
- return 1 ;
723
-
724
- slen = strlen (s );
725
- sublen = strlen (sub );
726
-
727
- if ((slen == 0 ) || (sublen == 0 ))
728
- return 1 ;
729
-
730
- if (sublen > slen )
731
- return 1 ;
732
-
733
- return memcmp (s + slen - sublen , sub , sublen );
734
- }
735
-
736
714
static const char * sym_name (struct elf_info * elf , Elf_Sym * sym )
737
715
{
738
716
if (sym )
@@ -741,48 +719,22 @@ static const char *sym_name(struct elf_info *elf, Elf_Sym *sym)
741
719
return "(unknown)" ;
742
720
}
743
721
744
- /* The pattern is an array of simple patterns.
745
- * "foo" will match an exact string equal to "foo"
746
- * "*foo" will match a string that ends with "foo"
747
- * "foo*" will match a string that begins with "foo"
748
- * "*foo*" will match a string that contains "foo"
722
+ /*
723
+ * Check whether the 'string' argument matches one of the 'patterns',
724
+ * an array of shell wildcard patterns (glob).
725
+ *
726
+ * Return true is there is a match.
749
727
*/
750
- static int match (const char * sym , const char * const pat [])
728
+ static bool match (const char * string , const char * const patterns [])
751
729
{
752
- const char * p ;
753
- while (* pat ) {
754
- const char * endp ;
755
-
756
- p = * pat ++ ;
757
- endp = p + strlen (p ) - 1 ;
730
+ const char * pattern ;
758
731
759
- /* "*foo*" */
760
- if (* p == '*' && * endp == '*' ) {
761
- char * bare = NOFAIL (strndup (p + 1 , strlen (p ) - 2 ));
762
- char * here = strstr (sym , bare );
763
-
764
- free (bare );
765
- if (here != NULL )
766
- return 1 ;
767
- }
768
- /* "*foo" */
769
- else if (* p == '*' ) {
770
- if (strrcmp (sym , p + 1 ) == 0 )
771
- return 1 ;
772
- }
773
- /* "foo*" */
774
- else if (* endp == '*' ) {
775
- if (strncmp (sym , p , strlen (p ) - 1 ) == 0 )
776
- return 1 ;
777
- }
778
- /* no wildcards */
779
- else {
780
- if (strcmp (p , sym ) == 0 )
781
- return 1 ;
782
- }
732
+ while ((pattern = * patterns ++ )) {
733
+ if (!fnmatch (pattern , string , 0 ))
734
+ return true;
783
735
}
784
- /* no match */
785
- return 0 ;
736
+
737
+ return false ;
786
738
}
787
739
788
740
/* sections that we do not want to do full section mismatch check on */
0 commit comments