summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorart <>1999-11-09 11:20:13 +0000
committerart <>1999-11-09 11:20:13 +0000
commit0d3f282640bd1317811927392860497f0291a7fe (patch)
tree67e73727b3f67f16aa4f75d5468971e575db0031
parentcaebbd0c832cbc61947462bd8fab0b7e6ff89244 (diff)
downloadopenbsd-0d3f282640bd1317811927392860497f0291a7fe.tar.gz
openbsd-0d3f282640bd1317811927392860497f0291a7fe.tar.bz2
openbsd-0d3f282640bd1317811927392860497f0291a7fe.zip
Document strtok_r.
-rw-r--r--src/lib/libc/string/strtok.327
1 files changed, 19 insertions, 8 deletions
diff --git a/src/lib/libc/string/strtok.3 b/src/lib/libc/string/strtok.3
index afe851f5bc..fa2ec28cf0 100644
--- a/src/lib/libc/string/strtok.3
+++ b/src/lib/libc/string/strtok.3
@@ -33,18 +33,20 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 34.\" SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: strtok.3,v 1.9 1999/09/21 16:44:01 espie Exp $ 36.\" $OpenBSD: strtok.3,v 1.10 1999/11/09 11:20:13 art Exp $
37.\" 37.\"
38.Dd June 29, 1991 38.Dd June 29, 1991
39.Dt STRTOK 3 39.Dt STRTOK 3
40.Os 40.Os
41.Sh NAME 41.Sh NAME
42.Nm strtok 42.Nm strtok, strtok_r
43.Nd string token operations 43.Nd string token operations
44.Sh SYNOPSIS 44.Sh SYNOPSIS
45.Fd #include <string.h> 45.Fd #include <string.h>
46.Ft char * 46.Ft char *
47.Fn strtok "char *str" "const char *sep" 47.Fn strtok "char *str" "const char *sep"
48.Ft char *
49.Fn strtok_r "char *str" "const char *sep" "char **last"
48.Sh DESCRIPTION 50.Sh DESCRIPTION
49.Bf -symbolic 51.Bf -symbolic
50This interface is obsoleted by 52This interface is obsoleted by
@@ -70,9 +72,17 @@ The separator string,
70must be supplied each time, and may change between calls. 72must be supplied each time, and may change between calls.
71.Pp 73.Pp
72The 74The
75.Fn strtok_r
76function is a version of
73.Fn strtok 77.Fn strtok
74function 78that takes an explicit context argument and is reentrant.
75returns a pointer to the beginning of each subsequent token in the string, 79.Pp
80The
81.Fn strtok
82and
83.Fn strtok_r
84functions
85return a pointer to the beginning of each subsequent token in the string,
76after replacing the separator character itself with an 86after replacing the separator character itself with an
77.Tn ASCII NUL 87.Tn ASCII NUL
78character. 88character.
@@ -80,7 +90,9 @@ When no more tokens remain, a null pointer is returned.
80.Pp 90.Pp
81Since 91Since
82.Fn strtok 92.Fn strtok
83modifies the string, 93and
94.Fn strtok_r
95modify the string,
84.Fa str 96.Fa str
85should not point to an area in the initialized data segment. 97should not point to an area in the initialized data segment.
86.Pp 98.Pp
@@ -92,11 +104,12 @@ the string
92#define MAXTOKENS 128 104#define MAXTOKENS 128
93 105
94char s[512], *p, *tokens[MAXTOKENS]; 106char s[512], *p, *tokens[MAXTOKENS];
107char *last;
95int i = 0; 108int i = 0;
96 109
97snprintf(s, sizeof(s), "cat dog horse cow"); 110snprintf(s, sizeof(s), "cat dog horse cow");
98 111
99for ((p = strtok(s, " ")); p; (p = strtok(NULL, " ")), i++) { 112for ((p = strtok_r(s, " ", &last)); p; (p = strtok_r(NULL, " ", &last)), i++) {
100 if (i < MAXTOKENS - 1) 113 if (i < MAXTOKENS - 1)
101 tokens[i] = p; 114 tokens[i] = p;
102} 115}
@@ -127,8 +140,6 @@ function
127conforms to 140conforms to
128.St -ansiC . 141.St -ansiC .
129.Sh BUGS 142.Sh BUGS
130There is no way to get tokens from multiple strings simultaneously.
131.Pp
132The System V 143The System V
133.Fn strtok , 144.Fn strtok ,
134if handed a string containing only delimiter characters, 145if handed a string containing only delimiter characters,