Browse code

include cli_strtokbuf()

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

Tomasz Kojm authored on 2004/10/14 05:23:50
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Wed Oct 13 22:20:17 CEST 2004 (tk)
2
+----------------------------------
3
+  * libclamav/str.c: include cli_strtokbuf() from Nigel
4
+
1 5
 Wed Oct 13 20:21:26 CEST 2004 (tk)
2 6
 ----------------------------------
3 7
   * libclamav/mspack/cabd.c: fix possible description leak
... ...
@@ -6,7 +10,7 @@ Wed Oct 13 11:19:03 BST 2004 (njh)
6 6
 ----------------------------------
7 7
   * libclamav/untar.c:	Added handling of some extra file types within the
8 8
 				archive. Thanks to
9
-				djgardner@users.sourceforge.net
9
+				djgardner*users.sourceforge.net
10 10
 
11 11
 Wed Oct 13 09:57:54 BST 2004 (trog)
12 12
 -----------------------------------
... ...
@@ -231,3 +231,41 @@ char *cli_strtok(const char *line, int fieldno, const char *delim)
231 231
 
232 232
     return buffer;
233 233
 }
234
+
235
+/*
236
+ * Like cli_strtok, but this puts the output into a given argument, rather
237
+ * than allocating fresh memory
238
+ * Returns NULL for error, or a pointer to output
239
+ * njh@bandsman.co.uk
240
+ */
241
+char *cli_strtokbuf(const char *input, int fieldno, const char *delim, char *output)
242
+{
243
+    int counter = 0, i, j;
244
+
245
+    /* step to arg # <fieldno> */
246
+    for (i=0; input[i] && counter != fieldno; i++) {
247
+	if (strchr(delim, input[i])) {
248
+	    counter++;
249
+	    while(input[i+1] && strchr(delim, input[i+1])) {
250
+		i++;
251
+	    }
252
+	}
253
+    }
254
+    if (input[i] == '\0') {
255
+	/* end of buffer before field reached */
256
+	return NULL;
257
+    }
258
+
259
+    for (j=i; input[j]; j++) {
260
+	if (strchr(delim, input[j])) {
261
+	    break;
262
+	}
263
+    }
264
+    if (i == j) {
265
+	return NULL;
266
+    }
267
+    strncpy(output, input+i, j-i);
268
+    output[j-i] = '\0';
269
+
270
+    return output;
271
+}
... ...
@@ -25,5 +25,6 @@ char *cli_strtok(const char *line, int field, const char *delim);
25 25
 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
+char *cli_strtokbuf(const char *input, int fieldno, const char *delim, char *output);
28 29
 
29 30
 #endif