diff --git a/SConstruct b/SConstruct index f8dde3d0f..959661c00 100644 --- a/SConstruct +++ b/SConstruct @@ -856,6 +856,12 @@ help:always wipe certain freed memory poison = True if poison: context.sconf.Define('DXX_HAVE_POISON') + @_custom_test + def check_strcasecmp_present(self,context): + main = ''' + return !strcasecmp(argv[0], argv[0] + 1) && !strncasecmp(argv[0] + 1, argv[0], 1); +''' + self.Compile(context, text='#include ', main=main, msg='for strcasecmp', successflags={'CPPDEFINES' : ['DXX_HAVE_STRCASECMP']}) class LazyObjectConstructor: def __get_lazy_object(self,srcname,transform_target): diff --git a/common/include/strutil.h b/common/include/strutil.h index 596b1f478..38afe6db7 100644 --- a/common/include/strutil.h +++ b/common/include/strutil.h @@ -15,10 +15,19 @@ #define snprintf macintosh_snprintf extern void snprintf(char *out_string, int size, const char * format, ... ); #endif + +#ifdef DXX_HAVE_STRCASECMP +#define d_stricmp strcasecmp +static inline int d_strnicmp(const char *s1, const char *s2, size_t n) +{ + return strncasecmp(s1, s2, n); +} +#else __attribute_nonnull() extern int d_stricmp( const char *s1, const char *s2 ); __attribute_nonnull() int d_strnicmp(const char *s1, const char *s2, uint_fast32_t n); +#endif extern void d_strlwr( char *s1 ); extern void d_strupr( char *s1 ); extern void d_strrev( char *s1 ); diff --git a/common/misc/strutil.cpp b/common/misc/strutil.cpp index 23937be03..85a9d0e96 100644 --- a/common/misc/strutil.cpp +++ b/common/misc/strutil.cpp @@ -56,6 +56,7 @@ void snprintf(char *out_string, int size, char * format, ... ) // string compare without regard to case +#ifndef DXX_HAVE_STRCASECMP int d_stricmp( const char *s1, const char *s2 ) { for (;; ++s1, ++s2) @@ -82,6 +83,7 @@ int d_strnicmp(const char *s1, const char *s2, uint_fast32_t n) } return 0; } +#endif void d_strlwr( char *s1 ) {