aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-11-29 15:31:39 -0800
committerIan Lance Taylor <iant@golang.org>2022-11-29 16:09:13 -0800
commitb6c6a3d64f2e4e9347733290aca3c75898c44b2e (patch)
treec3f37a1483d0e780eaf20715c4c565612b883ffb /libgo/runtime
parent3832c6f7e672e76bba74a508bf3a49740ea38046 (diff)
downloadgcc-b6c6a3d64f2e4e9347733290aca3c75898c44b2e.zip
gcc-b6c6a3d64f2e4e9347733290aca3c75898c44b2e.tar.gz
gcc-b6c6a3d64f2e4e9347733290aca3c75898c44b2e.tar.bz2
syscall, runtime: always call XSI strerror_r
This does the right thing for either glibc or musl on GNU/Linux. Based on patch by Sören Tempel. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176
Diffstat (limited to 'libgo/runtime')
-rw-r--r--libgo/runtime/go-strerror.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/libgo/runtime/go-strerror.c b/libgo/runtime/go-strerror.c
new file mode 100644
index 0000000..13d1d91
--- /dev/null
+++ b/libgo/runtime/go-strerror.c
@@ -0,0 +1,37 @@
+/* go-strerror.c -- wrapper around XSI-compliant strerror_r.
+
+ Copyright 2022 The Go Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style
+ license that can be found in the LICENSE file. */
+
+/* There are two version of strerror_r on GNU/Linux: a GNU-specific
+ and an XSI-compliant version. The former version is only available
+ on glibc. Since glibc 2.13, the XSI-compliant version is also
+ provided by glibc if _GNU_SOURCE is not defined. Since the
+ entirety of gofrontend is compiled with _GNU_SOURCE, this file
+ exists to selectively undefine it and provides an alias to the
+ XSI-compliant version of strerror_r(3). */
+
+#ifdef __linux__
+
+/* Force selection of XSI-compliant strerror_r by glibc. */
+#undef XOPEN_SOURCE
+#define XOPEN_SOURCE 600
+#undef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200112L
+#undef _GNU_SOURCE
+
+#endif /* __linux__ */
+
+#include <string.h>
+
+#ifndef HAVE_STRERROR_R
+// Provided by go-nosys.c if not provided by libc itself.
+extern int strerror_r (int, char *, size_t);
+#endif
+
+int
+go_strerror (int errnum, char *buf, size_t buflen)
+{
+ return strerror_r (errnum, buf, buflen);
+}