1strsep(3)                  Library Functions Manual                  strsep(3)
2
3
4

NAME

6       strsep - extract token from string
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <string.h>
13
14       char *strsep(char **restrict stringp, const char *restrict delim);
15
16   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18       strsep():
19           Since glibc 2.19:
20               _DEFAULT_SOURCE
21           glibc 2.19 and earlier:
22               _BSD_SOURCE
23

DESCRIPTION

25       If  *stringp is NULL, the strsep() function returns NULL and does noth‐
26       ing else.  Otherwise, this function finds the first token in the string
27       *stringp  that  is  delimited  by one of the bytes in the string delim.
28       This token is terminated by overwriting the delimiter with a null  byte
29       ('\0'),  and  *stringp  is updated to point past the token.  In case no
30       delimiter was found, the  token  is  taken  to  be  the  entire  string
31       *stringp, and *stringp is made NULL.
32

RETURN VALUE

34       The  strsep()  function returns a pointer to the token, that is, it re‐
35       turns the original value of *stringp.
36

ATTRIBUTES

38       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
39       tributes(7).
40
41       ┌────────────────────────────────────────────┬───────────────┬─────────┐
42Interface                                   Attribute     Value   
43       ├────────────────────────────────────────────┼───────────────┼─────────┤
44strsep()                                    │ Thread safety │ MT-Safe │
45       └────────────────────────────────────────────┴───────────────┴─────────┘
46

STANDARDS

48       None.
49

HISTORY

51       4.4BSD.
52
53       The  strsep()  function  was introduced as a replacement for strtok(3),
54       since the  latter  cannot  handle  empty  fields.   However,  strtok(3)
55       conforms to C89/C99 and hence is more portable.
56

BUGS

58       Be cautious when using this function.  If you do use it, note that:
59
60       •  This function modifies its first argument.
61
62       •  This function cannot be used on constant strings.
63
64       •  The identity of the delimiting character is lost.
65

EXAMPLES

67       The  program  below  is  a  port  of the one found in strtok(3), which,
68       however, doesn't discard multiple delimiters or empty tokens:
69
70           $ ./a.out 'a/bbb///cc;xxx:yyy:' ':;' '/'
71           1: a/bbb///cc
72                    --> a
73                    --> bbb
74                    -->
75                    -->
76                    --> cc
77           2: xxx
78                    --> xxx
79           3: yyy
80                    --> yyy
81           4:
82                    -->
83
84   Program source
85
86       #include <stdio.h>
87       #include <stdlib.h>
88       #include <string.h>
89
90       int
91       main(in