# HG changeset patch # User tuomov # Date 1078695924 -3600 # Node ID f20d97d852ce544dec12b95b2caaf1683b768fe4 # Parent 5b732dd506d3fd2748abb02abcf2696eb252c9c4 trunk: changeset 1362 Added libtu_strcasestr. diff -r 5b732dd506d3 -r f20d97d852ce misc.c --- a/misc.c Sun Mar 07 22:10:48 2004 +0100 +++ b/misc.c Sun Mar 07 22:45:24 2004 +0100 @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -50,7 +51,8 @@ if(pn==NULL) return NULL; - memcpy(pn, p, l+1); + memcpy(pn, p, l); + pn[l]='\0'; return pn; } @@ -175,6 +177,20 @@ } +const char *libtu_strcasestr(const char *str, const char *ptn) +{ + const char *s2, *p2; + for(; *str; str++) { + for(s2=str, p2=ptn; ; s2++, p2++) { + if(!*p2) + return str; + if(toupper(*s2)!=toupper(*p2)) + break; + } + } + return NULL; +} + /* */ diff -r 5b732dd506d3 -r f20d97d852ce misc.h --- a/misc.h Sun Mar 07 22:10:48 2004 +0100 +++ b/misc.h Sun Mar 07 22:45:24 2004 +0100 @@ -33,6 +33,7 @@ extern char* scatn(const char *p1, ssize_t n1, const char *p2, ssize_t n2); extern char* scat3(const char *p1, const char *p2, const char *p3); extern void stripws(char *p); +extern const char *libtu_strcasestr(const char *str, const char *ptn); extern const char* simple_basename(const char *name);