trunk: changeset 1362

Sun, 07 Mar 2004 22:45:24 +0100

author
tuomov
date
Sun, 07 Mar 2004 22:45:24 +0100
changeset 64
f20d97d852ce
parent 63
5b732dd506d3
child 65
58e382ae97cd

trunk: changeset 1362
Added libtu_strcasestr.

misc.c file | annotate | diff | comparison | revisions
misc.h file | annotate | diff | comparison | revisions
--- 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 <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 #include <libtu/misc.h>
 
@@ -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;
+}
+
 /* */
 
 
--- 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);
 

mercurial