Browse code

core, parser: moved ser_mem[r]mem() functions from parser to ut.c

Juha Heinanen authored on 09/04/2014 17:30:23
Showing 3 changed files
... ...
@@ -67,68 +67,6 @@ static struct {
67 67
 	(_x==_t[0]||_x==_t[7]||_x==_t[1]||_x==_t[2]||_x==_t[3]||_x==_t[4]\
68 68
 	||_x==_t[5]||_x==_t[6])
69 69
 
70
-/*
71
- * ser_memmem() returns the location of the first occurrence of data
72
- * pattern b2 of size len2 in memory block b1 of size len1 or
73
- * NULL if none is found. Obtained from NetBSD.
74
- */
75
-static void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2)
76
-{
77
-	/* Initialize search pointer */
78
-	char *sp = (char *) b1;
79
-
80
-	/* Initialize pattern pointer */
81
-	char *pp = (char *) b2;
82
-
83
-	/* Initialize end of search address space pointer */
84
-	char *eos = sp + len1 - len2;
85
-
86
-	/* Sanity check */
87
-	if(!(b1 && b2 && len1 && len2))
88
-		return NULL;
89
-
90
-	while (sp <= eos) {
91
-		if (*sp == *pp)
92
-			if (memcmp(sp, pp, len2) == 0)
93
-				return sp;
94
-
95
-			sp++;
96
-	}
97
-
98
-	return NULL;
99
-}
100
-
101
-/*
102
- * ser_memrmem() returns the location of the last occurrence of data
103
- * pattern b2 of size len2 in memory block b1 of size len1 or
104
- * NULL if none is found.
105
- */
106
-static void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2)
107
-{
108
-	/* Initialize search pointer */
109
-	char *sp = (char *) b1 + len1 - len2;
110
-
111
-	/* Initialize pattern pointer */
112
-	char *pp = (char *) b2;
113
-
114
-	/* Initialize end of search address space pointer */
115
-	char *eos = (char *) b1;
116
-
117
-	/* Sanity check */
118
-	if(!(b1 && b2 && len1 && len2))
119
-		return NULL;
120
-
121
-	while (sp >= eos) {
122
-		if (*sp == *pp)
123
-			if (memcmp(sp, pp, len2) == 0)
124
-				return sp;
125
-
126
-			sp--;
127
-	}
128
-
129
-	return NULL;
130
-}
131
-
132 70
 int get_mixed_part_delimiter(str* body, str *mp_delimiter)
133 71
 {
134 72
 	static unsigned int boun[16] = {
... ...
@@ -297,3 +297,65 @@ char *str_search(str *text, str *needle)
297 297
 
298 298
     return NULL;
299 299
 }
300
+
301
+/*
302
+ * ser_memmem() returns the location of the first occurrence of data
303
+ * pattern b2 of size len2 in memory block b1 of size len1 or
304
+ * NULL if none is found. Obtained from NetBSD.
305
+ */
306
+void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2)
307
+{
308
+	/* Initialize search pointer */
309
+	char *sp = (char *) b1;
310
+
311
+	/* Initialize pattern pointer */
312
+	char *pp = (char *) b2;
313
+
314
+	/* Initialize end of search address space pointer */
315
+	char *eos = sp + len1 - len2;
316
+
317
+	/* Sanity check */
318
+	if(!(b1 && b2 && len1 && len2))
319
+		return NULL;
320
+
321
+	while (sp <= eos) {
322
+		if (*sp == *pp)
323
+			if (memcmp(sp, pp, len2) == 0)
324
+				return sp;
325
+
326
+			sp++;
327
+	}
328
+
329
+	return NULL;
330
+}
331
+
332
+/*
333
+ * ser_memrmem() returns the location of the last occurrence of data
334
+ * pattern b2 of size len2 in memory block b1 of size len1 or
335
+ * NULL if none is found.
336
+ */
337
+void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2)
338
+{
339
+	/* Initialize search pointer */
340
+	char *sp = (char *) b1 + len1 - len2;
341
+
342
+	/* Initialize pattern pointer */
343
+	char *pp = (char *) b2;
344
+
345
+	/* Initialize end of search address space pointer */
346
+	char *eos = (char *) b1;
347
+
348
+	/* Sanity check */
349
+	if(!(b1 && b2 && len1 && len2))
350
+		return NULL;
351
+
352
+	while (sp >= eos) {
353
+		if (*sp == *pp)
354
+			if (memcmp(sp, pp, len2) == 0)
355
+				return sp;
356
+
357
+			sp--;
358
+	}
359
+
360
+	return NULL;
361
+}
... ...
@@ -902,4 +902,19 @@ char* get_abs_pathname(str* base, str* file);
902 902
  * search for needle in text
903 903
  */
904 904
 char *str_search(str *text, str *needle);
905
+
906
+/*
907
+ * ser_memmem() returns the location of the first occurrence of data
908
+ * pattern b2 of size len2 in memory block b1 of size len1 or
909
+ * NULL if none is found. Obtained from NetBSD.
910
+ */
911
+void * ser_memmem(const void *b1, const void *b2, size_t len1, size_t len2);
912
+
913
+/*
914
+ * ser_memrmem() returns the location of the last occurrence of data
915
+ * pattern b2 of size len2 in memory block b1 of size len1 or
916
+ * NULL if none is found.
917
+ */
918
+void * ser_memrmem(const void *b1, const void *b2, size_t len1, size_t len2);
919
+
905 920
 #endif