The apr_strtok() doc says: the 'last' state points to the trailing NUL char of the final token, otherwise it points to the character following the current token (all successive or empty occurances of sep are skiped on the subsequent call to apr_strtok). Therefore it is possible to avoid a strlen() determination, with the following logic; toklen = last - retval; if (*last) –toklen;
Please explain that last clause, starting with exactly what *last is supposed to represent (hint: since last is declared as char**, it's a pointer, not the character past the end of the current token). In any case, decrementing the length just calculated is clearly incorrect, whether it's an early token or the last token in the string. But in fact, it's worse than that. By analogy with strtok(), the value of last has to be constant across successive calls to apr_strtok(). So to calculate the length of the token, one would need to use toklen = *last - retval; instead of toklen = last - retval; Does that not make sense?