OpenVPN
compat-strsep.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2019-2025 Arne Schwabe <arne@rfc2549.org>
9 * Copyright (C) 1992-2019 Free Software Foundation, Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#ifndef HAVE_STRSEP
29#include <string.h>
30
31/*
32 * Modified version based on the glibc
33 */
34char *
35strsep(char **stringp, const char *delim)
36{
37 char *begin, *end;
38 begin = *stringp;
39 if (begin == NULL)
40 {
41 return NULL;
42 }
43 /* Find the end of the token. */
44 end = begin + strcspn(begin, delim);
45 if (*end)
46 {
47 /* Terminate the token and set *STRINGP past NUL character. */
48 *end++ = '\0';
49 *stringp = end;
50 }
51 else
52 {
53 /* No more delimiters; this is the last token. */
54 *stringp = NULL;
55 }
56 return begin;
57}
58#endif /* ifndef HAVE_STRSEP */
char * strsep(char **stringp, const char *delim)