1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" References consulted:
6 .\" Linux libc source code
7 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
9 .\" Modified Sat Jul 24 18:00:10 1993 by Rik Faith (faith@cs.unc.edu)
10 .\" Modified Mon Jan 20 12:04:18 1997 by Andries Brouwer (aeb@cwi.nl)
11 .\" Modified Tue Jan 23 20:23:07 2001 by Andries Brouwer (aeb@cwi.nl)
13 .TH strsep 3 (date) "Linux man-pages (unreleased)"
15 strsep \- extract token from string
18 .RI ( libc ", " \-lc )
21 .B #include <string.h>
23 .BI "char *strsep(char **restrict " stringp ", const char *restrict " delim );
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
35 Glibc 2.19 and earlier:
44 and does nothing else.
45 Otherwise, this function finds the first token
48 that is delimited by one of the bytes in the string
50 This token is terminated by overwriting the delimiter
51 with a null byte (\(aq\e0\(aq),
54 is updated to point past the token.
55 In case no delimiter was found, the token is taken to be
64 function returns a pointer to the token,
65 that is, it returns the original value of
68 For an explanation of the terms used in this section, see
76 Interface Attribute Value
79 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 \(aqa/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);