summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormillert <>1997-08-20 04:28:14 +0000
committermillert <>1997-08-20 04:28:14 +0000
commitd9e9dd15aef27c2a7246403ea76898fa1a4c061a (patch)
tree3ea56483928248a93c3560051206ccfcceb1c614
parent4faa3305b950b8ac8eaa6c02f8d7099f2e0f623d (diff)
downloadopenbsd-d9e9dd15aef27c2a7246403ea76898fa1a4c061a.tar.gz
openbsd-d9e9dd15aef27c2a7246403ea76898fa1a4c061a.tar.bz2
openbsd-d9e9dd15aef27c2a7246403ea76898fa1a4c061a.zip
Update from lite2.
-rw-r--r--src/lib/libc/string/strsep.376
-rw-r--r--src/lib/libc/string/strsep.c21
2 files changed, 61 insertions, 36 deletions
diff --git a/src/lib/libc/string/strsep.3 b/src/lib/libc/string/strsep.3
index 0cae3e0f1b..471e693ecc 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.3 1997/08/20 04:28:13 millert 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:
@@ -31,9 +34,9 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 35.\" SUCH DAMAGE.
33.\" 36.\"
34.\" $OpenBSD: strsep.3,v 1.2 1996/08/19 08:34:24 tholo Exp $ 37.\" @(#)strsep.3 8.1 (Berkeley) 6/9/93
35.\" 38.\"
36.Dd April 19, 1991 39.Dd June 9, 1993
37.Dt STRSEP 3 40.Dt STRSEP 3
38.Os 41.Os
39.Sh NAME 42.Sh NAME
@@ -46,23 +49,29 @@
46.Sh DESCRIPTION 49.Sh DESCRIPTION
47The 50The
48.Fn strsep 51.Fn strsep
49locates in the null-terminated string at 52function locates, in the string referenced by
50.Fa *stringp
51the first occurrence of any character in
52.Fa delim
53and replaces this with a
54.Ql \e0 ,
55records the location of the immediate following character in
56.Fa *stringp , 53.Fa *stringp ,
57then returns the original value of 54the first occurrence of any character in the string
55.Fa delim
56(or the terminating
57.Ql \e0
58character) and replaces it with a
59.Ql \e0 .
60The location of the next character after the delimiter character
61(or NULL, if the end of the string was reached) is stored in
58.Fa *stringp . 62.Fa *stringp .
59If no delimiter characters are found, 63The original value of
60.Fn strsep 64.Fa *stringp
61sets 65is returned.
66.Pp
67An ``empty'' field, i.e. one caused by two adjacent delimiter characters,
68can be detected by comparing the location referenced by the pointer returned
69in
62.Fa *stringp 70.Fa *stringp
63to 71to
64.Dv NULL ; 72.Ql \e0 .
65if 73.Pp
74If
66.Fa *stringp 75.Fa *stringp
67is initially 76is initially
68.Dv NULL , 77.Dv NULL ,
@@ -72,20 +81,29 @@ returns
72.Sh EXAMPLES 81.Sh EXAMPLES
73The following uses 82The following uses
74.Fn strsep 83.Fn strsep
75to parse strings containing runs of white space, 84to parse a string, containing tokens delimited by white space, into an
76making up an argument vector: 85argument vector:
77.Bd -literal -offset indent 86.Bd -literal -offset indent
78char inputstring[100]; 87char **ap, *argv[10], *inputstring;
79char **argv[51], **ap = argv, *p, *val; 88
80/* set up inputstring */ 89for (ap = argv; (*ap = strsep(&inputstring, " \et")) != NULL;)
81for (p = inputstring; p != NULL; ) { 90 if (**ap != '\e0')
82 while ((val = strsep(&p, " \et")) != NULL && *val == '\e0'); 91 ++ap;
83 *ap++ = val;
84}
85*ap = 0;
86.Ed 92.Ed
87.Sh HISTORY 93.Sh HISTORY
88The 94The
89.Fn strsep 95.Fn strsep
90function is 96function
91.Ud . 97is intended as a replacement for the
98.Fn strtok
99function.
100While the
101.Fn strtok
102function should be preferred for portability reasons (it conforms to
103.St -ansiC )
104it is unable to handle empty fields, i.e. detect fields delimited by
105two adjacent delimiter characters, or to be used for more than a single
106string at a time.
107The
108.Fn strsep
109function first appeared in 4.4BSD.
diff --git a/src/lib/libc/string/strsep.c b/src/lib/libc/string/strsep.c
index 09f187b62d..b69b715fc5 100644
--- a/src/lib/libc/string/strsep.c
+++ b/src/lib/libc/string/strsep.c
@@ -1,6 +1,8 @@
1/* $OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $ */
2
1/*- 3/*-
2 * Copyright (c) 1990 The Regents of the University of California. 4 * Copyright (c) 1990, 1993
3 * All rights reserved. 5 * The Regents of the University of California. All rights reserved.
4 * 6 *
5 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
@@ -31,14 +33,19 @@
31 * SUCH DAMAGE. 33 * SUCH DAMAGE.
32 */ 34 */
33 35
36#include <string.h>
37#include <stdio.h>
38
34#if defined(LIBC_SCCS) && !defined(lint) 39#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: strsep.c,v 1.2 1996/08/19 08:34:24 tholo Exp $"; 40#if 0
41static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93";
42#else
43static char *rcsid = "$OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $";
44#endif
36#endif /* LIBC_SCCS and not lint */ 45#endif /* LIBC_SCCS and not lint */
37 46
38#include <string.h>
39
40/* 47/*
41 * Get next token from string *stringp, where tokens are nonempty 48 * Get next token from string *stringp, where tokens are possibly-empty
42 * strings separated by characters from delim. 49 * strings separated by characters from delim.
43 * 50 *
44 * Writes NULs into the string at *stringp to end tokens. 51 * Writes NULs into the string at *stringp to end tokens.
@@ -46,7 +53,7 @@ static char *rcsid = "$OpenBSD: strsep.c,v 1.2 1996/08/19 08:34:24 tholo Exp $";
46 * On return, *stringp points past the last NUL written (if there might 53 * On return, *stringp points past the last NUL written (if there might
47 * be further tokens), or is NULL (if there are definitely no more tokens). 54 * be further tokens), or is NULL (if there are definitely no more tokens).
48 * 55 *
49 * If *stringp is NULL, strtoken returns NULL. 56 * If *stringp is NULL, strsep returns NULL.
50 */ 57 */
51char * 58char *
52strsep(stringp, delim) 59strsep(stringp, delim)