]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Add strsep compat function
authorArne Schwabe <arne@rfc2549.org>
Mon, 17 Feb 2020 14:43:36 +0000 (15:43 +0100)
committerGert Doering <gert@greenie.muc.de>
Mon, 17 Feb 2020 18:34:23 +0000 (19:34 +0100)
Some operating system do not have the strsep function. Since this API
is more "modern" (4.4BSD) than strtok, add it as compat function.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20200217144339.3273-3-arne@rfc2549.org>
URL: https://www.mail-archive.com/search?l=mid&q=20200217144339.3273-3-arne@rfc2549.org
Signed-off-by: Gert Doering <gert@greenie.muc.de>
configure.ac
src/compat/Makefile.am
src/compat/compat-strsep.c [new file with mode: 0644]
src/compat/compat.h
src/compat/compat.vcxproj

index 3c057295f7a63f2cb4a7e82a6244bd9de77ff775..a47ef3e7b748b6ed78f7652abbc706ab205719a1 100644 (file)
@@ -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(
index b51f661ef23ddd29a609d73e6a65a4d3bf9653c8..2e94e943c8310b732a130a9441b5666aa72b05f9 100644 (file)
@@ -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
diff --git a/src/compat/compat-strsep.c b/src/compat/compat-strsep.c
new file mode 100644 (file)
index 0000000..42ff641
--- /dev/null
@@ -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
index d5228989dd8187e6c38c09385ce745109303e977..592881df389893234dce73f5095836fb6180ce00 100644 (file)
@@ -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 */
index e388008a44044fb1e87fac36c48f37fb673c5ca1..0c4c7b0f3899bf35dcc795e4bcbb45194daacb7e 100644 (file)
     <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" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>