From f46c983df58a41ec8f994f30f57154bd78392de8 Mon Sep 17 00:00:00 2001 From: Brice Goglin Date: Sat, 12 Jul 2014 10:01:18 +0200 Subject: [PATCH] hwloc_strncasecmp: don't fallback to strncmp when strncasecmp is missing This fallback breaks some internals where we assume that hwloc_strncasecmp is really case-insensitive. Reimplement a basic strncasecmp instead. This is used on HP-UX, and with icc when it fails to properly check whether strcasecmp is available. Thanks to Nick Papior Andersen for reporting the problem. (cherry picked from commit c9dcf65977cb170b802199403e8068b8122ab151) --- NEWS | 2 ++ config/hwloc.m4 | 4 +--- include/hwloc/rename.h | 1 + include/private/misc.h | 17 ++++++++++++++++- utils/misc.h | 1 + 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index b0f011716e..6b2bf1679d 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ Version 1.9.1 * Fix a crash when the PCI locality is invalid. Attach to the root object instead. Thanks to Nicolas Denoyelle for reporting the issue. * Fix -f in lstopo manpage. Thanks to Jirka Hladky for reporting the issue. +* Fix hwloc_obj_type_sscanf() and others when strncasecmp() is not properly + available. Thanks to Nick Papior Andersen for reporting the problem. Version 1.9.0 diff --git a/config/hwloc.m4 b/config/hwloc.m4 index ef3c53edda..470ad58386 100644 --- a/config/hwloc.m4 +++ b/config/hwloc.m4 @@ -354,13 +354,11 @@ EOF]) AC_CHECK_HEADERS([dirent.h]) AC_CHECK_HEADERS([strings.h]) - hwloc_strncasecmp=strncmp AC_CHECK_FUNCS([strncasecmp], [ _HWLOC_CHECK_DECL([strncasecmp], [ - hwloc_strncasecmp=strncasecmp + AC_DEFINE([HWLOC_HAVE_DECL_STRNCASECMP], [1], [Define to 1 if function `strncasecmp' is declared by system headers]) ]) ]) - AC_DEFINE_UNQUOTED(hwloc_strncasecmp, $hwloc_strncasecmp, [Define this to either strncasecmp or strncmp]) AC_CHECK_FUNCS([strftime]) AC_CHECK_FUNCS([setlocale]) diff --git a/include/hwloc/rename.h b/include/hwloc/rename.h index 56d4aa5de1..999fd6e658 100644 --- a/include/hwloc/rename.h +++ b/include/hwloc/rename.h @@ -514,6 +514,7 @@ extern "C" { #define hwloc_fls32 HWLOC_NAME(fls32) #define hwloc_flsl_from_fls32 HWLOC_NAME(flsl_from_fls32) #define hwloc_weight_long HWLOC_NAME(weight_long) +#define hwloc_strncasecmp HWLOC_NAME(strncasecmp) /* private/cpuid-x86.h */ diff --git a/include/private/misc.h b/include/private/misc.h index 3f4c95c330..df99171a30 100644 --- a/include/private/misc.h +++ b/include/private/misc.h @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2010 inria. All rights reserved. + * Copyright © 2009-2014 Inria. All rights reserved. * Copyright © 2009-2012 Université Bordeaux 1 * Copyright © 2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -354,4 +354,19 @@ hwloc_weight_long(unsigned long w) unsigned long long int strtoull(const char *nptr, char **endptr, int base); #endif +static __hwloc_inline int hwloc_strncasecmp(const char *s1, const char *s2, size_t n) +{ +#ifdef HWLOC_HAVE_DECL_STRNCASECMP + return strncasecmp(s1, s2, n); +#else + while (n) { + char c1 = tolower(*s1), c2 = tolower(*s2); + if (!c1 || !c2 || c1 != c2) + return c1-c2; + n--; s1++; s2++; + } + return 0; +#endif +} + #endif /* HWLOC_PRIVATE_MISC_H */ diff --git a/utils/misc.h b/utils/misc.h index d5db53b26e..9958c34f23 100644 --- a/utils/misc.h +++ b/utils/misc.h @@ -8,6 +8,7 @@ #include #include +#include #include #include