Browse code

return needle address in cli_memstr

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1246 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2005/01/16 02:36:25
Showing 5 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sat Jan 15 18:33:41 CET 2005 (tk)
2
+---------------------------------
3
+  * libclamav/str.c: cli_memstr: return needle address
4
+
1 5
 Fri Jan 14 16:12:21 GMT 2005 (trog)
2 6
 -----------------------------------
3 7
   * libclamav/filetypes.c: add a few more HTML filetype markers
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 1999 - 2004 Tomasz Kojm <tk@clamav.net>
2
+ *  Copyright (C) 1999 - 2005 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -547,43 +547,6 @@ void cli_writeint32(char *offset, uint32_t value)
547 547
     offset[3] = (value & 0xff000000) >> 24;
548 548
 }
549 549
 
550
-int cli_memstr(const char *haystack, int hs, const char *needle, int ns)
551
-{
552
-	const char *pt, *hay;
553
-	int n;
554
-
555
-
556
-    if(hs < ns)
557
-	return 0;
558
-
559
-    if(haystack == needle)
560
-	return 1;
561
-
562
-    if(!memcmp(haystack, needle, ns))
563
-	return 1;
564
-
565
-    pt = hay = haystack;
566
-    n = hs;
567
-
568
-    while((pt = memchr(hay, needle[0], n)) != NULL) {
569
-	n -= (int) pt - (int) hay;
570
-	if(n < ns)
571
-	    break;
572
-
573
-	if(!memcmp(pt, needle, ns))
574
-	    return 1;
575
-
576
-	if(hay == pt) {
577
-	    n--;
578
-	    hay++;
579
-	} else {
580
-	    hay = pt;
581
-	}
582
-    }
583
-
584
-    return 0;
585
-}
586
-
587 550
 int cli_filecopy(const char *src, const char *dest)
588 551
 {
589 552
 	char *buffer;
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 1999 - 2004 Tomasz Kojm <tk@clamav.net>
2
+ *  Copyright (C) 1999 - 2005 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -38,7 +38,6 @@ int32_t cli_readint32(const char *buff);
38 38
 void cli_writeint32(char *offset, uint32_t value);
39 39
 char *cli_gentemp(const char *dir);
40 40
 unsigned int cli_rndnum(unsigned int max);
41
-int cli_memstr(const char *haystack, int hs, const char *needle, int ns);
42 41
 int cli_filecopy(const char *src, const char *dest);
43 42
 
44 43
 #endif
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002, 2003 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -269,3 +269,40 @@ char *cli_strtokbuf(const char *input, int fieldno, const char *delim, char *out
269 269
 
270 270
     return output;
271 271
 }
272
+
273
+int cli_memstr(const char *haystack, int hs, const char *needle, int ns)
274
+{
275
+	const char *pt, *hay;
276
+	int n;
277
+
278
+
279
+    if(hs < ns)
280
+	return NULL;
281
+
282
+    if(haystack == needle)
283
+	return haystack;
284
+
285
+    if(!memcmp(haystack, needle, ns))
286
+	return haystack;
287
+
288
+    pt = hay = haystack;
289
+    n = hs;
290
+
291
+    while((pt = memchr(hay, needle[0], n)) != NULL) {
292
+	n -= (int) pt - (int) hay;
293
+	if(n < ns)
294
+	    break;
295
+
296
+	if(!memcmp(pt, needle, ns))
297
+	    return pt;
298
+
299
+	if(hay == pt) {
300
+	    n--;
301
+	    hay++;
302
+	} else {
303
+	    hay = pt;
304
+	}
305
+    }
306
+
307
+    return NULL;
308
+}
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2002 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 2002 - 2005 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -26,5 +26,6 @@ short int *cli_hex2si(const char *hex);
26 26
 char *cli_hex2str(const char *hex);
27 27
 char *cli_str2hex(const char *string, unsigned int len);
28 28
 char *cli_strtokbuf(const char *input, int fieldno, const char *delim, char *output);
29
+int cli_memstr(const char *haystack, int hs, const char *needle, int ns);
29 30
 
30 31
 #endif