/* Test case for MySQLBug #17762 Connect fails in all tests of standard build http://bugs.mysql.com/bug.php?id=17762 */ #include #include char wild_many='*'; char wild_one='?'; char wild_prefix=0; /* We have macros that insert debug code, when disabled they look like this. */ #define DBUG_RETURN(a1) do { return(a1); } while(0) // Change the macro to the below and function will return 0 //#define DBUG_RETURN(a1) return(a1) static int wild_case_compare(const char *str,const char *wildstr) { int flag; printf("str: '%s' wildstr: '%s'\n",str,wildstr); while (*wildstr) { while (*wildstr && *wildstr != wild_many && *wildstr != wild_one) { if (*wildstr == wild_prefix && wildstr[1]) wildstr++; if (toupper(*wildstr++) != toupper(*str++)) DBUG_RETURN(1); } if (! *wildstr ) DBUG_RETURN (*str != 0); if (*wildstr++ == wild_one) { if (! *str++) DBUG_RETURN (1); /* One char; skip */ } else { /* Found '*' */ if (!*wildstr) DBUG_RETURN(0); /* '*' as last char: OK */ flag=(*wildstr != wild_many && *wildstr != wild_one); do { if (flag) { int cmp; if ((cmp= *wildstr) == wild_prefix && wildstr[1]) cmp=wildstr[1]; cmp=toupper(cmp); while (*str && toupper(*str) != cmp) str++; if (!*str) DBUG_RETURN (1); } if (wild_case_compare(str,wildstr) == 0) DBUG_RETURN (0); } while (*str++); DBUG_RETURN(1); } } printf("str: %s", str); DBUG_RETURN (*str != '\0'); } int main(void) { /* Compare "localhost" with "localhost", should return 0 */ int res= wild_case_compare("localhost", "localhost"); if (res==0) printf("OK\n"); else printf("FAILED: res: %d\n", res); }