Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Change-Id: If2969e131f0fae456d58b35d839d8abe191fcc59 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/454176 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Ian Lance Taylor <iant@google.com>
- Loading branch information
1 parent
5e658f4
commit fef6aa3
Showing
5 changed files
with
52 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ianlancetaylor
Author
Contributor
|
||
|
||
/* 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); | ||
} |
@ianlancetaylor I haven't tested this but I believe you also need the
#undef
/#define
dance on GNU Hurd since they also use glibc (Hurd also usederrstr_glibc.go
previously via//go:build
tags). Maybe#ifdef __GLIBC__
instead of#ifdef __linux__
is more appropriate here?Thanks for merging the patch!