Web lists-archives.com

Re: [Mingw-users] MinGW GCC 5.3.0 doesn't work on Windows XP




-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 18/04/16 15:10, Earnie wrote:
> We need to create our own version of strnlen for libmingw32.a ...

Any particular reason for libmingw32.a, rather than libmingwex.a?  The
latter is where we normally provide our own implementations, to extend
the scope of basic MSVCRT.DLL content.

I have a (trivial) implementation, as __mingw_strnlen() in <string.h>,
and with external __LIBIMPL__ representation, ready to go, (see patch
as attached).  Note that the current __LIBIMPL__ implementation will
go, by default, in libmingwex.a, but I can easily extend it to allow
placement in any alternative library, if that is required.

- -- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)

iQIcBAEBAgAGBQJXINtfAAoJEMCtNsY0flo/uNwP/10seYSPbpjh7F0gtcZkuO+j
UtFXU5hipV/cC0c773D2fIXGgAAhS6/mUG0Bne/bOI+f3nBzLwyWSTIerjDsdjBD
rf9ahgi3oHNGY7ZIM1WE2VpizzZgIvVOTu+CumSsxQzOdgaK6pOkhZVVXxA8ZzTv
5Nhl4UGwHr5vQfEm+fF4XR0eR32gFhHWQQYdEemfyxM50PsHPJzeM/gcy9DMcnmR
Swjks4AS9MogW36FXWJbpc6ynpdT8kE3gxHYRn+rkERBvsq7GjP7momJrrY3sI8A
w9Zyw6aP5z9q6f2sDaiDWDot7JQiIZkiF8xPpFpYqjlM0b16kdfjyRSkUsfqjNdQ
TxjQnwI2RsdW+g9MvI0Ch9R90iC4EtBSfu5tp8BTTCWL5JwDBLGjeBz/QEDoeQN9
KQU7NJm1viLgvcYYU4OKkS2Dx2FAE5C9aDkJpIM2lNzMGu5mr2fHgf0WFIirL9JB
g/FzxRFwHEkRRI4BGRRi0uhzYxTSkm4MYazT2xHBSf4LyOsS9xVXzXlx8lwZgpda
ouVvQGToaJ4Vokn8qTAaJoLJxo7ZKh6VDIDb6LzaW9UX/E+CkcU8ePtRss10C/Z4
WGTTd/hjwMhnR61sWV81SYYm+er6jQ/CGaEbcgmZtBNIuT5pSXV5Fp3CJQ1UVCj/
kti+JIzF4njo3zKFhUdl
=CsF3
-----END PGP SIGNATURE-----
diff --git a/mingwrt/include/string.h b/mingwrt/include/string.h
--- a/mingwrt/include/string.h
+++ b/mingwrt/include/string.h
@@ -150,10 +150,48 @@
  * anomalous behaviour.
  */
 #include <wchar.h>
 
 #endif /* ! __STRICT_ANSI__ */
+
+#if __MSVCRT_VERSION__ >= __MSVCR80_DLL
+/* MSVCR80.DLL adds a (mostly) POSIX.1-2008 conforming strnlen(); (it's
+ * also available in MSVCRT.DLL from _WIN32_WINNT_VISTA onwards, but we
+ * pretend otherwise, since recent GCC will try to use the function when
+ * it can be found in libmsvcrt.a, so breaking it for use on WinXP and
+ * earlier).
+ */
+_CRTIMP __cdecl __MINGW_NOTHROW  char *strnlen (const char *, size_t);
+
+#elif _POSIX_C_SOURCE >= 200809L
+/* Emulation, to support recent POSIX.1; we prefer this for ALL versions
+ * of MSVCRT.DLL, (even those which already provide strnlen()); to avoid
+ * the GCC breakage noted above.  (Note that we implement strnlen() with
+ * the alternative external name, __mingw_strnlen() in libmingwex.a, to
+ * avoid possible link time collision with MSVCR80.DLL's implementation,
+ * then map this to strnlen() via a preprocessor define, so that users
+ * may use it conventionally, (including taking its address); this may
+ * interfere with C++ namespace qualification, but since strnlen() is
+ * not a standard C++ function, we do not anticipate any consequent
+ * usage issues).
+ */
+#define strnlen  __mingw_strnlen
+__CRT_ALIAS __LIBIMPL__(( FUNCTION = strnlen ))
+size_t __mingw_strnlen (const char *__string, size_t __maxlen)
+{
+  size_t __retval = 0;
+  /* POSIX.1 defines no error return conditions here; in particular,
+   * there is no prescribed handling if __string is passed as a NULL
+   * pointer; unlike C11's similar strnlen_s() function, this will
+   * simply induce a segmentation fault, (as does the corresponding
+   * MSVCR80.DLL implementation).
+   */
+  while ((__retval < __maxlen) && (*__string++ != '\0'))
+    ++__retval;
+  return __retval;
+}
+#endif
 #undef __STRING_H_SOURCED__
 
 _END_C_DECLS
 
 #endif	/* ! RC_INVOKED */
diff --git a/mingwrt/msvcrt-xref/msvcrt.def.in b/mingwrt/msvcrt-xref/msvcrt.def.in
--- a/mingwrt/msvcrt-xref/msvcrt.def.in
+++ b/mingwrt/msvcrt-xref/msvcrt.def.in
@@ -3415,11 +3415,11 @@ strncat_s
 strncmp
 strncpy
 #if __MSVCRT_VERSION__ >= 0x0600UL
 # if __MSVCRT_VERSION__ < 0x07000000UL || __MSVCRT_VERSION__ >= 0x08000000UL
 strncpy_s
-strnlen
+__MINGW_DLSYM(strnlen); exposure in libmsvcrt.a may break GCC builds.
 # endif
 #endif
 strpbrk
 strrchr
 strspn
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe