Define _DEFAULT_SOURCE for getentropy in musl
glibc and musl do not make getentropy available from <unistd.h> unless
_BSD_SOURCE (or _GNU_SOURCE) is defined. _BSD_SOURCE, in glibc, triggers
a deprecation warning to use _DEFAULT_SOURCE instead.
It seems _DEFAULT_SOURCE might be fairly broadly defined, but some
Emscripten-based toolchain (which uses musl) didn't end up defining
it for some reason. Just do it explicitly in the source file so it
always works.
Change-Id: I4532d4adb9f8ed55c43763ca2dd426b5fa1b4f5c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/61625
Reviewed-by: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
diff --git a/crypto/rand_extra/getentropy.c b/crypto/rand_extra/getentropy.c
index d4b5e68..234b9b6 100644
--- a/crypto/rand_extra/getentropy.c
+++ b/crypto/rand_extra/getentropy.c
@@ -12,6 +12,10 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+#if !defined(_DEFAULT_SOURCE)
+#define _DEFAULT_SOURCE // Needed for getentropy on musl and glibc
+#endif
+
#include <openssl/rand.h>
#include "../fipsmodule/rand/internal.h"