Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
Allow strcasecmp on Windows, because sometimes only POSIX is provided…
Browse files Browse the repository at this point in the history
… there.
  • Loading branch information
the3dfxdude committed Jun 22, 2019
1 parent 75a6f7e commit ce4b11f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 7 deletions.
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ AC_TYPE_UINT8_T
# Checks for library functions.
AC_CHECK_FUNCS([_NSGetExecutablePath])

AX_STRING_STRCASECMP
if test x"$ac_cv_string_strcasecmp" = "xno" ; then
AX_STRINGS_STRCASECMP
fi

AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.19])

Expand Down
18 changes: 11 additions & 7 deletions include/posix_string_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
#ifndef _POSIX_STRING_COMPAT_H
#define _POSIX_STRING_COMPAT_H

#include <string.h>

#ifndef USE_WINDOWS
#include <strings.h>
#define strcmpi(s1,s2) strcasecmp(s1,s2)
#define strnicmp(s1,s2,len) strncasecmp(s1,s2,len)
#ifdef HAVE_STRING_STRCASECMP
#include <string.h>
#define strcmpi(s1,s2) strcasecmp(s1,s2)
#define strnicmp(s1,s2,len) strncasecmp(s1,s2,len)
#elif HAVE_STRINGS_STRCASECMP
#include <strings.h>
#define strcmpi(s1,s2) strcasecmp(s1,s2)
#define strnicmp(s1,s2,len) strncasecmp(s1,s2,len)
#else
#include <string.h>
// platform provides strcmpi and strnicmp
#endif


#endif // _POSIX_STRING_COMPAT_H
52 changes: 52 additions & 0 deletions m4/ax_string_strcasecmp.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_string_strcasecmp.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_STRING_STRCASECMP
#
# DESCRIPTION
#
# This macro tries to find strcasecmp() in string.h.
#
# Use this macro in conjunction with AX_STRINGS_STRCASECMP in your
# configure.in like so:
#
# AX_STRING_STRCASECMP
# if test x"$ac_cv_string_strcasecmp" = "xno" ; then
# AX_STRINGS_STRCASECMP
# fi
#
# This will cause either HAVE_STRING_STRCASECMP or HAVE_STRINGS_STRCASECMP
# to be defined in config.h, which will tell your code what header to
# include to get strcasecmp()'s prototype.
#
# LICENSE
#
# Copyright (c) 2008 Warren Young <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 9

AU_ALIAS([ETR_STRING_STRCASECMP], [AX_STRING_STRCASECMP])
AC_DEFUN([AX_STRING_STRCASECMP],
[
AC_CACHE_CHECK([for strcasecmp() in string.h], ac_cv_string_strcasecmp, [
AC_LINK_IFELSE([AC_LANG_PROGRAM(
[[#include <string.h>]],
[[strcasecmp("foo", "bar");]])],
[ac_cv_string_strcasecmp=yes],
[ac_cv_string_strcasecmp=no])
])
if test x"$ac_cv_string_strcasecmp" = "xyes"
then
AC_DEFINE(HAVE_STRING_STRCASECMP, 1,
[ Define if your system has strcasecmp() in string.h ])
fi
]) dnl AX_STRING_STRCASECMP
41 changes: 41 additions & 0 deletions m4/ax_strings_strcasecmp.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_strings_strcasecmp.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_STRINGS_STRCASECMP
#
# DESCRIPTION
#
# This macro tries to find strcasecmp() in strings.h. See the
# AX_STRING_STRCASECMP macro's commentary for usage details.
#
# LICENSE
#
# Copyright (c) 2008 Warren Young <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 9

AU_ALIAS([ETR_STRINGS_STRCASECMP], [AX_STRINGS_STRCASECMP])
AC_DEFUN([AX_STRINGS_STRCASECMP],
[ AC_CACHE_CHECK([for strcasecmp() in strings.h], ac_cv_strings_strcasecmp, [
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <strings.h>]],
[[strcasecmp("foo", "bar");]])],
[ac_cv_strings_strcasecmp=yes],
[ac_cv_strings_strcasecmp=no])
])
if test x"$ac_cv_strings_strcasecmp" = "xyes"
then
AC_DEFINE(HAVE_STRINGS_STRCASECMP, 1,
[ Define if your system has strcasecmp() in strings.h ])
fi
]) dnl AX_STRINGS_STRCASECMP

0 comments on commit ce4b11f

Please sign in to comment.