From: Matthew Fernandez Date: Sat, 19 Feb 2022 17:59:06 +0000 (-0800) Subject: cgraph: [nfc] guard 'strcasecmp' definition to avoid duplication X-Git-Tag: 3.0.0~16^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c64195e4293d205bd0349c1de78bcbae693e0b13;p=graphviz cgraph: [nfc] guard 'strcasecmp' definition to avoid duplication When compiling with Microsoft Visual Studio 2019, the compiler emits: …\lib\cgraph\strcasecmp.h(12,64): warning C4211: nonstandard extension used: redefined extern to static Investigation reveals libgd defines their own `strcasecmp` shim in gd.h: /* VS2012+ disable keyword macroizing unless _ALLOW_KEYWORD_MACROS is set We define inline, and strcasecmp if they're missing */ #ifdef _MSC_VER # define _ALLOW_KEYWORD_MACROS # ifndef inline # define inline __inline # endif # ifndef strcasecmp # define strcasecmp _stricmp # endif #endif To avoid this warning, guard Graphviz’ shim so it is only used when the libgd shim is not in use. Note that this also explains why MSVC is able to compile diffimg.c despite the Graphviz shim file not being included. --- diff --git a/lib/cgraph/strcasecmp.h b/lib/cgraph/strcasecmp.h index 78654feb7..f8e628385 100644 --- a/lib/cgraph/strcasecmp.h +++ b/lib/cgraph/strcasecmp.h @@ -9,9 +9,13 @@ #include + // some third-party libraries like libgd provide their own macro-based + // `strcasecmp` shim, so only define our own if their’s is not in scope +#ifndef strcasecmp static inline int strcasecmp(const char *s1, const char *s2) { return _stricmp(s1, s2); } +#endif static inline int strncasecmp(const char *s1, const char *s2, size_t n) { return _strnicmp(s1, s2, n);