3 <<strtok>>, <<strtok_r>>, <<strsep>>---get next token from a string
16 char *strtok(char *restrict <[source]>,
17 const char *restrict <[delimiters]>);
18 char *strtok_r(char *restrict <[source]>,
19 const char *restrict <[delimiters]>,
21 char *strsep(char **<[source_ptr]>, const char *<[delimiters]>);
24 The <<strtok>> function is used to isolate sequential tokens in a
25 null-terminated string, <<*<[source]>>>. These tokens are delimited
26 in the string by at least one of the characters in <<*<[delimiters]>>>.
27 The first time that <<strtok>> is called, <<*<[source]>>> should be
28 specified; subsequent calls, wishing to obtain further tokens from
29 the same string, should pass a null pointer instead. The separator
30 string, <<*<[delimiters]>>>, must be supplied each time and may
33 The <<strtok>> function returns a pointer to the beginning of each
34 subsequent token in the string, after replacing the separator
35 character itself with a null character. When no more tokens remain,
36 a null pointer is returned.
38 The <<strtok_r>> function has the same behavior as <<strtok>>, except
39 a pointer to placeholder <<*<[lasts]>>> must be supplied by the caller.
41 The <<strsep>> function is similar in behavior to <<strtok>>, except
42 a pointer to the string pointer must be supplied <<<[source_ptr]>>> and
43 the function does not skip leading delimiters. When the string starts
44 with a delimiter, the delimiter is changed to the null character and
45 the empty string is returned. Like <<strtok_r>> and <<strtok>>, the
46 <<*<[source_ptr]>>> is updated to the next character following the
47 last delimiter found or NULL if the end of string is reached with
51 <<strtok>>, <<strtok_r>>, and <<strsep>> all return a pointer to the
52 next token, or <<NULL>> if no more tokens can be found. For
53 <<strsep>>, a token may be the empty string.
56 <<strtok>> is unsafe for multi-threaded applications. <<strtok_r>>
57 and <<strsep>> are thread-safe and should be used instead.
61 <<strtok_r>> is POSIX.
62 <<strsep>> is a BSD extension.
64 <<strtok>>, <<strtok_r>>, and <<strsep>> require no supporting OS subroutines.
70 /* undef STRICT_ANSI so that strtok_r prototype will be defined */
71 #undef __STRICT_ANSI__
77 #ifdef _REENT_THREAD_LOCAL
78 _Thread_local
char *_tls_strtok_last
;
83 extern char *__strtok_r (char *, const char *, char **, int);
86 strtok (register char *__restrict s
,
87 register const char *__restrict delim
)
89 struct _reent
*reent
= _REENT
;
91 _REENT_CHECK_MISC(reent
);
92 return __strtok_r (s
, delim
, &(_REENT_STRTOK_LAST(reent
)), 1);