diff options
Diffstat (limited to 'man3/strtok.3')
-rw-r--r-- | man3/strtok.3 | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/man3/strtok.3 b/man3/strtok.3 new file mode 100644 index 000000000..44014e3ff --- /dev/null +++ b/man3/strtok.3 @@ -0,0 +1,110 @@ +.\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl) +.\" +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" +.\" Rewritten old page, 960210, aeb@cwi.nl +.\" Updated, added strtok_r. 2000-02-13 Nicolás Lichtmaier <nick@debian.org> +.TH STRTOK 3 2000-02-13 "GNU" "Linux Programmer's Manual" +.SH NAME +strtok, strtok_r \- extract tokens from strings +.SH SYNOPSIS +.nf +.B #include <string.h> +.sp +.BI "char *strtok(char *" s ", const char *" delim ); +.sp +.BI "char *strtok_r(char *" s ", const char *" delim ", char **" ptrptr ); +.fi +.SH DESCRIPTION +A `token' is a nonempty string of characters not occurring in +the string \fIdelim\fP, followed by \e0 or by a character occurring +in \fIdelim\fP. +.PP +The \fBstrtok()\fP function can be used to parse the string \fIs\fP +into tokens. The first call to \fBstrtok()\fP should have \fIs\fP +as its first argument. Subsequent calls should have the first argument +set to NULL. Each call returns a pointer to the next token, or NULL +when no more tokens are found. +.PP +If a token ends with a delimiter, this delimiting character is +overwritten with a \e0 and a pointer to the next character is +saved for the next call to \fBstrtok()\fP. +The delimiter string \fIdelim\fP may be different for each call. +.PP +The +.B strtok_r() +function is a reentrant version of the +.B strtok() +function, which instead of using its own static buffer, requires a pointer +to a user allocated char*. This pointer, the +.I ptrptr +parameter, must be the same while parsing the same string. +.\" .SH EXAMPLE +.\" The following parses words out of a string, using 'white space' +.\" separators, with +.\" .BR strtok_r() : +.\" .PP +.\" .nf +.\" char buf[128]; +.\" char *sep = " \\t\\n"; +.\" char *tok, *cb; +.\" +.\" snprintf(buf, sizeof(buf), "%s", " One Two\\tThree\\nFour\\n\\n"); +.\" +.\" for ( tok = strtok_r(buf, sep, &cb); tok; +.\" tok = strtok_r(NULL, sep, &cb) ) +.\" printf("%s\\n", tok); +.\" .fi +.SH BUGS +Never use these functions. If you do, note that: +.PP +.RS +These functions modify their first argument. +.PP +These functions cannot be used on constant strings. +.PP +The identity of the delimiting character is lost. +.PP +The +.BR strtok () +function uses a static buffer while parsing, so it's not thread safe. Use +.BR strtok_r () +if this matters to you. +.RE +.SH "RETURN VALUE" +The \fBstrtok()\fP function returns a pointer to the next token, or +NULL if there are no more tokens. +.SH "CONFORMING TO" +.TP +strtok() +SVID 3, POSIX, BSD 4.3, ISO 9899 +.TP +strtok_r() +POSIX.1c +.SH "SEE ALSO" +.BR index (3), +.BR memchr (3), +.BR rindex (3), +.BR strchr (3), +.BR strpbrk (3), +.BR strsep (3), +.BR strspn (3), +.BR strstr (3) |