1 | /* |
---|
2 | FUNCTION |
---|
3 | <<strtok>>, <<strtok_r>>, <<strsep>>---get next token from a string |
---|
4 | |
---|
5 | INDEX |
---|
6 | strtok |
---|
7 | |
---|
8 | INDEX |
---|
9 | strtok_r |
---|
10 | |
---|
11 | INDEX |
---|
12 | strsep |
---|
13 | |
---|
14 | SYNOPSIS |
---|
15 | #include <string.h> |
---|
16 | char *strtok(char *restrict <[source]>, |
---|
17 | const char *restrict <[delimiters]>); |
---|
18 | char *strtok_r(char *restrict <[source]>, |
---|
19 | const char *restrict <[delimiters]>, |
---|
20 | char **<[lasts]>); |
---|
21 | char *strsep(char **<[source_ptr]>, const char *<[delimiters]>); |
---|
22 | |
---|
23 | DESCRIPTION |
---|
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 |
---|
31 | change between calls. |
---|
32 | |
---|
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. |
---|
37 | |
---|
38 | The <<strtok_r>> function has the same behavior as <<strtok>>, except |
---|
39 | a pointer to placeholder <<*<[lasts]>>> must be supplied by the caller. |
---|
40 | |
---|
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 |
---|
48 | no more delimiters. |
---|
49 | |
---|
50 | RETURNS |
---|
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. |
---|
54 | |
---|
55 | NOTES |
---|
56 | <<strtok>> is unsafe for multi-threaded applications. <<strtok_r>> |
---|
57 | and <<strsep>> are thread-safe and should be used instead. |
---|
58 | |
---|
59 | PORTABILITY |
---|
60 | <<strtok>> is ANSI C. |
---|
61 | <<strtok_r>> is POSIX. |
---|
62 | <<strsep>> is a BSD extension. |
---|
63 | |
---|
64 | <<strtok>>, <<strtok_r>>, and <<strsep>> require no supporting OS subroutines. |
---|
65 | |
---|
66 | QUICKREF |
---|
67 | strtok ansi impure |
---|
68 | */ |
---|
69 | |
---|
70 | /* undef STRICT_ANSI so that strtok_r prototype will be defined */ |
---|
71 | #undef __STRICT_ANSI__ |
---|
72 | #include <string.h> |
---|
73 | #include <stdlib.h> |
---|
74 | #include <_ansi.h> |
---|
75 | #include <reent.h> |
---|
76 | |
---|
77 | #ifndef _REENT_ONLY |
---|
78 | |
---|
79 | extern char *__strtok_r (char *, const char *, char **, int); |
---|
80 | |
---|
81 | char * |
---|
82 | strtok (register char *__restrict s, |
---|
83 | register const char *__restrict delim) |
---|
84 | { |
---|
85 | struct _reent *reent = _REENT; |
---|
86 | |
---|
87 | _REENT_CHECK_MISC(reent); |
---|
88 | return __strtok_r (s, delim, &(_REENT_STRTOK_LAST(reent)), 1); |
---|
89 | } |
---|
90 | #endif |
---|