From 38099fe3d9f1f3b4b9d907f3fd730b206b572fa7 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Wed, 3 Jul 2019 19:47:55 -0600
Subject: [PATCH] Fix definition of errno to match what is used by musl

---
 include/bits/errno.h    | 2 +-
 src/header/errno/mod.rs | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/bits/errno.h b/include/bits/errno.h
index c4f10c1d..5181e3a9 100644
--- a/include/bits/errno.h
+++ b/include/bits/errno.h
@@ -7,7 +7,7 @@ extern "C" {
 
 #define ENOTSUP EOPNOTSUPP
 
-extern __thread int errno;
+#define errno (*__errno_location())
 
 #ifdef __cplusplus
 } // extern "C"
diff --git a/src/header/errno/mod.rs b/src/header/errno/mod.rs
index e39fb205..a203373b 100644
--- a/src/header/errno/mod.rs
+++ b/src/header/errno/mod.rs
@@ -3,14 +3,15 @@
 use platform;
 use platform::types::*;
 
+//TODO: Consider removing, provided for compatibility with newlib
 #[no_mangle]
 pub unsafe extern "C" fn __errno() -> *mut c_int {
-    &mut platform::errno
+    __errno_location()
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn __errno_location() -> *mut c_int {
-    __errno()
+    &mut platform::errno
 }
 
 pub const EPERM: c_int = 1; /* Operation not permitted */
-- 
GitLab