]>
Commit | Line | Data |
---|---|---|
224c7076 A |
1 | .\" Copyright (c) 1998 Softweyr LLC. All rights reserved. |
2 | .\" | |
3 | .\" strtok_r, from Berkeley strtok | |
4 | .\" Oct 13, 1998 by Wes Peters <wes@softweyr.com> | |
5 | .\" | |
6 | .\" Copyright (c) 1988, 1991, 1993 | |
7 | .\" The Regents of the University of California. All rights reserved. | |
8 | .\" | |
9 | .\" This code is derived from software contributed to Berkeley by | |
10 | .\" the American National Standards Committee X3, on Information | |
11 | .\" Processing Systems. | |
12 | .\" | |
13 | .\" Redistribution and use in source and binary forms, with or without | |
14 | .\" modification, are permitted provided that the following conditions | |
15 | .\" are met: | |
16 | .\" | |
17 | .\" 1. Redistributions of source code must retain the above copyright | |
18 | .\" notices, this list of conditions and the following disclaimer. | |
19 | .\" | |
20 | .\" 2. Redistributions in binary form must reproduce the above | |
21 | .\" copyright notices, this list of conditions and the following | |
22 | .\" disclaimer in the documentation and/or other materials provided | |
23 | .\" with the distribution. | |
24 | .\" | |
25 | .\" 3. All advertising materials mentioning features or use of this | |
26 | .\" software must display the following acknowledgement: | |
27 | .\" | |
28 | .\" This product includes software developed by Softweyr LLC, the | |
29 | .\" University of California, Berkeley, and its contributors. | |
30 | .\" | |
31 | .\" 4. Neither the name of Softweyr LLC, the University nor the names | |
32 | .\" of its contributors may be used to endorse or promote products | |
33 | .\" derived from this software without specific prior written | |
34 | .\" permission. | |
35 | .\" | |
36 | .\" THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND | |
37 | .\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
38 | .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
39 | .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
40 | .\" DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE REGENTS, OR | |
41 | .\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
42 | .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
43 | .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |
44 | .\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
45 | .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
46 | .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
47 | .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
48 | .\" SUCH DAMAGE. | |
49 | .\" | |
50 | .\" @(#)strtok.3 8.2 (Berkeley) 2/3/94 | |
51 | .\" $FreeBSD: src/lib/libc/string/strtok.3,v 1.24 2002/12/18 12:45:11 ru Exp $ | |
52 | .\" | |
53 | .Dd November 27, 1998 | |
54 | .Dt STRTOK 3 | |
55 | .Os | |
56 | .Sh NAME | |
57 | .Nm strtok , strtok_r | |
58 | .Nd string tokens | |
59 | .Sh LIBRARY | |
60 | .Lb libc | |
61 | .Sh SYNOPSIS | |
62 | .In string.h | |
63 | .Ft char * | |
64 | .Fo strtok | |
65 | .Fa "char *restrict str" | |
66 | .Fa "const char *restrict sep" | |
67 | .Fc | |
68 | .Ft char * | |
69 | .Fo strtok_r | |
70 | .Fa "char *restrict str" | |
71 | .Fa "const char *restrict sep" | |
72 | .Fa "char **restrict lasts" | |
73 | .Fc | |
74 | .Sh DESCRIPTION | |
75 | .Bf -symbolic | |
76 | This interface is obsoleted by | |
77 | .Xr strsep 3 . | |
78 | .Ef | |
79 | .Pp | |
80 | The | |
81 | .Fn strtok | |
82 | function | |
83 | is used to isolate sequential tokens in a null-terminated string, | |
84 | .Fa str . | |
85 | These tokens are separated in the string by at least one of the | |
86 | characters in | |
87 | .Fa sep . | |
88 | The first time that | |
89 | .Fn strtok | |
90 | is called, | |
91 | .Fa str | |
92 | should be specified; subsequent calls, wishing to obtain further tokens | |
93 | from the same string, should pass a null pointer instead. | |
94 | The separator string, | |
95 | .Fa sep , | |
96 | must be supplied each time, and may change between calls. | |
97 | .Pp | |
98 | The implementation will behave as if no library function calls | |
99 | .Fn strtok . | |
100 | .Pp | |
101 | The | |
102 | .Fn strtok_r | |
103 | function is a reentrant version of | |
104 | .Fn strtok . | |
105 | The context pointer | |
106 | .Fa last | |
107 | must be provided on each call. | |
108 | The | |
109 | .Fn strtok_r | |
110 | function | |
111 | may also be used to nest two parsing loops within one another, as | |
112 | long as separate context pointers are used. | |
113 | .Pp | |
114 | The | |
115 | .Fn strtok | |
116 | and | |
117 | .Fn strtok_r | |
118 | functions | |
119 | return a pointer to the beginning of each subsequent token in the string, | |
120 | after replacing the token itself with a | |
121 | .Dv NUL | |
122 | character. | |
123 | When no more tokens remain, a null pointer is returned. | |
124 | .Sh EXAMPLES | |
125 | The following uses | |
126 | .Fn strtok_r | |
127 | to parse two strings using separate contexts: | |
128 | .Bd -literal | |
129 | char test[80], blah[80]; | |
130 | char *sep = "\e\e/:;=-"; | |
131 | char *word, *phrase, *brkt, *brkb; | |
132 | ||
133 | strcpy(test, "This;is.a:test:of=the/string\e\etokenizer-function."); | |
134 | ||
135 | for (word = strtok_r(test, sep, &brkt); | |
136 | word; | |
137 | word = strtok_r(NULL, sep, &brkt)) | |
138 | { | |
139 | strcpy(blah, "blah:blat:blab:blag"); | |
140 | ||
141 | for (phrase = strtok_r(blah, sep, &brkb); | |
142 | phrase; | |
143 | phrase = strtok_r(NULL, sep, &brkb)) | |
144 | { | |
145 | printf("So far we're at %s:%s\en", word, phrase); | |
146 | } | |
147 | } | |
148 | .Ed | |
149 | .Sh SEE ALSO | |
150 | .Xr memchr 3 , | |
151 | .Xr strchr 3 , | |
152 | .Xr strcspn 3 , | |
153 | .Xr strpbrk 3 , | |
154 | .Xr strrchr 3 , | |
155 | .Xr strsep 3 , | |
156 | .Xr strspn 3 , | |
157 | .Xr strstr 3 , | |
158 | .Xr wcstok 3 | |
159 | .Sh STANDARDS | |
160 | The | |
161 | .Fn strtok | |
162 | function | |
163 | conforms to | |
164 | .St -isoC . | |
165 | .Sh BUGS | |
166 | The System V | |
167 | .Fn strtok , | |
168 | if handed a string containing only delimiter characters, | |
169 | will not alter the next starting point, so that a call to | |
170 | .Fn strtok | |
171 | with a different (or empty) delimiter string | |
172 | may return a | |
173 | .Pf non- Dv NULL | |
174 | value. | |
175 | Since this implementation always alters the next starting point, | |
176 | such a sequence of calls would always return | |
177 | .Dv NULL . | |
178 | .Sh AUTHORS | |
179 | .An Wes Peters , | |
180 | Softweyr LLC: | |
181 | .Aq wes@softweyr.com | |
182 | .Pp | |
183 | Based on the | |
184 | .Fx 3.0 | |
185 | implementation. |