OSDN Git Service

Emulate glibc <string.h> POSIX.1 non-compliance.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 13 Oct 2016 21:03:26 +0000 (22:03 +0100)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 13 Oct 2016 21:03:26 +0000 (22:03 +0100)
mingwrt/ChangeLog
mingwrt/include/_mingw.h.in
mingwrt/include/string.h

index 5739a02..e8102c0 100644 (file)
@@ -1,5 +1,20 @@
 2016-10-13  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
+       Emulate glibc <string.h> POSIX.1 non-compliance.
+
+       * include/_mingw.h.in (_EMULATE_GLIBC): New feature test macro.
+       [_GNU_SOURCE || _BSD_SOURCE || !__STRICT_ANSI__]: Enable it when...
+       [_XOPEN_SOURCE || _POSIX_C_SOURCE || _POSIX_SOURCE]: ...none of
+       these have been pre-defined by the user.
+
+       * include/string.h [_EMULATE_GLIBC]: Include <strings.h> in full...
+       (strcasecmp, strncasecmp): ...so prototypes for these are declared.
+       [!_EMULATE_GLIBC]: Preserve partial <strings.h> include, guarded by...
+       [__STRING_H_SOURCED__]: ...this context selector, so suppressing the
+       declarations of those function prototypes.
+
+2016-10-13  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
        Resolve some non-ANSI typedef omissions.
 
        * include/sys/types.h (off_t, ssize_t): Always typedef them when...
index 8328298..57fc0cc 100644 (file)
@@ -430,6 +430,14 @@ allow GCC to optimize away some EH unwind code, at least in DW2 case.  */
    */
 #  define _POSIX_C_SOURCE  200809L
 
+#  if ! defined _EMULATE_GLIBC && ! defined _POSIX_SOURCE
+   /* For this default case, unless it has already been specified
+    * otherwise, we enable some GNU glibc extensions, which may be
+    * considered as violations of strict POSIX.1 conformance.
+    */
+#   define _EMULATE_GLIBC  1
+#  endif
+
 # elif defined _POSIX_SOURCE
   /* Now formally deprecated by POSIX, some old code may specify this;
    * it will enable a minimal level of POSIX support, in addition to the
index 2e5940b..720c85a 100644 (file)
 #endif
 #include <stddef.h>
 
+#if _EMULATE_GLIBC
+/* GNU's glibc declares strcasecmp() and strncasecmp() in <string.h>,
+ * contravening POSIX.1-2008 which requires them to be declared only in
+ * <strings.h>; we may emulate this anomalous glibc behaviour, which is
+ * ostensibly to support BSD usage, (in spite of such usage now being
+ * obsolete in BSD), by simply including our <strings.h> here.
+ */
+#include <strings.h>
+#endif
+
 _BEGIN_C_DECLS
 
 #define __STRING_H_SOURCED__
@@ -101,9 +111,12 @@ _CRTIMP __cdecl __MINGW_NOTHROW  void _swab (const char *, char *, size_t);
 /* MSVC's non-ANSI _stricmp() and _strnicmp() functions must also be
  * prototyped here, but we need to share them with <strings.h>, where
  * we declare their POSIX strcasecmp() and strncasecmp() equivalents;
- * get the requisite prototypes by selective <strings.h> inclusion.
+ * get the requisite prototypes by selective <strings.h> inclusion,
+ * (noting that we've already done so, if emulating glibc).
  */
+#if !_EMULATE_GLIBC
 #include <strings.h>
+#endif
 
 # ifdef __MSVCRT__
  /* These were not present in the CRTDLL prior to the first release of