summaryrefslogtreecommitdiff
path: root/lib/compat
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2018-07-12 02:14:48 +0200
committerGuillem Jover <guillem@debian.org>2018-08-30 03:14:08 +0200
commitfbed23421fe867d76e6123d2cf79ffafeed5aafd (patch)
tree921f00f02c2f76cb17db02125f6c90ba2b4463b1 /lib/compat
parentc7c948d8b9ed774163d35c573f25029d69e45348 (diff)
downloaddpkg-fbed23421fe867d76e6123d2cf79ffafeed5aafd.tar.gz
libcompat: Add new strchrnul() compat function
Diffstat (limited to 'lib/compat')
-rw-r--r--lib/compat/Makefile.am5
-rw-r--r--lib/compat/compat.h6
-rw-r--r--lib/compat/strchrnul.c37
3 files changed, 48 insertions, 0 deletions
diff --git a/lib/compat/Makefile.am b/lib/compat/Makefile.am
index 19ddcef86..4477c27b4 100644
--- a/lib/compat/Makefile.am
+++ b/lib/compat/Makefile.am
@@ -11,6 +11,7 @@ libcompat_test_la_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_LIBCOMPAT=1
libcompat_test_la_SOURCES = \
compat.h \
md5.c md5.h \
+ strchrnul.c \
strnlen.c \
strndup.c \
strsignal.c \
@@ -57,6 +58,10 @@ if !HAVE_STRNLEN
libcompat_la_SOURCES += strnlen.c
endif
+if !HAVE_STRCHRNUL
+libcompat_la_SOURCES += strchrnul.c
+endif
+
if !HAVE_STRNDUP
libcompat_la_SOURCES += strndup.c
endif
diff --git a/lib/compat/compat.h b/lib/compat/compat.h
index 320ffdbc9..c1aa60180 100644
--- a/lib/compat/compat.h
+++ b/lib/compat/compat.h
@@ -109,6 +109,8 @@ extern "C" {
#define asprintf test_asprintf
#undef vasprintf
#define vasprintf test_vasprintf
+#undef strchrnul
+#define strchrnul test_strchrnul
#undef strndup
#define strndup test_strndup
#undef strnlen
@@ -139,6 +141,10 @@ int vasprintf(char **str, const char *fmt, va_list args)
LIBCOMPAT_ATTR_VPRINTF(2);
#endif
+#if TEST_LIBCOMPAT || !defined(HAVE_STRCHRNUL)
+char *strchrnul(const char *s, int c);
+#endif
+
#if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN)
size_t strnlen(const char *s, size_t n);
#endif
diff --git a/lib/compat/strchrnul.c b/lib/compat/strchrnul.c
new file mode 100644
index 000000000..b072e1ad3
--- /dev/null
+++ b/lib/compat/strchrnul.c
@@ -0,0 +1,37 @@
+/*
+ * libcompat - system compatibility library
+ *
+ * Copyright © 2018 Guillem Jover <guillem@debian.org>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "compat.h"
+
+char *
+strchrnul(const char *s, int c)
+{
+ char *match;
+
+ match = strchr(s, c);
+ if (match)
+ return match;
+
+ return (char *)s + strlen(s);
+}