[lttng-dev] [Babeltrace PATCH 06/23] Add MinGW implementation of strerror_r

Ikaheimonen, JP jp_ikaheimonen at mentor.com
Wed May 22 04:06:05 EDT 2013


Add MinGW implementation of strerror_r.
Visual C runtime libraries include a function strerror_s,
but unfortunately the current release of MinGW32 does not provide
it. We have our own non-secure implementation instead.
---
 include/babeltrace/compat/string.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/babeltrace/compat/string.h b/include/babeltrace/compat/string.h
index 62cf1bf..2584ecb 100644
--- a/include/babeltrace/compat/string.h
+++ b/include/babeltrace/compat/string.h
@@ -3,7 +3,20 @@
 
 #include <string.h>
 
-#if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
+#ifdef __MINGW32__
+
+static inline int compat_strerror_r(int errnum, char *buf, size_t buflen)
+{
+	/* non-recursive implementation of strerror_r */
+	/* Windows function strerror_s is not available in MinGW32 */
+	char * retbuf;
+
+	retbuf = strerror(errnum);
+	strncpy(buf, retbuf, buflen);
+	buf[buflen - 1] = '\0';
+	return 0;
+}
+#elif !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
 
 /* XSI-compliant strerror_r */
 static inline int compat_strerror_r(int errnum, char *buf, size_t buflen)
@@ -17,6 +30,7 @@ static inline int compat_strerror_r(int errnum, char *buf, size_t buflen)
 static inline int compat_strerror_r(int errnum, char *buf, size_t buflen)
 {
 	char * retbuf;
+
 	retbuf = strerror_r(errnum, buf, buflen);
 	if (retbuf != buf)
 		strcpy(buf, retbuf);
-- 
1.8.1.msysgit.1




More information about the lttng-dev mailing list