Add nsswitch support.
[dragonfly.git] / lib / libc / string / strtok.3
CommitLineData
984263bc
MD
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.10.2.8 2001/12/14 18:33:59 ru Exp $
0b84df5c 52.\" $DragonFly: src/lib/libc/string/strtok.3,v 1.4 2006/02/17 19:35:06 swildner Exp $
984263bc
MD
53.\"
54.Dd November 27, 1998
55.Dt STRTOK 3
56.Os
57.Sh NAME
d0de9052
SW
58.Nm strtok ,
59.Nm strtok_r
984263bc
MD
60.Nd string tokens
61.Sh LIBRARY
62.Lb libc
63.Sh SYNOPSIS
64.In string.h
65.Ft char *
66.Fn strtok "char *str" "const char *sep"
67.Ft char *
68.Fn strtok_r "char *str" "const char *sep" "char **last"
69.Sh DESCRIPTION
70.Bf -symbolic
71This interface is obsoleted by
72.Xr strsep 3 .
73.Ef
74.Pp
75The
76.Fn strtok
77function
78is used to isolate sequential tokens in a null-terminated string,
79.Fa str .
80These tokens are separated in the string by at least one of the
81characters in
82.Fa sep .
83The first time that
84.Fn strtok
85is called,
86.Fa str
87should be specified; subsequent calls, wishing to obtain further tokens
88from the same string, should pass a null pointer instead.
89The separator string,
90.Fa sep ,
91must be supplied each time, and may change between calls.
92.Pp
93The implementation will behave as if no library function calls
94.Fn strtok .
95.Pp
96The
97.Fn strtok_r
98function is a reentrant version of
99.Fn strtok .
100The context pointer
101.Fa last
102must be provided on each call.
103.Fn strtok_r
104may also be used to nest two parsing loops within one another, as
105long as separate context pointers are used.
106.Pp
107The
108.Fn strtok
109and
110.Fn strtok_r
111functions
112return a pointer to the beginning of each subsequent token in the string,
113after replacing the token itself with a
114.Dv NUL
115character.
116When no more tokens remain, a null pointer is returned.
117.Sh EXAMPLES
118The following uses
119.Fn strtok_r
120to parse two strings using separate contexts:
121.Bd -literal
122char test[80], blah[80];
123char *sep = "\e\e/:;=-";
124char *word, *phrase, *brkt, *brkb;
125
126strcpy(test, "This;is.a:test:of=the/string\e\etokenizer-function.");
127
128for (word = strtok_r(test, sep, &brkt);
129 word;
130 word = strtok_r(NULL, sep, &brkt))
131{
132 strcpy(blah, "blah:blat:blab:blag");
133
134 for (phrase = strtok_r(blah, sep, &brkb);
135 phrase;
136 phrase = strtok_r(NULL, sep, &brkb))
137 {
138 printf("So far we're at %s:%s\en", word, phrase);
139 }
140}
141.Ed
142.Sh SEE ALSO
143.Xr memchr 3 ,
144.Xr strchr 3 ,
145.Xr strcspn 3 ,
146.Xr strpbrk 3 ,
147.Xr strrchr 3 ,
148.Xr strsep 3 ,
149.Xr strspn 3 ,
150.Xr strstr 3
151.Sh STANDARDS
152The
153.Fn strtok
154function
155conforms to
156.St -isoC .
0b84df5c
SW
157.Sh AUTHORS
158.An Wes Peters ,
159Softweyr LLC:
160.Aq wes@softweyr.com
161.Pp
162Based on the
163.Fx 3.0
164implementation.
984263bc
MD
165.Sh BUGS
166The System V
167.Fn strtok ,
168if handed a string containing only delimiter characters,
169will not alter the next starting point, so that a call to
170.Fn strtok
171with a different (or empty) delimiter string
172may return a
173.Pf non- Dv NULL
174value.
175Since this implementation always alters the next starting point,
176such a sequence of calls would always return
177.Dv NULL .