]> granicus.if.org Git - graphviz/commitdiff
add an abstraction for strcasecmp
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 2 Aug 2020 01:13:13 +0000 (18:13 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 7 Aug 2020 14:00:28 +0000 (07:00 -0700)
Related to #1775.

lib/cgraph/CMakeLists.txt
lib/cgraph/Makefile.am
lib/cgraph/cgraph.vcxproj
lib/cgraph/cgraph.vcxproj.filters
lib/cgraph/strcasecmp.h [new file with mode: 0644]

index 651a61c1e6715a0cf12bc36c539fdc1fae10fd9f..6182bf37a05fa5d43aee4c23d5b48e5161cbf1db 100644 (file)
@@ -42,6 +42,7 @@ add_library(cgraph SHARED
     agxbuf.h
     cghdr.h
     cgraph.h
+    strcasecmp.h
 
     # Source files
     agerror.c
@@ -81,7 +82,7 @@ install(
 
 # Specify headers to be installed
 install(
-    FILES cgraph.h
+    FILES cgraph.h strcasecmp.h
     DESTINATION ${HEADER_INSTALL_DIR}
 )
 
index be611dbe368832f01fe7f66422d7c074d5b714e2..ea36126e880d0195bc24ecc43d59dc1a56055e47 100644 (file)
@@ -10,7 +10,7 @@ AM_CPPFLAGS = \
        -I$(top_srcdir) \
        -I$(top_srcdir)/lib/cdt
 
-pkginclude_HEADERS = cgraph.h
+pkginclude_HEADERS = cgraph.h strcasecmp.h
 noinst_HEADERS = agxbuf.h cghdr.h
 noinst_LTLIBRARIES = libcgraph_C.la
 lib_LTLIBRARIES = libcgraph.la
index 23f18e346019e8c3c2ba663ed4bb953b7b4cd563..b8f1d587169e71ab5fc6b9cfcd240076cf9058d0 100644 (file)
@@ -101,6 +101,7 @@ flex -oscan.c scan.l</Command>
     <ClInclude Include="agxbuf.h" />
     <ClInclude Include="cghdr.h" />
     <ClInclude Include="cgraph.h" />
+    <ClInclude Include="strcasecmp.h" />
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="agerror.c" />
index 481de2ff0fcc82ec64a0d480493b7de7f262725d..ae190d3792ce00e6a4ffb0c90cfaff5ef90c2b53 100644 (file)
@@ -24,6 +24,9 @@
     <ClInclude Include="cgraph.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="strcasecmp.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="agerror.c">
diff --git a/lib/cgraph/strcasecmp.h b/lib/cgraph/strcasecmp.h
new file mode 100644 (file)
index 0000000..e2ec198
--- /dev/null
@@ -0,0 +1,35 @@
+/* platform abstraction for case-insensitive string functions */
+
+#pragma once
+
+#include <stddef.h>
+
+/* Re-prototype the functions we are abstracting. The purpose of this is to
+ * cause a compiler warning if our implementations diverge. Windows compilation
+ * will see these and the inline functions below, and warn if they do not match.
+ * Compilation on other platforms will see these and the strings.h prototypes,
+ * and warn if they do not match. This way we have a safeguard that the
+ * alternatives provided for Windows match the libc functions on other
+ * platforms.
+ */
+int strcasecmp(const char *s1, const char *s2);
+int strncasecmp(const char *s1, const char *s2, size_t n);
+
+#ifdef _MSC_VER
+  /* redirect these to the Windows alternatives */
+
+  #include <string.h>
+
+  static inline int strcasecmp(const char *s1, const char *s2) {
+    return _stricmp(s1, s2);
+  }
+
+  static inline int strncasecmp(const char *s1, const char *s2, size_t n) {
+    return _strnicmp(s1, s2, n);
+  }
+
+#else
+  /* other platforms define these in strings.h */
+  #include <strings.h>
+
+#endif