2 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" References consulted:
7 .\" Linux libc source code
8 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
10 .\" Modified Sat Jul 24 18:00:10 1993 by Rik Faith (faith@cs.unc.edu)
11 .\" Modified Mon Jan 20 12:04:18 1997 by Andries Brouwer (aeb@cwi.nl)
12 .\" Modified Tue Jan 23 20:23:07 2001 by Andries Brouwer (aeb@cwi.nl)
14 .TH strsep 3 (date) "Linux man-pages (unreleased)"
16 strsep \- extract token from string
19 .RI ( libc ", " \-lc )
22 .B #include <string.h>
24 .BI "char *strsep(char **restrict " stringp ", const char *restrict " delim );
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
36 glibc 2.19 and earlier:
45 and does nothing else.
46 Otherwise, this function finds the first token
49 that is delimited by one of the bytes in the string
51 This token is terminated by overwriting the delimiter
52 with a null byte (\[aq]\e0\[aq]),
55 is updated to point past the token.
56 In case no delimiter was found, the token is taken to be
65 function returns a pointer to the token,
66 that is, it returns the original value of
69 For an explanation of the terms used in this section, see
75 Interface Attribute Value
80 T} Thread safety MT-Safe
89 function was introduced as a replacement for
91 since the latter cannot handle empty fields.
94 conforms to C89/C99 and hence is more portable.
96 Be cautious when using this function.
97 If you do use it, note that:
99 This function modifies its first argument.
101 This function cannot be used on constant strings.
103 The identity of the delimiting character is lost.
105 The program below is a port of the one found in
107 which, however, doesn't discard multiple delimiters or empty tokens:
111 .RB "$" " ./a.out \[aq]a/bbb///cc;xxx:yyy:\[aq] \[aq]:;\[aq] \[aq]/\[aq]"
128 .\" SRC BEGIN (strsep.c)
135 main(int argc, char *argv[])
137 char *token, *subtoken;
140 fprintf(stderr, "Usage: %s string delim subdelim\en", argv[0]);
144 for (unsigned int j = 1; (token = strsep(&argv[1], argv[2])); j++) {
145 printf("%u: %s\en", j, token);
147 while ((subtoken = strsep(&token, argv[3])))
148 printf("\et \-\-> %s\en", subtoken);