1 .\" Copyright (c) 1988, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" from: @(#)strtok.3 8.2 (Berkeley) 2/3/94
33 .\" $NetBSD: strtok.3,v 1.22 2006/10/16 08:48:45 wiz Exp $
46 .Fn strtok "char * restrict str" "const char * restrict sep"
48 .Fn strtok_r "char *str" "const char *sep" "char **lasts"
53 is used to isolate sequential tokens in a nul-terminated string,
55 These tokens are separated in the string by at least one of the
62 should be specified; subsequent calls, wishing to obtain further tokens
63 from the same string, should pass a null pointer instead.
66 must be supplied each time, and may change between calls.
71 returns a pointer to the beginning of each subsequent token in the string,
72 after replacing the separator character itself with a
75 Separator characters at the beginning of the string or at the
76 continuation point are skipped so that zero length tokens
78 When no more tokens remain, a null pointer is returned.
82 function implements the functionality of
84 but is passed an additional argument,
86 which points to a user-provided pointer which is used by
88 to store state which needs to be kept between calls to scan the same string;
91 it is not necessary to limit tokenizing to a single string at a time
95 The following will construct an array of pointers to each individual word in
98 .Bd -literal -offset indent
101 char s[512], *p, *tokens[MAXTOKENS];
105 snprintf(s, sizeof(s), "cat dog horse cow");
107 for ((p = strtok_r(s, " ", &last)); p;
108 (p = strtok_r(NULL, " ", &last)), i++) {
109 if (i < MAXTOKENS - 1)
153 if handed a string containing only delimiter characters,
154 will not alter the next starting point, so that a call to
156 with a different (or empty) delimiter string
160 Since this implementation always alters the next starting point,
161 such a sequence of calls would always return