6 #include "libmallocab.h"
8 #define DEBUG_LIBSTRTOKDUP 0
11 Return a pointer to a copy of n-th word of a string.
12 Return NULL if there are not enough words.
14 Words are separated by whitespace
15 Caller is responsible to free() the returning pointer.
18 char* strtokdup(const char* s
, unsigned int nth
)
23 #if DEBUG_LIBSTRTOKDUP
24 fprintf(stderr
, "strtokdup('%s', %d)\n", s
, nth
);
30 /* Jump to nth token */
33 /* Strip leading whitespace */
34 while(isspace(s
[i
]) && s
[i
] != '\0') i
++;
39 /* Skip to next whitespace */
40 while(!isspace(s
[i
]) && s
[i
] != '\0') i
++;
47 L
= strcspn(s
+i
, " \f\n\r\t\v");
51 #if DEBUG_LIBSTRTOKDUP
52 fprintf(stderr
, " -> '%s'\n", r
);