Branch data Line data Source code
1 : : /******************************************************************************
2 : : * Copyright (c) 2004, 2008 IBM Corporation
3 : : * All rights reserved.
4 : : * This program and the accompanying materials
5 : : * are made available under the terms of the BSD License
6 : : * which accompanies this distribution, and is available at
7 : : * http://www.opensource.org/licenses/bsd-license.php
8 : : *
9 : : * Contributors:
10 : : * IBM Corporation - initial implementation
11 : : *****************************************************************************/
12 : :
13 : : #include <stddef.h>
14 : :
15 : : char *strtok(char *src, const char *pattern);
16 : 0 : char *strtok(char *src, const char *pattern)
17 : : {
18 : : static char *nxtTok;
19 : 0 : char *retVal = NULL;
20 : :
21 : 0 : if (!src) {
22 : 0 : src = nxtTok;
23 : 0 : if (!src)
24 : 0 : return retVal;
25 : : }
26 : :
27 : 0 : while (*src) {
28 : 0 : const char *pp = pattern;
29 : 0 : while (*pp) {
30 : 0 : if (*pp == *src) {
31 : 0 : break;
32 : : }
33 : 0 : pp++;
34 : : }
35 : 0 : if (!*pp) {
36 : 0 : if (!retVal)
37 : 0 : retVal = src;
38 : 0 : else if (!src[-1])
39 : 0 : break;
40 : : } else
41 : 0 : *src = '\0';
42 : 0 : src++;
43 : : }
44 : :
45 : 0 : nxtTok = src;
46 : :
47 : 0 : return retVal;
48 : : }
|