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>
This commit is contained in:
Arne Schwabe 2020-02-17 15:43:36 +01:00 committed by Gert Doering
parent 868b200c3a
commit 0a88ef8c2a
5 changed files with 69 additions and 2 deletions

View 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(

View 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

View File

@ -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

View 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 */

View File

@ -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>
</Project>