From a7137512fa07b439f171d32b98dded24b07ead41 Mon Sep 17 00:00:00 2001
From: Peter Limkilde Svendsen <peter.limkilde@gmail.com>
Date: Fri, 1 Mar 2024 00:25:42 +0000
Subject: [PATCH] Use standard casing and mangling for internal errno

---
 src/header/arpa_inet/mod.rs   |  6 ++---
 src/header/dirent/mod.rs      | 10 ++++----
 src/header/errno/mod.rs       |  2 +-
 src/header/grp/mod.rs         |  2 +-
 src/header/netdb/mod.rs       | 20 ++++++++--------
 src/header/pty/mod.rs         |  6 ++---
 src/header/pwd/mod.rs         |  2 +-
 src/header/signal/mod.rs      |  8 +++----
 src/header/stdio/getdelim.rs  | 10 ++++----
 src/header/stdio/helpers.rs   |  2 +-
 src/header/stdio/mod.rs       | 16 ++++++-------
 src/header/stdio/printf.rs    |  4 ++--
 src/header/stdlib/mod.rs      | 44 +++++++++++++++++------------------
 src/header/string/mod.rs      |  2 +-
 src/header/sys_ioctl/redox.rs |  2 +-
 src/header/sys_select/mod.rs  |  4 ++--
 src/header/sys_uio/mod.rs     |  4 ++--
 src/header/termios/mod.rs     | 10 ++++----
 src/header/time/mod.rs        |  2 +-
 src/header/unistd/brk.rs      |  4 ++--
 src/header/unistd/mod.rs      | 26 ++++++++++-----------
 src/header/unistd/pathconf.rs |  2 +-
 src/header/unistd/sysconf.rs  |  2 +-
 src/header/wchar/mod.rs       | 16 ++++++-------
 src/header/wchar/utf8.rs      |  8 +++----
 src/header/wchar/wprintf.rs   |  4 ++--
 src/io/error.rs               |  2 +-
 src/ld_so/dso.rs              |  4 ++--
 src/macros.rs                 |  4 ++--
 src/platform/linux/mod.rs     |  4 ++--
 src/platform/mod.rs           |  4 +---
 src/platform/redox/epoll.rs   |  4 ++--
 src/platform/redox/mod.rs     | 36 ++++++++++++++--------------
 src/platform/redox/ptrace.rs  |  4 ++--
 src/platform/redox/signal.rs  | 12 +++++-----
 src/platform/redox/socket.rs  | 24 +++++++++----------
 36 files changed, 157 insertions(+), 159 deletions(-)

diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs
index b439d7e8..c20443aa 100644
--- a/src/header/arpa_inet/mod.rs
+++ b/src/header/arpa_inet/mod.rs
@@ -56,7 +56,7 @@ pub unsafe extern "C" fn inet_ntoa(addr: in_addr) -> *const c_char {
 #[no_mangle]
 pub unsafe extern "C" fn inet_pton(domain: c_int, src: *const c_char, dest: *mut c_void) -> c_int {
     if domain != AF_INET {
-        platform::errno.set(EAFNOSUPPORT);
+        platform::ERRNO.set(EAFNOSUPPORT);
         -1
     } else {
         let s_addr = slice::from_raw_parts_mut(
@@ -88,10 +88,10 @@ pub unsafe extern "C" fn inet_ntop(
     size: socklen_t,
 ) -> *const c_char {
     if domain != AF_INET {
-        platform::errno.set(EAFNOSUPPORT);
+        platform::ERRNO.set(EAFNOSUPPORT);
         ptr::null()
     } else if size < 16 {
-        platform::errno.set(ENOSPC);
+        platform::ERRNO.set(ENOSPC);
         ptr::null()
     } else {
         let s_addr = slice::from_raw_parts(
diff --git a/src/header/dirent/mod.rs b/src/header/dirent/mod.rs
index ee6d6593..8f922092 100644
--- a/src/header/dirent/mod.rs
+++ b/src/header/dirent/mod.rs
@@ -83,7 +83,7 @@ pub unsafe extern "C" fn readdir(dir: *mut DIR) -> *mut dirent {
         );
         if read <= 0 {
             if read != 0 && read != -errno::ENOENT {
-                platform::errno.set(-read);
+                platform::ERRNO.set(-read);
             }
             return ptr::null_mut();
         }
@@ -145,8 +145,8 @@ pub unsafe extern "C" fn scandir(
         Err(err) => return -1,
     };
 
-    let old_errno = platform::errno.get();
-    platform::errno.set(0);
+    let old_errno = platform::ERRNO.get();
+    platform::ERRNO.set(0);
 
     loop {
         let entry: *mut dirent = readdir(dir);
@@ -177,7 +177,7 @@ pub unsafe extern "C" fn scandir(
         return -1;
     }
 
-    if platform::errno.get() != 0 {
+    if platform::ERRNO.get() != 0 {
         for ptr in &mut vec {
             platform::free(*ptr as *mut c_void);
         }
@@ -185,7 +185,7 @@ pub unsafe extern "C" fn scandir(
     } else {
         *namelist = vec.leak();
 
-        platform::errno.set(old_errno);
+        platform::ERRNO.set(old_errno);
         stdlib::qsort(
             *namelist as *mut c_void,
             len as size_t,
diff --git a/src/header/errno/mod.rs b/src/header/errno/mod.rs
index b1748c6a..df5c0d39 100644
--- a/src/header/errno/mod.rs
+++ b/src/header/errno/mod.rs
@@ -10,7 +10,7 @@ pub extern "C" fn __errno() -> *mut c_int {
 
 #[no_mangle]
 pub extern "C" fn __errno_location() -> *mut c_int {
-    platform::errno.as_ptr()
+    platform::ERRNO.as_ptr()
 }
 
 #[no_mangle]
diff --git a/src/header/grp/mod.rs b/src/header/grp/mod.rs
index 55734757..4958791c 100644
--- a/src/header/grp/mod.rs
+++ b/src/header/grp/mod.rs
@@ -224,7 +224,7 @@ fn parse_grp(line: String, destbuf: Option<DestBuffer>) -> Result<OwnedGrp, Erro
             let mut buf = MaybeAllocated::Borrowed(buf);
 
             if buf.len() < buf.len() {
-                platform::errno.set(errno::ERANGE);
+                platform::ERRNO.set(errno::ERANGE);
                 return Err(Error::BufTooSmall);
             }
 
diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs
index fa48942b..9736a3d2 100644
--- a/src/header/netdb/mod.rs
+++ b/src/header/netdb/mod.rs
@@ -244,7 +244,7 @@ pub unsafe extern "C" fn gethostbyaddr(
             &mut HOST_ENTRY
         }
         Err(e) => {
-            platform::errno.set(e);
+            platform::ERRNO.set(e);
             ptr::null_mut()
         }
     }
@@ -307,14 +307,14 @@ pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
     let mut host = match lookup_host(str::from_utf8_unchecked(name_cstr.to_bytes())) {
         Ok(lookuphost) => lookuphost,
         Err(e) => {
-            platform::errno.set(e);
+            platform::ERRNO.set(e);
             return ptr::null_mut();
         }
     };
     let host_addr = match host.next() {
         Some(result) => result,
         None => {
-            platform::errno.set(ENOENT);
+            platform::ERRNO.set(ENOENT);
             return ptr::null_mut();
         }
     };
@@ -363,7 +363,7 @@ pub unsafe extern "C" fn getnetbyname(name: *const c_char) -> *mut netent {
     }
     setnetent(NET_STAYOPEN);
 
-    platform::errno.set(ENOENT);
+    platform::ERRNO.set(ENOENT);
     ptr::null_mut() as *mut netent
 }
 
@@ -459,7 +459,7 @@ pub unsafe extern "C" fn getprotobyname(name: *const c_char) -> *mut protoent {
     }
     setprotoent(PROTO_STAYOPEN);
 
-    platform::errno.set(ENOENT);
+    platform::ERRNO.set(ENOENT);
     ptr::null_mut() as *mut protoent
 }
 
@@ -477,7 +477,7 @@ pub unsafe extern "C" fn getprotobynumber(number: c_int) -> *mut protoent {
         }
     }
     setprotoent(PROTO_STAYOPEN);
-    platform::errno.set(ENOENT);
+    platform::ERRNO.set(ENOENT);
     ptr::null_mut() as *mut protoent
 }
 
@@ -566,7 +566,7 @@ pub unsafe extern "C" fn getservbyname(name: *const c_char, proto: *const c_char
         }
     }
     setservent(SERV_STAYOPEN);
-    platform::errno.set(ENOENT);
+    platform::ERRNO.set(ENOENT);
     ptr::null_mut() as *mut servent
 }
 
@@ -596,7 +596,7 @@ pub unsafe extern "C" fn getservbyport(port: c_int, proto: *const c_char) -> *mu
         }
     }
     setservent(SERV_STAYOPEN);
-    platform::errno.set(ENOENT);
+    platform::ERRNO.set(ENOENT);
     ptr::null_mut()
 }
 
@@ -762,7 +762,7 @@ pub unsafe extern "C" fn getaddrinfo(
         let lookuphost = match lookup_host(str::from_utf8_unchecked(node.to_bytes())) {
             Ok(lookuphost) => lookuphost,
             Err(e) => {
-                platform::errno.set(e);
+                platform::ERRNO.set(e);
                 return EAI_SYSTEM;
             }
         };
@@ -840,7 +840,7 @@ pub unsafe extern "C" fn getnameinfo(
 
     eprintln!("getnameinfo({:p}, {}, {:#x})", addr, addrlen, flags);
 
-    platform::errno.set(ENOSYS);
+    platform::ERRNO.set(ENOSYS);
     EAI_SYSTEM
 }
 
diff --git a/src/header/pty/mod.rs b/src/header/pty/mod.rs
index fd0cf44e..e356a531 100644
--- a/src/header/pty/mod.rs
+++ b/src/header/pty/mod.rs
@@ -83,8 +83,8 @@ pub unsafe extern "C" fn forkpty(
             if utmp::login_tty(s) != 0 {
                 unistd::write(
                     p[1],
-                    &platform::errno as *const _ as *const c_void,
-                    mem::size_of::<c_int>(),
+                    platform::ERRNO.as_ptr().cast(),
+                    mem::size_of_val(&platform::ERRNO),
                 );
                 unistd::_exit(127);
             }
@@ -106,7 +106,7 @@ pub unsafe extern "C" fn forkpty(
             let mut status = 0;
             sys_wait::waitpid(pid, &mut status, 0);
             pid = -1;
-            platform::errno.set(ec);
+            platform::ERRNO.set(ec);
         }
         unistd::close(p[0]);
     }
diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs
index e8da45f2..5a238a0a 100644
--- a/src/header/pwd/mod.rs
+++ b/src/header/pwd/mod.rs
@@ -154,7 +154,7 @@ fn getpwent_r(
         Some(dst) => {
             let mut new = MaybeAllocated::Borrowed(dst);
             if new.len() < buf.len() {
-                platform::errno.set(errno::ERANGE);
+                platform::ERRNO.set(errno::ERANGE);
                 return Err(Cause::Other);
             }
             new[..buf.len()].copy_from_slice(&buf);
diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs
index 7ed401b4..b0685932 100644
--- a/src/header/signal/mod.rs
+++ b/src/header/signal/mod.rs
@@ -92,7 +92,7 @@ pub unsafe extern "C" fn pthread_sigmask(
         0
     } else {
         //TODO: Fix race
-        platform::errno.get()
+        platform::ERRNO.get()
     }
 }
 
@@ -119,7 +119,7 @@ pub unsafe extern "C" fn sigaction(
 #[no_mangle]
 pub extern "C" fn sigaddset(set: *mut sigset_t, signo: c_int) -> c_int {
     if signo <= 0 || signo as usize > NSIG {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return -1;
     }
 
@@ -146,7 +146,7 @@ pub unsafe extern "C" fn sigaltstack(ss: *const stack_t, old_ss: *mut stack_t) -
 #[no_mangle]
 pub extern "C" fn sigdelset(set: *mut sigset_t, signo: c_int) -> c_int {
     if signo <= 0 || signo as usize > NSIG {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return -1;
     }
 
@@ -210,7 +210,7 @@ pub extern "C" fn siginterrupt(sig: c_int, flag: c_int) -> c_int {
 #[no_mangle]
 pub extern "C" fn sigismember(set: *const sigset_t, signo: c_int) -> c_int {
     if signo <= 0 || signo as usize > NSIG {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return -1;
     }
 
diff --git a/src/header/stdio/getdelim.rs b/src/header/stdio/getdelim.rs
index f621c7ee..195bfe28 100644
--- a/src/header/stdio/getdelim.rs
+++ b/src/header/stdio/getdelim.rs
@@ -17,7 +17,7 @@ use crate::{
 
 use crate::{
     header::stdio::{default_stdout, feof, ferror, F_EOF, F_ERR},
-    platform::errno,
+    platform::ERRNO,
 };
 
 /// see getdelim (getline is a special case of getdelim with delim == '\n')
@@ -59,7 +59,7 @@ pub unsafe extern "C" fn getdelim(
         if let (Some(ptr), Some(n), Some(file)) = (lineptr.as_mut(), n.as_mut(), stream.as_mut()) {
             (ptr, n, file)
         } else {
-            errno.set(EINVAL);
+            ERRNO.set(EINVAL);
             return -1 as ssize_t;
         };
 
@@ -72,7 +72,7 @@ pub unsafe extern "C" fn getdelim(
     let delim: u8 = if let Ok(delim) = delim.try_into() {
         delim
     } else {
-        errno.set(EINVAL);
+        ERRNO.set(EINVAL);
         return -1;
     };
 
@@ -92,7 +92,7 @@ pub unsafe extern "C" fn getdelim(
     // "[EOVERFLOW]
     // The number of bytes to be written into the buffer, including the delimiter character (if encountered), would exceed {SSIZE_MAX}."
     if unlikely(count > ssize_t::MAX as usize) {
-        errno.set(EOVERFLOW);
+        ERRNO.set(EOVERFLOW);
         return -1;
     }
 
@@ -124,7 +124,7 @@ pub unsafe extern "C" fn getdelim(
         *lineptr = stdlib::realloc(*lineptr as *mut c_void, *n) as *mut c_char;
         if unlikely(lineptr.is_null() && *n != 0usize) {
             // memory error; realloc returns NULL on alloc'ing 0 bytes
-            errno.set(ENOMEM);
+            ERRNO.set(ENOMEM);
             return -1;
         }
 
diff --git a/src/header/stdio/helpers.rs b/src/header/stdio/helpers.rs
index 7fcfcc8c..8fc4aa3f 100644
--- a/src/header/stdio/helpers.rs
+++ b/src/header/stdio/helpers.rs
@@ -40,7 +40,7 @@ pub unsafe fn parse_mode_flags(mode_str: *const c_char) -> i32 {
 /// Open a file with the file descriptor `fd` in the mode `mode`
 pub unsafe fn _fdopen(fd: c_int, mode: *const c_char) -> Option<*mut FILE> {
     if *mode != b'r' as i8 && *mode != b'w' as i8 && *mode != b'a' as i8 {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return None;
     }
 
diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs
index 23f659d2..a79f19a2 100644
--- a/src/header/stdio/mod.rs
+++ b/src/header/stdio/mod.rs
@@ -25,7 +25,7 @@ use crate::{
         unistd,
     },
     io::{self, BufRead, BufWriter, LineWriter, Read, Write},
-    platform::{self, errno, types::*, Pal, Sys, WriteByte},
+    platform::{self, types::*, Pal, Sys, WriteByte, ERRNO},
     sync::Mutex,
 };
 
@@ -498,7 +498,7 @@ pub unsafe extern "C" fn flockfile(file: *mut FILE) {
 pub unsafe extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE {
     let initial_mode = *mode;
     if initial_mode != b'r' as i8 && initial_mode != b'w' as i8 && initial_mode != b'a' as i8 {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return ptr::null_mut();
     }
 
@@ -821,7 +821,7 @@ pub unsafe extern "C" fn pclose(stream: *mut FILE) -> c_int {
         if let Some(pid) = stream.pid.take() {
             pid
         } else {
-            errno.set(errno::ECHILD);
+            ERRNO.set(errno::ECHILD);
             return -1;
         }
     };
@@ -842,7 +842,7 @@ pub unsafe extern "C" fn perror(s: *const c_char) {
     let s_str = str::from_utf8_unchecked(s_cstr.to_bytes());
 
     let mut w = platform::FileWriter(2);
-    let err = errno.get();
+    let err = ERRNO.get();
     if err >= 0 && err < STR_ERROR.len() as c_int {
         w.write_fmt(format_args!("{}: {}\n", s_str, STR_ERROR[err as usize]))
             .unwrap();
@@ -866,7 +866,7 @@ pub unsafe extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *
             b'r' if write_opt.is_none() => write_opt = Some(false),
             b'w' if write_opt.is_none() => write_opt = Some(true),
             _ => {
-                errno.set(errno::EINVAL);
+                ERRNO.set(errno::EINVAL);
                 return ptr::null_mut();
             }
         }
@@ -875,7 +875,7 @@ pub unsafe extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *
     let write = match write_opt {
         Some(some) => some,
         None => {
-            errno.set(errno::EINVAL);
+            ERRNO.set(errno::EINVAL);
             return ptr::null_mut();
         }
     };
@@ -1144,9 +1144,9 @@ unsafe extern "C" fn tmpnam_inner(buf: *mut c_char, offset: usize) -> *mut c_cha
     buf.add(offset)
         .copy_from_nonoverlapping(TEMPLATE.as_ptr() as _, TEMPLATE.len());
 
-    let err = platform::errno.get();
+    let err = platform::ERRNO.get();
     stdlib::mktemp(buf);
-    platform::errno.set(err);
+    platform::ERRNO.set(err);
 
     if *buf == 0 {
         ptr::null_mut()
diff --git a/src/header/stdio/printf.rs b/src/header/stdio/printf.rs
index e4897e74..0f4abe16 100644
--- a/src/header/stdio/printf.rs
+++ b/src/header/stdio/printf.rs
@@ -886,7 +886,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
                             let c = match char::from_u32(*ptr as _) {
                                 Some(c) => c,
                                 None => {
-                                    platform::errno.set(EILSEQ);
+                                    platform::ERRNO.set(EILSEQ);
                                     return Err(io::last_os_error());
                                 }
                             };
@@ -922,7 +922,7 @@ unsafe fn inner_printf<W: Write>(w: W, format: *const c_char, mut ap: VaList) ->
                     let c = match char::from_u32(c as _) {
                         Some(c) => c,
                         None => {
-                            platform::errno.set(EILSEQ);
+                            platform::ERRNO.set(EILSEQ);
                             return Err(io::last_os_error());
                         }
                     };
diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs
index 52e506dc..fa73a22a 100644
--- a/src/header/stdlib/mod.rs
+++ b/src/header/stdlib/mod.rs
@@ -125,7 +125,7 @@ pub unsafe extern "C" fn aligned_alloc(alignment: size_t, size: size_t) -> *mut
          * difference between aligned_alloc() and memalign(). */
         memalign(alignment, size)
     } else {
-        platform::errno.set(EINVAL);
+        platform::ERRNO.set(EINVAL);
         ptr::null_mut()
     }
 }
@@ -242,7 +242,7 @@ pub unsafe extern "C" fn calloc(nelem: size_t, elsize: size_t) -> *mut c_void {
         }
         None => {
             // For overflowing multiplication, we have to set errno here
-            platform::errno.set(ENOMEM);
+            platform::ERRNO.set(ENOMEM);
             ptr::null_mut()
         }
     }
@@ -545,7 +545,7 @@ pub unsafe extern "C" fn lrand48() -> c_long {
 pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
     let ptr = platform::alloc(size);
     if ptr.is_null() {
-        platform::errno.set(ENOMEM);
+        platform::ERRNO.set(ENOMEM);
     }
     ptr
 }
@@ -555,11 +555,11 @@ pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_voi
     if alignment.is_power_of_two() {
         let ptr = platform::alloc_align(size, alignment);
         if ptr.is_null() {
-            platform::errno.set(ENOMEM);
+            platform::ERRNO.set(ENOMEM);
         }
         ptr
     } else {
-        platform::errno.set(EINVAL);
+        platform::ERRNO.set(EINVAL);
         ptr::null_mut()
     }
 }
@@ -599,13 +599,13 @@ where
     let len = unsafe { strlen(name) as c_int };
 
     if len < 6 || suffix_len > len - 6 {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return None;
     }
 
     for i in (len - suffix_len - 6)..(len - suffix_len) {
         if unsafe { *name.offset(i as isize) } != b'X' as c_char {
-            platform::errno.set(errno::EINVAL);
+            platform::ERRNO.set(errno::EINVAL);
             return None;
         }
     }
@@ -630,7 +630,7 @@ where
         }
     }
 
-    platform::errno.set(errno::EEXIST);
+    platform::ERRNO.set(errno::EEXIST);
 
     None
 }
@@ -639,7 +639,7 @@ where
 pub unsafe extern "C" fn mktemp(name: *mut c_char) -> *mut c_char {
     if inner_mktemp(name, 0, || {
         let name = CStr::from_ptr(name);
-        if Sys::access(name, 0) != 0 && platform::errno.get() == ENOENT {
+        if Sys::access(name, 0) != 0 && platform::ERRNO.get() == ENOENT {
             Some(())
         } else {
             None
@@ -735,8 +735,8 @@ pub unsafe extern "C" fn posix_openpt(flags: c_int) -> c_int {
     #[cfg(target_os = "linux")]
     let r = open((b"/dev/ptmx\0" as *const u8).cast(), flags);
 
-    if r < 0 && platform::errno.get() == ENOSPC {
-        platform::errno.set(EAGAIN);
+    if r < 0 && platform::ERRNO.get() == ENOSPC {
+        platform::ERRNO.set(EAGAIN);
     }
 
     return r;
@@ -756,7 +756,7 @@ unsafe extern "C" fn ptsname(fd: c_int) -> *mut c_char {
 #[no_mangle]
 unsafe extern "C" fn ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
     if buf.is_null() {
-        platform::errno.set(EINVAL);
+        platform::ERRNO.set(EINVAL);
         EINVAL
     } else {
         __ptsname_r(fd, buf, buflen)
@@ -772,7 +772,7 @@ unsafe fn __ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
         if let Ok(name) = CStr::from_ptr(tty_ptr).to_str() {
             let len = name.len();
             if len > buflen {
-                platform::errno.set(ERANGE);
+                platform::ERRNO.set(ERANGE);
                 return ERANGE;
             } else {
                 // we have checked the string will fit in the buffer
@@ -783,31 +783,31 @@ unsafe fn __ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
             }
         }
     }
-    platform::errno.get()
+    platform::ERRNO.get()
 }
 
 #[cfg(target_os = "linux")]
 #[inline(always)]
 unsafe fn __ptsname_r(fd: c_int, buf: *mut c_char, buflen: size_t) -> c_int {
     let mut pty = 0;
-    let err = platform::errno.get();
+    let err = platform::ERRNO.get();
 
     if ioctl(fd, TIOCGPTN, &mut pty as *mut _ as *mut c_void) == 0 {
         let name = format!("/dev/pts/{}", pty);
         let len = name.len();
         if len > buflen {
-            platform::errno.set(ERANGE);
+            platform::ERRNO.set(ERANGE);
             ERANGE
         } else {
             // we have checked the string will fit in the buffer
             // so can use strcpy safely
             let s = name.as_ptr().cast();
             ptr::copy_nonoverlapping(s, buf, len);
-            platform::errno.set(err);
+            platform::ERRNO.set(err);
             0
         }
     } else {
-        platform::errno.get()
+        platform::ERRNO.get()
     }
 }
 
@@ -932,7 +932,7 @@ pub unsafe extern "C" fn random() -> c_long {
 pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void {
     let new_ptr = platform::realloc(ptr, size);
     if new_ptr.is_null() {
-        platform::errno.set(ENOMEM);
+        platform::ERRNO.set(ENOMEM);
     }
     new_ptr
 }
@@ -944,7 +944,7 @@ pub unsafe extern "C" fn reallocarray(ptr: *mut c_void, m: size_t, n: size_t) ->
         Some(size) => realloc(ptr, size),
         None => {
             // For overflowing multiplication, we have to set errno here
-            platform::errno.set(ENOMEM);
+            platform::ERRNO.set(ENOMEM);
             ptr::null_mut()
         }
     }
@@ -1185,7 +1185,7 @@ pub unsafe fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong,
             {
                 num = res;
             } else {
-                platform::errno.set(ERANGE);
+                platform::ERRNO.set(ERANGE);
                 num = c_ulong::max_value();
                 overflowed = true;
             }
@@ -1355,7 +1355,7 @@ pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void {
              * EINVAL, hence no call to memalign(). */
             let ptr = platform::alloc_align(size, page_size);
             if ptr.is_null() {
-                platform::errno.set(ENOMEM);
+                platform::ERRNO.set(ENOMEM);
             }
             ptr
         }
diff --git a/src/header/string/mod.rs b/src/header/string/mod.rs
index b06fd49b..285c19cf 100644
--- a/src/header/string/mod.rs
+++ b/src/header/string/mod.rs
@@ -214,7 +214,7 @@ pub unsafe extern "C" fn strndup(s1: *const c_char, size: size_t) -> *mut c_char
     // the "+ 1" is to account for the NUL byte
     let buffer = platform::alloc(len + 1) as *mut c_char;
     if buffer.is_null() {
-        platform::errno.set(ENOMEM as c_int);
+        platform::ERRNO.set(ENOMEM as c_int);
     } else {
         //memcpy(buffer, s1, len)
         for i in 0..len {
diff --git a/src/header/sys_ioctl/redox.rs b/src/header/sys_ioctl/redox.rs
index 1f3a57ee..6909e3de 100644
--- a/src/header/sys_ioctl/redox.rs
+++ b/src/header/sys_ioctl/redox.rs
@@ -158,7 +158,7 @@ pub unsafe extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) ->
             0
         }
         _ => {
-            platform::errno.set(errno::EINVAL);
+            platform::ERRNO.set(errno::EINVAL);
             -1
         }
     }
diff --git a/src/header/sys_select/mod.rs b/src/header/sys_select/mod.rs
index 8fd8ba6b..6208ab83 100644
--- a/src/header/sys_select/mod.rs
+++ b/src/header/sys_select/mod.rs
@@ -35,7 +35,7 @@ pub fn select_epoll(
     timeout: Option<&mut timeval>,
 ) -> c_int {
     if nfds < 0 || nfds > FD_SETSIZE as i32 {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return -1;
     };
 
@@ -81,7 +81,7 @@ pub fn select_epoll(
                 ..Default::default()
             };
             if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
-                if platform::errno.get() == errno::EPERM {
+                if platform::ERRNO.get() == errno::EPERM {
                     not_epoll += 1;
                 } else {
                     return -1;
diff --git a/src/header/sys_uio/mod.rs b/src/header/sys_uio/mod.rs
index d715d73b..2a7e2851 100644
--- a/src/header/sys_uio/mod.rs
+++ b/src/header/sys_uio/mod.rs
@@ -42,7 +42,7 @@ unsafe fn scatter(iovs: &[iovec], vec: Vec<u8>) {
 #[no_mangle]
 pub unsafe extern "C" fn readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
     if iovcnt < 0 || iovcnt > IOV_MAX {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return -1;
     }
 
@@ -59,7 +59,7 @@ pub unsafe extern "C" fn readv(fd: c_int, iov: *const iovec, iovcnt: c_int) -> s
 #[no_mangle]
 pub unsafe extern "C" fn writev(fd: c_int, iov: *const iovec, iovcnt: c_int) -> ssize_t {
     if iovcnt < 0 || iovcnt > IOV_MAX {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return -1;
     }
 
diff --git a/src/header/termios/mod.rs b/src/header/termios/mod.rs
index 523521c9..e1dc03fe 100644
--- a/src/header/termios/mod.rs
+++ b/src/header/termios/mod.rs
@@ -69,7 +69,7 @@ pub unsafe extern "C" fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
 #[no_mangle]
 pub unsafe extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int {
     if act < 0 || act > 2 {
-        platform::errno.set(errno::EINVAL);
+        platform::ERRNO.set(errno::EINVAL);
         return -1;
     }
     // This is safe because ioctl shouldn't modify the value
@@ -111,7 +111,7 @@ pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) ->
             0
         }
         _ => {
-            platform::errno.set(errno::EINVAL);
+            platform::ERRNO.set(errno::EINVAL);
             -1
         }
     }
@@ -121,7 +121,7 @@ pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) ->
 #[no_mangle]
 pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) -> c_int {
     //TODO
-    platform::errno.set(errno::EINVAL);
+    platform::ERRNO.set(errno::EINVAL);
     -1
 }
 
@@ -134,7 +134,7 @@ pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) ->
             0
         }
         _ => {
-            platform::errno.set(errno::EINVAL);
+            platform::ERRNO.set(errno::EINVAL);
             -1
         }
     }
@@ -144,7 +144,7 @@ pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) ->
 #[no_mangle]
 pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) -> c_int {
     //TODO
-    platform::errno.set(errno::EINVAL);
+    platform::ERRNO.set(errno::EINVAL);
     -1
 }
 
diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs
index 6534bd32..bd8594bb 100644
--- a/src/header/time/mod.rs
+++ b/src/header/time/mod.rs
@@ -396,7 +396,7 @@ pub unsafe extern "C" fn gmtime_r(clock: *const time_t, result: *mut tm) -> *mut
             result
         }
         Err(_) => {
-            platform::errno.set(EOVERFLOW);
+            platform::ERRNO.set(EOVERFLOW);
             core::ptr::null_mut()
         }
     }
diff --git a/src/header/unistd/brk.rs b/src/header/unistd/brk.rs
index 9b473794..7efa5c2b 100644
--- a/src/header/unistd/brk.rs
+++ b/src/header/unistd/brk.rs
@@ -12,7 +12,7 @@ pub unsafe extern "C" fn brk(addr: *mut c_void) -> c_int {
     BRK = Sys::brk(addr);
 
     if BRK < addr {
-        platform::errno.set(ENOMEM);
+        platform::ERRNO.set(ENOMEM);
         return -1;
     }
 
@@ -33,7 +33,7 @@ pub unsafe extern "C" fn sbrk(incr: intptr_t) -> *mut c_void {
         BRK = Sys::brk(addr);
 
         if BRK < addr {
-            platform::errno.set(ENOMEM);
+            platform::ERRNO.set(ENOMEM);
             return -1isize as *mut c_void;
         }
     }
diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs
index 1cb6236a..8068c6e1 100644
--- a/src/header/unistd/mod.rs
+++ b/src/header/unistd/mod.rs
@@ -78,13 +78,13 @@ pub extern "C" fn alarm(seconds: c_uint) -> c_uint {
         },
         ..Default::default()
     };
-    let errno_backup = platform::errno.get();
+    let errno_backup = platform::ERRNO.get();
     let secs = if sys_time::setitimer(sys_time::ITIMER_REAL, &timer, &mut timer) < 0 {
         0
     } else {
         timer.it_value.tv_sec as c_uint + if timer.it_value.tv_usec > 0 { 1 } else { 0 }
     };
-    platform::errno.set(errno_backup);
+    platform::ERRNO.set(errno_backup);
 
     secs
 }
@@ -98,7 +98,7 @@ pub unsafe extern "C" fn chdir(path: *const c_char) -> c_int {
 #[no_mangle]
 pub extern "C" fn chroot(path: *const c_char) -> c_int {
     // TODO: Implement
-    platform::errno.set(crate::header::errno::EPERM);
+    platform::ERRNO.set(crate::header::errno::EPERM);
 
     -1
 }
@@ -158,12 +158,12 @@ unsafe fn with_argv(
         // TODO: Use ARG_MAX, not this hardcoded constant
         let ptr = crate::header::stdlib::malloc(argc * mem::size_of::<*const c_char>());
         if ptr.is_null() {
-            platform::errno.set(ENOMEM);
+            platform::ERRNO.set(ENOMEM);
             return -1;
         }
         slice::from_raw_parts_mut(ptr.cast::<MaybeUninit<*const c_char>>(), argc)
     } else {
-        platform::errno.set(E2BIG);
+        platform::ERRNO.set(E2BIG);
         return -1;
     };
     out[0].write(arg0);
@@ -262,14 +262,14 @@ pub unsafe extern "C" fn execvp(file: *const c_char, argv: *const *mut c_char) -
                 let program_c = CStr::from_bytes_with_nul(&program).unwrap();
                 execv(program_c.as_ptr(), argv);
 
-                match platform::errno.get() {
+                match platform::ERRNO.get() {
                     errno::ENOENT => (),
                     other => error = other,
                 }
             }
         }
 
-        platform::errno.set(error);
+        platform::ERRNO.set(error);
         -1
     }
 }
@@ -433,7 +433,7 @@ pub unsafe extern "C" fn getlogin() -> *mut c_char {
 #[no_mangle]
 pub extern "C" fn getlogin_r(name: *mut c_char, namesize: size_t) -> c_int {
     //TODO: Determine correct getlogin result on Redox
-    platform::errno.set(errno::ENOENT);
+    platform::ERRNO.set(errno::ENOENT);
     -1
 }
 
@@ -527,7 +527,7 @@ pub unsafe extern "C" fn lockf(fildes: c_int, function: c_int, size: off_t) -> c
             if fl.l_type == fcntl::F_UNLCK as c_short || fl.l_pid == getpid() {
                 return 0;
             }
-            platform::errno.set(errno::EACCES);
+            platform::ERRNO.set(errno::EACCES);
             return -1;
         }
         fcntl::F_ULOCK => {
@@ -541,7 +541,7 @@ pub unsafe extern "C" fn lockf(fildes: c_int, function: c_int, size: off_t) -> c
             return fcntl::fcntl(fildes, fcntl::F_SETLKW, &mut fl as *mut _ as c_ulonglong);
         }
         _ => {
-            platform::errno.set(errno::EINVAL);
+            platform::ERRNO.set(errno::EINVAL);
             return -1;
         }
     };
@@ -797,7 +797,7 @@ pub extern "C" fn ttyname_r(fildes: c_int, name: *mut c_char, namesize: size_t)
 
     let len = Sys::fpath(fildes, &mut name[..namesize - 1]);
     if len < 0 {
-        return -platform::errno.get();
+        return -platform::ERRNO.get();
     }
     name[len as usize] = 0;
 
@@ -816,13 +816,13 @@ pub extern "C" fn ualarm(usecs: useconds_t, interval: useconds_t) -> useconds_t
             tv_usec: interval as suseconds_t,
         },
     };
-    let errno_backup = platform::errno.get();
+    let errno_backup = platform::ERRNO.get();
     let ret = if sys_time::setitimer(sys_time::ITIMER_REAL, &timer, &mut timer) < 0 {
         0
     } else {
         timer.it_value.tv_sec as useconds_t * 1_000_000 + timer.it_value.tv_usec as useconds_t
     };
-    platform::errno.set(errno_backup);
+    platform::ERRNO.set(errno_backup);
 
     ret
 }
diff --git a/src/header/unistd/pathconf.rs b/src/header/unistd/pathconf.rs
index 7974e042..074b6509 100644
--- a/src/header/unistd/pathconf.rs
+++ b/src/header/unistd/pathconf.rs
@@ -50,7 +50,7 @@ fn pc(name: c_int) -> c_long {
         _PC_SYMLINK_MAX => -1,
         _PC_2_SYMLINKS => 1,
         _ => {
-            platform::errno.set(errno::EINVAL);
+            platform::ERRNO.set(errno::EINVAL);
             -1
         }
     }
diff --git a/src/header/unistd/sysconf.rs b/src/header/unistd/sysconf.rs
index 3fce2930..15074a58 100644
--- a/src/header/unistd/sysconf.rs
+++ b/src/header/unistd/sysconf.rs
@@ -53,7 +53,7 @@ pub extern "C" fn sysconf(name: c_int) -> c_long {
         _SC_SYMLOOP_MAX => -1,
         _SC_HOST_NAME_MAX => 64,
         _ => {
-            platform::errno.set(errno::EINVAL);
+            platform::ERRNO.set(errno::EINVAL);
             -1
         }
     }
diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs
index 34fd1697..a2f8530a 100644
--- a/src/header/wchar/mod.rs
+++ b/src/header/wchar/mod.rs
@@ -12,7 +12,7 @@ use crate::{
         time::*,
         wctype::*,
     },
-    platform::{self, errno, types::*},
+    platform::{self, types::*, ERRNO},
 };
 
 mod utf8;
@@ -33,10 +33,10 @@ pub unsafe extern "C" fn btowc(c: c_int) -> wint_t {
     let c = uc as c_char;
     let mut ps: mbstate_t = mbstate_t;
     let mut wc: wchar_t = 0;
-    let saved_errno = platform::errno.get();
+    let saved_errno = platform::ERRNO.get();
     let status = mbrtowc(&mut wc, &c as *const c_char, 1, &mut ps);
     if status == usize::max_value() || status == usize::max_value() - 1 {
-        platform::errno.set(saved_errno);
+        platform::ERRNO.set(saved_errno);
         return WEOF;
     }
     wc as wint_t
@@ -59,7 +59,7 @@ pub unsafe extern "C" fn fgetwc(stream: *mut FILE) -> wint_t {
         );
 
         if nread != 1 {
-            errno.set(EILSEQ);
+            ERRNO.set(EILSEQ);
             return WEOF;
         }
 
@@ -75,7 +75,7 @@ pub unsafe extern "C" fn fgetwc(stream: *mut FILE) -> wint_t {
             } else if buf[0] >> 3 == 0x1e {
                 4
             } else {
-                errno.set(EILSEQ);
+                ERRNO.set(EILSEQ);
                 return WEOF;
             };
         }
@@ -392,7 +392,7 @@ pub unsafe extern "C" fn wcsdup(s: *const wchar_t) -> *mut wchar_t {
     let d = malloc((l + 1) * mem::size_of::<wchar_t>()) as *mut wchar_t;
 
     if d.is_null() {
-        errno.set(ENOMEM);
+        ERRNO.set(ENOMEM);
         return ptr::null_mut();
     }
 
@@ -586,7 +586,7 @@ pub unsafe extern "C" fn wcsnrtombs(
         let ret = wcrtomb(buf.as_mut_ptr(), **src, ps);
 
         if ret == size_t::MAX {
-            errno.set(EILSEQ);
+            ERRNO.set(EILSEQ);
             return size_t::MAX;
         }
 
@@ -785,7 +785,7 @@ macro_rules! strtou_impl {
             result = match new {
                 Some(new) => new,
                 None => {
-                    platform::errno.set(ERANGE);
+                    platform::ERRNO.set(ERANGE);
                     return !0;
                 }
             };
diff --git a/src/header/wchar/utf8.rs b/src/header/wchar/utf8.rs
index 21f3c346..b1961c1a 100644
--- a/src/header/wchar/utf8.rs
+++ b/src/header/wchar/utf8.rs
@@ -44,18 +44,18 @@ fn utf8_char_width(b: u8) -> usize {
 pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mbstate_t) -> usize {
     let size = utf8_char_width(*s as u8);
     if size > n {
-        platform::errno.set(errno::EILSEQ);
+        platform::ERRNO.set(errno::EILSEQ);
         return -2isize as usize;
     }
     if size == 0 {
-        platform::errno.set(errno::EILSEQ);
+        platform::ERRNO.set(errno::EILSEQ);
         return -1isize as usize;
     }
 
     let slice = slice::from_raw_parts(s as *const u8, size);
     let decoded = str::from_utf8(slice);
     if decoded.is_err() {
-        platform::errno.set(errno::EILSEQ);
+        platform::ERRNO.set(errno::EILSEQ);
         return -1isize as usize;
     }
 
@@ -79,7 +79,7 @@ pub unsafe fn wcrtomb(s: *mut c_char, wc: wchar_t, ps: *mut mbstate_t) -> usize
     let dc = char::from_u32(wc as u32);
 
     if dc.is_none() {
-        platform::errno.set(errno::EILSEQ);
+        platform::ERRNO.set(errno::EILSEQ);
         return -1isize as usize;
     }
 
diff --git a/src/header/wchar/wprintf.rs b/src/header/wchar/wprintf.rs
index 5576599f..875351ff 100644
--- a/src/header/wchar/wprintf.rs
+++ b/src/header/wchar/wprintf.rs
@@ -898,7 +898,7 @@ unsafe fn inner_wprintf<W: Write>(
                             let c = match char::from_u32(*ptr as _) {
                                 Some(c) => c,
                                 None => {
-                                    platform::errno.set(EILSEQ);
+                                    platform::ERRNO.set(EILSEQ);
                                     return Err(io::last_os_error());
                                 }
                             };
@@ -934,7 +934,7 @@ unsafe fn inner_wprintf<W: Write>(
                     let c = match char::from_u32(c as _) {
                         Some(c) => c,
                         None => {
-                            platform::errno.set(EILSEQ);
+                            platform::ERRNO.set(EILSEQ);
                             return Err(io::last_os_error());
                         }
                     };
diff --git a/src/io/error.rs b/src/io/error.rs
index 00fca803..e512d94b 100644
--- a/src/io/error.rs
+++ b/src/io/error.rs
@@ -170,7 +170,7 @@ impl Error {
     }
 
     pub fn last_os_error() -> Error {
-        let errno = crate::platform::errno.get();
+        let errno = crate::platform::ERRNO.get();
         Error::from_raw_os_error(errno)
     }
 }
diff --git a/src/ld_so/dso.rs b/src/ld_so/dso.rs
index d8e16b8d..0bd7a566 100644
--- a/src/ld_so/dso.rs
+++ b/src/ld_so/dso.rs
@@ -5,7 +5,7 @@ use super::{
 };
 use crate::{
     header::{errno::STR_ERROR, sys_mman},
-    platform::{errno, types::c_void},
+    platform::{types::c_void, ERRNO},
 };
 use alloc::{
     collections::BTreeMap,
@@ -230,7 +230,7 @@ impl DSO {
                     return Err(Error::Malformed(format!(
                         "failed to map {}. errno: {}",
                         path,
-                        STR_ERROR[errno.get() as usize]
+                        STR_ERROR[ERRNO.get() as usize]
                     )));
                 }
                 if start as *mut c_void != ptr::null_mut() {
diff --git a/src/macros.rs b/src/macros.rs
index a82c4a2b..23f6809d 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -145,7 +145,7 @@ macro_rules! strto_impl {
         };
 
         let invalid_input = || {
-            platform::errno.set(EINVAL);
+            platform::ERRNO.set(EINVAL);
             set_endptr(0);
         };
 
@@ -203,7 +203,7 @@ macro_rules! strto_impl {
         // account for the sign
         let num = num as $rettype;
         let num = if overflow {
-            platform::errno.set(ERANGE);
+            platform::ERRNO.set(ERANGE);
             if CHECK_SIGN {
                 if positive {
                     MAX_VAL
diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index b317ea05..5852a124 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -1,7 +1,7 @@
 use crate::io::Write;
 use core::{arch::asm, ptr};
 
-use super::{errno, types::*, Pal};
+use super::{types::*, Pal, ERRNO};
 use crate::{
     c_str::CStr,
     header::{dirent::dirent, errno::EINVAL, signal::SIGCHLD, sys_stat::S_IFIFO},
@@ -63,7 +63,7 @@ pub fn e(sys: usize) -> usize {
     match e_raw(sys) {
         Ok(value) => value,
         Err(errcode) => {
-            errno.set(errcode as c_int);
+            ERRNO.set(errcode as c_int);
             !0
         }
     }
diff --git a/src/platform/mod.rs b/src/platform/mod.rs
index 3006997b..8e2547c1 100644
--- a/src/platform/mod.rs
+++ b/src/platform/mod.rs
@@ -36,9 +36,7 @@ use self::types::*;
 pub mod types;
 
 #[thread_local]
-#[allow(non_upper_case_globals)]
-#[no_mangle]
-pub static errno: Cell<c_int> = Cell::new(0);
+pub static ERRNO: Cell<c_int> = Cell::new(0);
 
 #[allow(non_upper_case_globals)]
 pub static mut argv: *mut *mut c_char = ptr::null_mut();
diff --git a/src/platform/redox/epoll.rs b/src/platform/redox/epoll.rs
index 7ba86f11..6fb98170 100644
--- a/src/platform/redox/epoll.rs
+++ b/src/platform/redox/epoll.rs
@@ -47,7 +47,7 @@ impl PalEpoll for Sys {
                 ) as c_int
             }
             _ => {
-                platform::errno.set(EINVAL);
+                platform::ERRNO.set(EINVAL);
                 return -1;
             }
         }
@@ -64,7 +64,7 @@ impl PalEpoll for Sys {
         assert_eq!(mem::size_of::<epoll_event>(), mem::size_of::<Event>());
 
         if maxevents <= 0 {
-            platform::errno.set(EINVAL);
+            platform::ERRNO.set(EINVAL);
             return -1;
         }
 
diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs
index 5ebb2e80..1cab9ea2 100644
--- a/src/platform/redox/mod.rs
+++ b/src/platform/redox/mod.rs
@@ -28,7 +28,7 @@ use crate::{
 
 pub use redox_exec::FdGuard;
 
-use super::{errno, types::*, Pal, Read};
+use super::{types::*, Pal, Read, ERRNO};
 
 static mut BRK_CUR: *mut c_void = ptr::null_mut();
 static mut BRK_END: *mut c_void = ptr::null_mut();
@@ -54,7 +54,7 @@ macro_rules! path_from_c_str {
         match $c_str.to_str() {
             Ok(ok) => ok,
             Err(err) => {
-                errno.set(EINVAL);
+                ERRNO.set(EINVAL);
                 return -1;
             }
         }
@@ -67,7 +67,7 @@ pub fn e(sys: Result<usize>) -> usize {
     match sys {
         Ok(ok) => ok,
         Err(err) => {
-            errno.set(err.errno as c_int);
+            ERRNO.set(err.errno as c_int);
             !0
         }
     }
@@ -112,7 +112,7 @@ impl Pal for Sys {
             || (mode & W_OK == W_OK && perms & 0o2 != 0o2)
             || (mode & X_OK == X_OK && perms & 0o1 != 0o1)
         {
-            errno.set(EINVAL);
+            ERRNO.set(EINVAL);
             return -1;
         }
 
@@ -153,7 +153,7 @@ impl Pal for Sys {
                 addr
             } else {
                 // It was outside of valid range
-                errno.set(ENOMEM);
+                ERRNO.set(ENOMEM);
                 ptr::null_mut()
             }
         }
@@ -182,7 +182,7 @@ impl Pal for Sys {
     fn clock_getres(clk_id: clockid_t, tp: *mut timespec) -> c_int {
         // TODO
         eprintln!("relibc clock_getres({}, {:p}): not implemented", clk_id, tp);
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
@@ -198,7 +198,7 @@ impl Pal for Sys {
             "relibc clock_settime({}, {:p}): not implemented",
             clk_id, tp
         );
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
@@ -246,7 +246,7 @@ impl Pal for Sys {
             match str::from_utf8(&buf[..res]) {
                 Ok(path) => e(path::chdir(path).map(|()| 0)) as c_int,
                 Err(_) => {
-                    errno.set(EINVAL);
+                    ERRNO.set(EINVAL);
                     return -1;
                 }
             }
@@ -337,12 +337,12 @@ impl Pal for Sys {
 
         let buf_slice = unsafe { slice::from_raw_parts_mut(buf as *mut u8, size as usize) };
         if buf_slice.is_empty() {
-            errno.set(EINVAL);
+            ERRNO.set(EINVAL);
             return ptr::null_mut();
         }
 
         if path::getcwd(buf_slice).is_none() {
-            errno.set(ERANGE);
+            ERRNO.set(ERANGE);
             return ptr::null_mut();
         }
 
@@ -457,7 +457,7 @@ impl Pal for Sys {
     unsafe fn getgroups(size: c_int, list: *mut gid_t) -> c_int {
         // TODO
         eprintln!("relibc getgroups({}, {:p}): not implemented", size, list);
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
@@ -480,7 +480,7 @@ impl Pal for Sys {
     fn getpriority(which: c_int, who: id_t) -> c_int {
         // TODO
         eprintln!("getpriority({}, {}): not implemented", which, who);
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
@@ -530,7 +530,7 @@ impl Pal for Sys {
             "relibc setrlimit({}, {:p}): not implemented",
             resource, rlim
         );
-        errno.set(EPERM);
+        ERRNO.set(EPERM);
         -1
     }
 
@@ -630,7 +630,7 @@ impl Pal for Sys {
         let dir_path = match str::from_utf8(&dir_path_buf[..res as usize]) {
             Ok(path) => path,
             Err(_) => {
-                errno.set(EBADR);
+                ERRNO.set(EBADR);
                 return !0;
             }
         };
@@ -641,7 +641,7 @@ impl Pal for Sys {
                 None => {
                     // Since parent_dir_path is resolved by fpath, it is more likely that
                     // the problem was with path.
-                    errno.set(ENOENT);
+                    ERRNO.set(ENOENT);
                     return !0;
                 }
             };
@@ -874,7 +874,7 @@ impl Pal for Sys {
     unsafe fn setgroups(size: size_t, list: *const gid_t) -> c_int {
         // TODO
         eprintln!("relibc setgroups({}, {:p}): not implemented", size, list);
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
@@ -888,7 +888,7 @@ impl Pal for Sys {
             "relibc setpriority({}, {}, {}): not implemented",
             which, who, prio
         );
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
@@ -1018,7 +1018,7 @@ impl Pal for Sys {
         match inner(utsname) {
             Ok(()) => 0,
             Err(err) => {
-                errno.set(err);
+                ERRNO.set(err);
                 -1
             }
         }
diff --git a/src/platform/redox/ptrace.rs b/src/platform/redox/ptrace.rs
index 0c9ba44d..90234186 100644
--- a/src/platform/redox/ptrace.rs
+++ b/src/platform/redox/ptrace.rs
@@ -4,7 +4,7 @@
 //! we are NOT going to bend our API for the sake of
 //! compatibility. So, this module will be a hellhole.
 
-use super::super::{errno, types::*, Pal, PalPtrace, PalSignal, Sys};
+use super::super::{types::*, Pal, PalPtrace, PalSignal, Sys, ERRNO};
 #[cfg(target_arch = "aarch64")]
 use crate::header::arch_aarch64_user::user_regs_struct;
 #[cfg(target_arch = "x86_64")]
@@ -91,7 +91,7 @@ pub fn get_session(
                     )?,
                 }))
             } else {
-                errno.set(errnoh::ESRCH);
+                ERRNO.set(errnoh::ESRCH);
                 Err(io::last_os_error())
             }
         }
diff --git a/src/platform/redox/signal.rs b/src/platform/redox/signal.rs
index d60fd9ad..97d4ca73 100644
--- a/src/platform/redox/signal.rs
+++ b/src/platform/redox/signal.rs
@@ -12,7 +12,7 @@ use crate::{
         sys_time::{itimerval, ITIMER_REAL},
         time::timespec,
     },
-    platform::errno,
+    platform::ERRNO,
 };
 
 impl PalSignal for Sys {
@@ -20,7 +20,7 @@ impl PalSignal for Sys {
         let path = match which {
             ITIMER_REAL => "itimer:1",
             _ => {
-                errno.set(EINVAL);
+                ERRNO.set(EINVAL);
                 return -1;
             }
         };
@@ -65,7 +65,7 @@ impl PalSignal for Sys {
         let path = match which {
             ITIMER_REAL => "itimer:1",
             _ => {
-                errno.set(EINVAL);
+                ERRNO.set(EINVAL);
                 return -1;
             }
         };
@@ -115,7 +115,7 @@ impl PalSignal for Sys {
     }
 
     fn sigpending(set: *mut sigset_t) -> c_int {
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
@@ -124,12 +124,12 @@ impl PalSignal for Sys {
     }
 
     fn sigsuspend(set: *const sigset_t) -> c_int {
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 
     fn sigtimedwait(set: *const sigset_t, sig: *mut siginfo_t, tp: *const timespec) -> c_int {
-        errno.set(ENOSYS);
+        ERRNO.set(ENOSYS);
         -1
     }
 }
diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs
index cb9577b0..f01b6e96 100644
--- a/src/platform/redox/socket.rs
+++ b/src/platform/redox/socket.rs
@@ -3,7 +3,7 @@ use core::{cmp, mem, ptr, slice, str};
 use syscall::{self, flag::*, Result};
 
 use super::{
-    super::{errno, types::*, Pal, PalSocket},
+    super::{types::*, Pal, PalSocket, ERRNO},
     e, Sys,
 };
 use crate::header::{
@@ -34,14 +34,14 @@ macro_rules! bind_or_connect {
     }};
     ($mode:ident copy, $socket:expr, $address:expr, $address_len:expr) => {{
         if ($address_len as usize) < mem::size_of::<sa_family_t>() {
-            errno.set(syscall::EINVAL);
+            ERRNO.set(syscall::EINVAL);
             return -1;
         }
 
         let path = match (*$address).sa_family as c_int {
             AF_INET => {
                 if ($address_len as usize) != mem::size_of::<sockaddr_in>() {
-                    errno.set(syscall::EINVAL);
+                    ERRNO.set(syscall::EINVAL);
                     return -1;
                 }
                 let data = &*($address as *const sockaddr_in);
@@ -93,7 +93,7 @@ macro_rules! bind_or_connect {
                 path
             },
             _ => {
-                errno.set(syscall::EAFNOSUPPORT);
+                ERRNO.set(syscall::EAFNOSUPPORT);
                 return -1;
             },
         };
@@ -295,7 +295,7 @@ impl PalSocket for Sys {
         address_len: *mut socklen_t,
     ) -> ssize_t {
         if flags != 0 {
-            errno.set(syscall::EOPNOTSUPP);
+            ERRNO.set(syscall::EOPNOTSUPP);
             return -1;
         }
         if address == ptr::null_mut() || address_len == ptr::null_mut() {
@@ -319,14 +319,14 @@ impl PalSocket for Sys {
     unsafe fn recvmsg(socket: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t {
         //TODO: implement recvfrom with recvmsg
         eprintln!("recvmsg not implemented on redox");
-        errno.set(syscall::ENOSYS);
+        ERRNO.set(syscall::ENOSYS);
         return -1;
     }
 
     unsafe fn sendmsg(socket: c_int, msg: *const msghdr, flags: c_int) -> ssize_t {
         //TODO: implement sendto with sendmsg
         eprintln!("sendmsg not implemented on redox");
-        errno.set(syscall::ENOSYS);
+        ERRNO.set(syscall::ENOSYS);
         return -1;
     }
 
@@ -339,7 +339,7 @@ impl PalSocket for Sys {
         dest_len: socklen_t,
     ) -> ssize_t {
         if flags != 0 {
-            errno.set(syscall::EOPNOTSUPP);
+            ERRNO.set(syscall::EOPNOTSUPP);
             return -1;
         }
         if dest_addr == ptr::null() || dest_len == 0 {
@@ -414,11 +414,11 @@ impl PalSocket for Sys {
 
     unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
         if domain != AF_INET && domain != AF_UNIX {
-            errno.set(syscall::EAFNOSUPPORT);
+            ERRNO.set(syscall::EAFNOSUPPORT);
             return -1;
         }
         // if protocol != 0 {
-        //     errno.set(syscall::EPROTONOSUPPORT);
+        //     ERRNO.set(syscall::EPROTONOSUPPORT);
         //     return -1;
         // }
 
@@ -431,7 +431,7 @@ impl PalSocket for Sys {
             (AF_INET, SOCK_DGRAM) => e(syscall::open("udp:", flags)) as c_int,
             (AF_UNIX, SOCK_STREAM) => e(syscall::open("chan:", flags | O_CREAT)) as c_int,
             _ => {
-                errno.set(syscall::EPROTONOSUPPORT);
+                ERRNO.set(syscall::EPROTONOSUPPORT);
                 -1
             }
         }
@@ -476,7 +476,7 @@ impl PalSocket for Sys {
                     protocol,
                     sv.as_mut_ptr()
                 );
-                errno.set(syscall::EPROTONOSUPPORT);
+                ERRNO.set(syscall::EPROTONOSUPPORT);
                 -1
             },
         }
-- 
GitLab