diff options
Diffstat (limited to 'src/lib/libc/string/strsep.3')
| -rw-r--r-- | src/lib/libc/string/strsep.3 | 90 |
1 files changed, 55 insertions, 35 deletions
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3 index 21aa7376f2..cceeda7577 100644 --- a/src/lib/libc/string/strsep.3 +++ b/src/lib/libc/string/strsep.3 | |||
| @@ -1,8 +1,11 @@ | |||
| 1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | 1 | .\" $OpenBSD: strsep.3,v 1.12 2007/05/31 19:19:32 jmc Exp $ |
| 2 | .\" All rights reserved. | 2 | .\" |
| 3 | .\" Copyright (c) 1990, 1991, 1993 | ||
| 4 | .\" The Regents of the University of California. All rights reserved. | ||
| 3 | .\" | 5 | .\" |
| 4 | .\" This code is derived from software contributed to Berkeley by | 6 | .\" This code is derived from software contributed to Berkeley by |
| 5 | .\" Chris Torek. | 7 | .\" Chris Torek. |
| 8 | .\" | ||
| 6 | .\" Redistribution and use in source and binary forms, with or without | 9 | .\" Redistribution and use in source and binary forms, with or without |
| 7 | .\" modification, are permitted provided that the following conditions | 10 | .\" modification, are permitted provided that the following conditions |
| 8 | .\" are met: | 11 | .\" are met: |
| @@ -11,11 +14,7 @@ | |||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | .\" notice, this list of conditions and the following disclaimer in the | 15 | .\" notice, this list of conditions and the following disclaimer in the |
| 13 | .\" documentation and/or other materials provided with the distribution. | 16 | .\" documentation and/or other materials provided with the distribution. |
| 14 | .\" 3. All advertising materials mentioning features or use of this software | 17 | .\" 3. Neither the name of the University nor the names of its contributors |
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | 18 | .\" may be used to endorse or promote products derived from this software |
| 20 | .\" without specific prior written permission. | 19 | .\" without specific prior written permission. |
| 21 | .\" | 20 | .\" |
| @@ -31,10 +30,9 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. |
| 33 | .\" | 32 | .\" |
| 34 | .\" from: @(#)strsep.3 5.3 (Berkeley) 4/19/91 | 33 | .\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 |
| 35 | .\" $Id: strsep.3,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $ | ||
| 36 | .\" | 34 | .\" |
| 37 | .Dd April 19, 1991 | 35 | .Dd $Mdocdate: May 31 2007 $ |
| 38 | .Dt STRSEP 3 | 36 | .Dt STRSEP 3 |
| 39 | .Os | 37 | .Os |
| 40 | .Sh NAME | 38 | .Sh NAME |
| @@ -43,27 +41,37 @@ | |||
| 43 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
| 44 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
| 45 | .Ft char * | 43 | .Ft char * |
| 46 | .Fn strsep "char **stringp" "char *delim" | 44 | .Fn strsep "char **stringp" "const char *delim" |
| 47 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION |
| 48 | The | 46 | The |
| 49 | .Fn strsep | 47 | .Fn strsep |
| 50 | locates in the null-terminated string at | 48 | function locates, in the string referenced by |
| 51 | .Fa *stringp | ||
| 52 | the first occurrence of any character in | ||
| 53 | .Fa delim | ||
| 54 | and replaces this with a | ||
| 55 | .Ql \e0 , | ||
| 56 | records the location of the immediate following character in | ||
| 57 | .Fa *stringp , | 49 | .Fa *stringp , |
| 58 | then returns the original value of | 50 | the first occurrence of any character in the string |
| 51 | .Fa delim | ||
| 52 | (or the terminating | ||
| 53 | .Ql \e0 | ||
| 54 | character) and replaces it with a | ||
| 55 | .Ql \e0 . | ||
| 56 | The location of the next character after the delimiter character | ||
| 57 | (or | ||
| 58 | .Dv NULL , | ||
| 59 | if the end of the string was reached) is stored in | ||
| 59 | .Fa *stringp . | 60 | .Fa *stringp . |
| 60 | If no delimiter characters are found, | 61 | The original value of |
| 61 | .Fn strsep | ||
| 62 | sets | ||
| 63 | .Fa *stringp | 62 | .Fa *stringp |
| 63 | is returned. | ||
| 64 | .Pp | ||
| 65 | An | ||
| 66 | .Dq empty | ||
| 67 | field, i.e., one caused by two adjacent delimiter characters, | ||
| 68 | can be detected by comparing the location referenced by the pointer returned | ||
| 69 | by | ||
| 70 | .Fn strsep | ||
| 64 | to | 71 | to |
| 65 | .Dv NULL ; | 72 | .Ql \e0 . |
| 66 | if | 73 | .Pp |
| 74 | If | ||
| 67 | .Fa *stringp | 75 | .Fa *stringp |
| 68 | is initially | 76 | is initially |
| 69 | .Dv NULL , | 77 | .Dv NULL , |
| @@ -73,20 +81,32 @@ returns | |||
| 73 | .Sh EXAMPLES | 81 | .Sh EXAMPLES |
| 74 | The following uses | 82 | The following uses |
| 75 | .Fn strsep | 83 | .Fn strsep |
| 76 | to parse strings containing runs of white space, | 84 | to parse a string, containing tokens delimited by whitespace, into an |
| 77 | making up an argument vector: | 85 | argument vector: |
| 78 | .Bd -literal -offset indent | 86 | .Bd -literal -offset indent |
| 79 | char inputstring[100]; | 87 | char **ap, *argv[10], *inputstring; |
| 80 | char **argv[51], **ap = argv, *p, *val; | 88 | |
| 81 | /* set up inputstring */ | 89 | for (ap = argv; ap < &argv[9] && |
| 82 | for (p = inputstring; p != NULL; ) { | 90 | (*ap = strsep(&inputstring, " \et")) != NULL;) { |
| 83 | while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); | 91 | if (**ap != '\e0') |
| 84 | *ap++ = val; | 92 | ap++; |
| 85 | } | 93 | } |
| 86 | *ap = 0; | 94 | *ap = NULL; |
| 87 | .Ed | 95 | .Ed |
| 88 | .Sh HISTORY | 96 | .Sh HISTORY |
| 89 | The | 97 | The |
| 90 | .Fn strsep | 98 | .Fn strsep |
| 91 | function is | 99 | function is intended as a replacement for the |
| 92 | .Ud . | 100 | .Fn strtok |
| 101 | function. | ||
| 102 | While the | ||
| 103 | .Fn strtok | ||
| 104 | function should be preferred for portability reasons (it conforms to | ||
| 105 | .St -ansiC ) | ||
| 106 | it is unable to handle empty fields, i.e., detect fields delimited by | ||
| 107 | two adjacent delimiter characters, or to be used for more than a single | ||
| 108 | string at a time. | ||
| 109 | The | ||
| 110 | .Fn strsep | ||
| 111 | function first appeared in | ||
| 112 | .Bx 4.4 . | ||
