/*--------------------------------------------------------------------------*/ FilterResult wildcard(const char *pattern, int pattern_len, const char *str, int str_len) /* Check the pattern against the given string. Public interface to wildcard */ /* functionality. */ /* */ /* Params: */ /* pattern -- the pattern to evaluate */ /* pattern_len -- the length of the pattern (in bytes) */ /* str -- the string to test the pattern on */ /* str_len -- the length of the string */ /* */ /* Returns: */ /* -1 error, 0 success, 1 failure */ /* */ /* Implementation: */ /* This is the interface to wildcard finding. It actually just prepares */ /* for repeated calls to wildcard_wc_str() */ /*--------------------------------------------------------------------------*/ { char *first_wc; /* Position of the first WC in the pattern. */ int first_wc_len; /* Position of first_wc in pattern. */ int unescaped_first_wc_len; /* Position of first_wc in unescaped version of pattern. */ /***** Check text up to first WC *****/ /**** Get text ****/ first_wc = memchr(pattern, WILDCARD, pattern_len); if(first_wc == NULL) { /* No wc */ return unescape_cmp(pattern, pattern_len, str, str_len, SLP_TRUE, NULL); } else { first_wc_len = first_wc - pattern; } /**** Compare. ****/ unescaped_first_wc_len = first_wc_len; if(first_wc_len > 0) { FilterResult err; err = unescape_cmp(pattern, first_wc_len, str, str_len, SLP_FALSE, &unescaped_first_wc_len); if(err != FR_EVAL_TRUE) { /* The leading text is different. */ return err; } } /***** Start recursive call. *****/ return wildcard_wc_str(first_wc, pattern_len - first_wc_len, (char *)str + unescaped_first_wc_len, str_len - unescaped_first_wc_len); }
static int find_grub_drive (const char *name) { unsigned int i; if (name) { for (i = 0; i < ARRAY_SIZE (map); i++) if (map[i].drive && unescape_cmp (map[i].drive, name) == 0) return i; } return -1; }
/*--------------------------------------------------------------------------*/ void *my_memmem(char *haystack, int haystack_len, char *needle, int needle_len, int *punescaped_len) /* locate an (escaped) substring */ /* */ /* Params: */ /* haystack -- (IN) unescaped memory to look in */ /* haystack_len -- (IN) length of haystack */ /* needle -- (IN) escaped memory to search for */ /* needle_len -- (IN) length of needle */ /* punescaped_len -- (OUT) the size of the unescaped needle. invalid if */ /* NULL is returned */ /* */ /* Returns: */ /* pointer to substring. NULL if there is no substring */ /*--------------------------------------------------------------------------*/ { int offset; int search_len; if(escaped_verify(haystack, haystack_len, &search_len) == 0) { return NULL; } for(offset = 0; offset <= search_len; offset++) { FilterResult err; err = unescape_cmp(needle, needle_len, haystack + offset, haystack_len - offset, SLP_FALSE, punescaped_len); if(err == FR_EVAL_TRUE) { return(void *)(haystack + offset); } else if(err != FR_EVAL_FALSE) { return NULL; } } return NULL; }