Browse code

Add strsep compat function

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>

Arne Schwabe authored on 2020/02/17 23:43:36
Showing 5 changed files
... ...
@@ -655,7 +655,7 @@ AC_CHECK_FUNCS([ \
655 655
 	ctime memset vsnprintf strdup \
656 656
 	setsid chdir putenv getpeername unlink \
657 657
 	chsize ftruncate execve getpeereid umask basename dirname access \
658
-	epoll_create \
658
+	epoll_create strsep \
659 659
 ])
660 660
 
661 661
 AC_CHECK_LIB(
... ...
@@ -30,4 +30,5 @@ libcompat_la_SOURCES = \
30 30
 	compat-inet_ntop.c \
31 31
 	compat-inet_pton.c \
32 32
 	compat-lz4.c compat-lz4.h \
33
+	compat-strsep.c \
33 34
 	compat-versionhelpers.h
34 35
new file mode 100644
... ...
@@ -0,0 +1,61 @@
0
+/*
1
+ *  OpenVPN -- An application to securely tunnel IP networks
2
+ *             over a single UDP port, with support for SSL/TLS-based
3
+ *             session authentication and key exchange,
4
+ *             packet encryption, packet authentication, and
5
+ *             packet compression.
6
+ *
7
+ *  Copyright (C) 2019 Arne Schwabe <arne@rfc2549.org>
8
+ *  Copyright (C) 1992-2019 Free Software Foundation, Inc.
9
+ *
10
+ *  This program is free software; you can redistribute it and/or modify
11
+ *  it under the terms of the GNU General Public License version 2
12
+ *  as published by the Free Software Foundation.
13
+ *
14
+ *  This program is distributed in the hope that it will be useful,
15
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ *  GNU General Public License for more details.
18
+ *
19
+ *  You should have received a copy of the GNU General Public License along
20
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
21
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
+ */
23
+
24
+#ifdef HAVE_CONFIG_H
25
+#include "config.h"
26
+#elif defined(_MSC_VER)
27
+#include "config-msvc.h"
28
+#endif
29
+
30
+#ifndef HAVE_STRSEP
31
+#include <string.h>
32
+
33
+/*
34
+ * Modified version based on the glibc
35
+ */
36
+char *
37
+strsep(char **stringp, const char *delim)
38
+{
39
+    char *begin, *end;
40
+    begin = *stringp;
41
+    if (begin == NULL)
42
+    {
43
+        return NULL;
44
+    }
45
+    /* Find the end of the token.  */
46
+    end = begin + strcspn(begin, delim);
47
+    if (*end)
48
+    {
49
+        /* Terminate the token and set *STRINGP past NUL character.  */
50
+        *end++ = '\0';
51
+        *stringp = end;
52
+    }
53
+    else
54
+    {
55
+        /* No more delimiters; this is the last token.  */
56
+        *stringp = NULL;
57
+    }
58
+    return begin;
59
+}
60
+#endif
... ...
@@ -70,4 +70,8 @@ int inet_pton(int af, const char *src, void *dst);
70 70
 
71 71
 #endif
72 72
 
73
+#ifndef HAVE_STRSEP
74
+char* strsep(char **stringp, const char *delim);
75
+#endif
76
+
73 77
 #endif /* COMPAT_H */
... ...
@@ -102,6 +102,7 @@
102 102
     <ClCompile Include="compat-inet_pton.c" />
103 103
     <ClCompile Include="compat-daemon.c" />
104 104
     <ClCompile Include="compat-lz4.c" />
105
+    <ClCompile Include="compat-strsep.c" />
105 106
   </ItemGroup>
106 107
   <ItemGroup>
107 108
     <ClInclude Include="compat.h" />
... ...
@@ -115,4 +116,4 @@
115 115
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
116 116
   <ImportGroup Label="ExtensionTargets">
117 117
   </ImportGroup>
118
-</Project>
119 118
\ No newline at end of file
119
+</Project>