1 .\" Copyright (c) 1998 Softweyr LLC. All rights reserved.
3 .\" strtok_r, from Berkeley strtok
4 .\" Oct 13, 1998 by Wes Peters <wes@softweyr.com>
6 .\" Copyright (c) 1988, 1991, 1993
7 .\" The Regents of the University of California. All rights reserved.
9 .\" This code is derived from software contributed to Berkeley by
10 .\" the American National Standards Committee X3, on Information
11 .\" Processing Systems.
13 .\" Redistribution and use in source and binary forms, with or without
14 .\" modification, are permitted provided that the following conditions
17 .\" 1. Redistributions of source code must retain the above copyright
18 .\" notices, this list of conditions and the following disclaimer.
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.
25 .\" 3. Neither the name of Softweyr LLC, the University nor the names
26 .\" of its contributors may be used to endorse or promote products
27 .\" derived from this software without specific prior written
30 .\" THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND
31 .\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
32 .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 .\" DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE REGENTS, OR
35 .\" CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37 .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
38 .\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
40 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
41 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 .\" @(#)strtok.3 8.2 (Berkeley) 2/3/94
45 .\" $FreeBSD: head/lib/libc/string/strtok.3 251069 2013-05-28 20:57:40Z emaste $
58 .Fn strtok "char *str" "const char *sep"
60 .Fn strtok_r "char *str" "const char *sep" "char **last"
63 This interface is obsoleted by
70 is used to isolate sequential tokens in a null-terminated string,
72 These tokens are separated in the string by at least one of the
79 should be specified; subsequent calls, wishing to obtain further tokens
80 from the same string, should pass a null pointer instead.
83 must be supplied each time, and may change between calls.
85 The implementation will behave as if no library function calls
90 function is a reentrant version of
94 must be provided on each call.
98 may also be used to nest two parsing loops within one another, as
99 long as separate context pointers are used.
106 return a pointer to the beginning of each subsequent token in the string,
107 after replacing the token itself with a
110 When no more tokens remain, a null pointer is returned.
114 to parse two strings using separate contexts:
116 char test[80], blah[80];
117 char *sep = "\e\e/:;=-";
118 char *word, *phrase, *brkt, *brkb;
120 strcpy(test, "This;is.a:test:of=the/string\e\etokenizer-function.");
122 for (word = strtok_r(test, sep, &brkt);
124 word = strtok_r(NULL, sep, &brkt))
126 strcpy(blah, "blah:blat:blab:blag");
128 for (phrase = strtok_r(blah, sep, &brkb);
130 phrase = strtok_r(NULL, sep, &brkb))
132 printf("So far we're at %s:%s\en", word, phrase);
153 .An Wes Peters, Softweyr LLC Aq Mt wes@softweyr.com
161 if handed a string containing only delimiter characters,
162 will not alter the next starting point, so that a call to
164 with a different (or empty) delimiter string
168 Since this implementation always alters the next starting point,
169 such a sequence of calls would always return