From 5e415c510012f2f4bc7d63d016ceb1a3f1d8a655 Mon Sep 17 00:00:00 2001 From: Niclas Zeising Date: Fri, 22 Feb 2013 13:24:44 +0100 Subject: [PATCH] Add local implementation of strchrnul() strchrnul() is a gnu extention to libc, and some platforms (most notably FreeBSD) lacks this function. Add a local implementation of this function, together with a configure check for strchrnul(), and use the library function instead of the local copy if it exists. --- configure.ac | 4 ++++ tests/modetest/Makefile.am | 5 +++++ tests/modetest/modetest.c | 4 ++++ tests/modetest/strchrnul.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 tests/modetest/strchrnul.c diff --git a/configure.ac b/configure.ac index e2e3466..e2dfeec 100644 --- a/configure.ac +++ b/configure.ac @@ -121,6 +121,10 @@ AC_SUBST([CLOCK_LIB]) AC_CHECK_FUNCS([open_memstream], [HAVE_OPEN_MEMSTREAM=yes]) +AC_CHECK_FUNCS([strchrnul], [HAVE_STRCHRNUL=yes]) + +AM_CONDITIONAL(HAVE_STRCHRNUL, [test "x$ac_cv_func_strchrnul" = xyes]) + dnl Use lots of warning flags with with gcc and compatible compilers dnl Note: if you change the following variable, the cache is automatically diff --git a/tests/modetest/Makefile.am b/tests/modetest/Makefile.am index 065ae13..9025ad6 100644 --- a/tests/modetest/Makefile.am +++ b/tests/modetest/Makefile.am @@ -9,6 +9,11 @@ noinst_PROGRAMS = \ modetest_SOURCES = \ buffers.c modetest.c buffers.h +if !HAVE_STRCHRNUL +modetest_SOURCES += \ + strchrnul.c +endif + modetest_LDADD = \ $(top_builddir)/libdrm.la \ $(top_builddir)/libkms/libkms.la diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index c91bb9d..0f09a31 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -57,6 +57,10 @@ #include "buffers.h" +#ifndef HAVE_STRCHRNUL +char *strchrnul(const char *, int); +#endif + drmModeRes *resources; int fd, modes; diff --git a/tests/modetest/strchrnul.c b/tests/modetest/strchrnul.c new file mode 100644 index 0000000..3b1c981 --- /dev/null +++ b/tests/modetest/strchrnul.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2013 Niclas Zeising + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/* + * Copied from: + * svn://svn.freebsd.org/base/head/lib/libc/string/strchrnul.c revision 246766 + */ + +char * +strchrnul(const char *p, int ch) +{ + char c; + + c = ch; + for (;; ++p) { + if (*p == c || *p == '\0') + return ((char *)p); + } + /* NOTREACHED */ +} + -- 1.8.0.1