diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/string/strtok.3 | 27 |
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 |
| 50 | This interface is obsoleted by | 52 | This interface is obsoleted by |
| @@ -70,9 +72,17 @@ The separator string, | |||
| 70 | must be supplied each time, and may change between calls. | 72 | must be supplied each time, and may change between calls. |
| 71 | .Pp | 73 | .Pp |
| 72 | The | 74 | The |
| 75 | .Fn strtok_r | ||
| 76 | function is a version of | ||
| 73 | .Fn strtok | 77 | .Fn strtok |
| 74 | function | 78 | that takes an explicit context argument and is reentrant. |
| 75 | returns a pointer to the beginning of each subsequent token in the string, | 79 | .Pp |
| 80 | The | ||
| 81 | .Fn strtok | ||
| 82 | and | ||
| 83 | .Fn strtok_r | ||
| 84 | functions | ||
| 85 | return a pointer to the beginning of each subsequent token in the string, | ||
| 76 | after replacing the separator character itself with an | 86 | after replacing the separator character itself with an |
| 77 | .Tn ASCII NUL | 87 | .Tn ASCII NUL |
| 78 | character. | 88 | character. |
| @@ -80,7 +90,9 @@ When no more tokens remain, a null pointer is returned. | |||
| 80 | .Pp | 90 | .Pp |
| 81 | Since | 91 | Since |
| 82 | .Fn strtok | 92 | .Fn strtok |
| 83 | modifies the string, | 93 | and |
| 94 | .Fn strtok_r | ||
| 95 | modify the string, | ||
| 84 | .Fa str | 96 | .Fa str |
| 85 | should not point to an area in the initialized data segment. | 97 | should 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 | ||
| 94 | char s[512], *p, *tokens[MAXTOKENS]; | 106 | char s[512], *p, *tokens[MAXTOKENS]; |
| 107 | char *last; | ||
| 95 | int i = 0; | 108 | int i = 0; |
| 96 | 109 | ||
| 97 | snprintf(s, sizeof(s), "cat dog horse cow"); | 110 | snprintf(s, sizeof(s), "cat dog horse cow"); |
| 98 | 111 | ||
| 99 | for ((p = strtok(s, " ")); p; (p = strtok(NULL, " ")), i++) { | 112 | for ((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 | |||
| 127 | conforms to | 140 | conforms to |
| 128 | .St -ansiC . | 141 | .St -ansiC . |
| 129 | .Sh BUGS | 142 | .Sh BUGS |
| 130 | There is no way to get tokens from multiple strings simultaneously. | ||
| 131 | .Pp | ||
| 132 | The System V | 143 | The System V |
| 133 | .Fn strtok , | 144 | .Fn strtok , |
| 134 | if handed a string containing only delimiter characters, | 145 | if handed a string containing only delimiter characters, |
