split string into tokens */
| 12 | |
| 13 | /* split string into tokens */ |
| 14 | int |
| 15 | rte_strsplit(char *string, int stringlen, |
| 16 | char **tokens, int maxtokens, char delim) |
| 17 | { |
| 18 | int i, tok = 0; |
| 19 | int tokstart = 1; /* first token is right at start of string */ |
| 20 | |
| 21 | if (string == NULL || tokens == NULL) |
| 22 | goto einval_error; |
| 23 | |
| 24 | for (i = 0; i < stringlen; i++) { |
| 25 | if (string[i] == '\0' || tok >= maxtokens) |
| 26 | break; |
| 27 | if (tokstart) { |
| 28 | tokstart = 0; |
| 29 | tokens[tok++] = &string[i]; |
| 30 | } |
| 31 | if (string[i] == delim) { |
| 32 | string[i] = '\0'; |
| 33 | tokstart = 1; |
| 34 | } |
| 35 | } |
| 36 | return tok; |
| 37 | |
| 38 | einval_error: |
| 39 | errno = EINVAL; |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | /* Copy src string into dst. |
| 44 | * |
no outgoing calls