@@ -655,7 +655,7 @@ AC_CHECK_FUNCS([ \
ctime memset vsnprintf strdup \
setsid chdir putenv getpeername unlink \
chsize ftruncate execve getpeereid umask basename dirname access \
- epoll_create \
+ epoll_create strsep \
])
AC_CHECK_LIB(
@@ -30,4 +30,5 @@ libcompat_la_SOURCES = \
compat-inet_ntop.c \
compat-inet_pton.c \
compat-lz4.c compat-lz4.h \
+ compat-strsep.c \
compat-versionhelpers.h
new file mode 100644
@@ -0,0 +1,61 @@
+/*
+ * OpenVPN -- An application to securely tunnel IP networks
+ * over a single UDP port, with support for SSL/TLS-based
+ * session authentication and key exchange,
+ * packet encryption, packet authentication, and
+ * packet compression.
+ *
+ * Copyright (C) 2019 Arne Schwabe <arne@rfc2549.org>
+ * Copyright (C) 1992-2019 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#elif defined(_MSC_VER)
+#include "config-msvc.h"
+#endif
+
+#ifndef HAVE_STRSEP
+#include <string.h>
+
+/*
+ * Modified version based on the glibc
+ */
+char *
+strsep(char **stringp, const char *delim)
+{
+ char *begin, *end;
+ begin = *stringp;
+ if (begin == NULL)
+ {
+ return NULL;
+ }
+ /* Find the end of the token. */
+ end = begin + strcspn(begin, delim);
+ if (*end)
+ {
+ /* Terminate the token and set *STRINGP past NUL character. */
+ *end++ = '\0';
+ *stringp = end;
+ }
+ else
+ {
+ /* No more delimiters; this is the last token. */
+ *stringp = NULL;
+ }
+ return begin;
+}
+#endif
@@ -70,4 +70,8 @@ int inet_pton(int af, const char *src, void *dst);
#endif
+#ifndef HAVE_STRSEP
+char* strsep(char **stringp, const char *delim);
+#endif
+
#endif /* COMPAT_H */
@@ -102,6 +102,7 @@
<ClCompile Include="compat-inet_pton.c" />
<ClCompile Include="compat-daemon.c" />
<ClCompile Include="compat-lz4.c" />
+ <ClCompile Include="compat-strsep.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="compat.h" />
@@ -115,4 +116,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
Some operating system do not have the strsep function. Since this API is more "modern" (4.4BSD) than strtok, add it as compat function. At least Windows is missing strsep. FreeBSD, Linux, macOS and OpenSolaris should not need the compat function. Signed-off-by: Arne Schwabe <arne@rfc2549.org> --- configure.ac | 2 +- src/compat/Makefile.am | 1 + src/compat/compat-strsep.c | 61 ++++++++++++++++++++++++++++++++++++++ src/compat/compat.h | 4 +++ src/compat/compat.vcxproj | 3 +- 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/compat/compat-strsep.c