From 0b83088b0ef17c4b210f41b1debcd6c3dc1fc30a Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 19 Sep 2014 19:07:59 +0000 Subject: [PATCH] #2934, support strcasestr for platforms that (passing understanding) do not have it git-svn-id: http://svn.osgeo.org/postgis/trunk@12989 b70326c6-7e19-0410-871a-916f4a2858ee --- configure.ac | 1 + liblwgeom/liblwgeom.h.in | 3 +++ liblwgeom/lwutil.c | 21 +++++++++++++++++++++ postgis_config.h.in | 1 + 4 files changed, 26 insertions(+) diff --git a/configure.ac b/configure.ac index f381763f2..671f51e42 100644 --- a/configure.ac +++ b/configure.ac @@ -114,6 +114,7 @@ dnl Check for platform-specific functions dnl AC_CHECK_FUNC(vasprintf, AC_DEFINE([HAVE_VASPRINTF])) AC_CHECK_FUNC(asprintf, AC_DEFINE([HAVE_ASPRINTF])) +AC_CHECK_FUNC(strcasestr, AC_DEFINE([HAVE_STRCASESTR])) AC_FUNC_FSEEKO() dnl diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 2566beecb..976081d78 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -1877,6 +1877,9 @@ extern void lwfree(void *mem); /* Utilities */ extern char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int truncdirection); +#ifndef HAVE_STRCASESTR +extern char *strcasestr(const char *s, const char *find); +#endif /******************************************************************************* * SQLMM internal functions - TODO: Move into separate header files diff --git a/liblwgeom/lwutil.c b/liblwgeom/lwutil.c index 3c4a6bbb0..2f858f70d 100644 --- a/liblwgeom/lwutil.c +++ b/liblwgeom/lwutil.c @@ -342,3 +342,24 @@ clamp_srid(int srid) return newsrid; } + +#ifndef HAVE_STRCASESTR +char *strcasestr(const char *s, const char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} +#endif diff --git a/postgis_config.h.in b/postgis_config.h.in index 2fe598ae6..3d46de2a6 100644 --- a/postgis_config.h.in +++ b/postgis_config.h.in @@ -28,6 +28,7 @@ #undef HAVE_ISFINITE #undef HAVE_GNU_ISFINITE #undef HAVE_FSEEKO +#undef HAVE_STRCASESTR /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H -- 2.40.0