Port __errno_location to FreeBSD (__error) across 11 libraries

ober

3e8bd41d2acb03c4de13a43292565a8905ec5882

diff --git a/lib/std/net/repl.sls b/lib/std/net/repl.sls
index 668426b..99241ee 100644
--- a/lib/std/net/repl.sls
+++ b/lib/std/net/repl.sls
@@ -30,7 +30,10 @@
   (define c-htons     (foreign-procedure "htons" (unsigned-short) unsigned-short))
   (define c-getsockname (foreign-procedure "getsockname" (int void* void*) int))
   (define c-fcntl     (foreign-procedure "fcntl" (int int int) int))
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
 
   ;; Constants
diff --git a/lib/std/net/tcp-raw.sls b/lib/std/net/tcp-raw.sls
index 58d4e00..f0d568b 100644
--- a/lib/std/net/tcp-raw.sls
+++ b/lib/std/net/tcp-raw.sls
@@ -36,7 +36,10 @@
   (define c-inet-pton (foreign-procedure "inet_pton" (int string void*) int))
 
   ;; errno
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
   (define EINTR 4)
 
diff --git a/lib/std/net/tcp.sls b/lib/std/net/tcp.sls
index 65c81bc..fd6b214 100644
--- a/lib/std/net/tcp.sls
+++ b/lib/std/net/tcp.sls
@@ -50,7 +50,10 @@
   (define c-fcntl     (foreign-procedure "fcntl" (int int int) int))
 
   ;; errno access for EINTR retry
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
   (define EINTR 4)
   (define EAGAIN 11)
diff --git a/lib/std/os/fcntl.sls b/lib/std/os/fcntl.sls
index d36824b..8b58b30 100644
--- a/lib/std/os/fcntl.sls
+++ b/lib/std/os/fcntl.sls
@@ -27,7 +27,10 @@
   (define c-fcntl (foreign-procedure "fcntl" (int int int) int))
 
   ;; errno access for error reporting
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
 
   ;; ========== Constants ==========
diff --git a/lib/std/os/flock.sls b/lib/std/os/flock.sls
index 88a570a..95f5087 100644
--- a/lib/std/os/flock.sls
+++ b/lib/std/os/flock.sls
@@ -23,7 +23,10 @@
   (define c-flock (foreign-procedure "flock" (int int) int))
 
   ;; errno access
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
   (define EWOULDBLOCK 11)  ;; same as EAGAIN on Linux
 
diff --git a/lib/std/os/posix.sls b/lib/std/os/posix.sls
index cca13c7..a4e5f31 100644
--- a/lib/std/os/posix.sls
+++ b/lib/std/os/posix.sls
@@ -95,10 +95,12 @@
 
   ;; ========== Errno ==========
 
-  ;; errno is thread-local via __errno_location on Linux
+  ;; errno is thread-local via __errno_location on Linux / __error on FreeBSD
   (define c-errno-location
     (guard (e [#t #f])
-      (foreign-procedure "__errno_location" () void*)))
+      (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+        (foreign-procedure "__error" () void*)
+        (foreign-procedure "__errno_location" () void*))))
 
   (define (posix-errno)
     (if c-errno-location
diff --git a/lib/std/os/signalfd.sls b/lib/std/os/signalfd.sls
index 34264d5..b2ee12e 100644
--- a/lib/std/os/signalfd.sls
+++ b/lib/std/os/signalfd.sls
@@ -54,7 +54,10 @@
   (define c-sigprocmask (foreign-procedure "sigprocmask" (int void* void*) int))
 
   ;; errno access
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
   (define EINTR 4)
 
diff --git a/lib/std/security/landlock.sls b/lib/std/security/landlock.sls
index 6d4f2da..d8145c5 100644
--- a/lib/std/security/landlock.sls
+++ b/lib/std/security/landlock.sls
@@ -56,7 +56,9 @@
 
   (define c-errno
     (guard (e [#t (lambda () 0)])
-      (foreign-procedure "__errno_location" () void*)))
+      (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+        (foreign-procedure "__error" () void*)
+        (foreign-procedure "__errno_location" () void*))))
 
   (define (get-errno)
     (guard (e [#t 0])
diff --git a/lib/std/security/seccomp.sls b/lib/std/security/seccomp.sls
index d394a33..c3cfe8f 100644
--- a/lib/std/security/seccomp.sls
+++ b/lib/std/security/seccomp.sls
@@ -47,7 +47,9 @@
 
   (define c-errno
     (guard (e [#t (lambda () 0)])
-      (foreign-procedure "__errno_location" () void*)))
+      (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+        (foreign-procedure "__error" () void*)
+        (foreign-procedure "__errno_location" () void*))))
 
   (define (get-errno)
     (guard (e [#t 0])
diff --git a/lib/std/web/fastcgi.sls b/lib/std/web/fastcgi.sls
index bef8f2a..ddd425d 100644
--- a/lib/std/web/fastcgi.sls
+++ b/lib/std/web/fastcgi.sls
@@ -43,7 +43,10 @@
   (define c-htons     (foreign-procedure "htons" (unsigned-short) unsigned-short))
   (define c-inet-pton (foreign-procedure "inet_pton" (int string void*) int))
   (define c-fcntl     (foreign-procedure "fcntl" (int int int) int))
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
 
   (define AF_INET 2)
diff --git a/lib/std/web/rack.sls b/lib/std/web/rack.sls
index 063a84f..579ca43 100644
--- a/lib/std/web/rack.sls
+++ b/lib/std/web/rack.sls
@@ -38,7 +38,10 @@
   (define c-htons     (foreign-procedure "htons" (unsigned-short) unsigned-short))
   (define c-inet-pton (foreign-procedure "inet_pton" (int string void*) int))
   (define c-fcntl     (foreign-procedure "fcntl" (int int int) int))
-  (define c-errno-location (foreign-procedure "__errno_location" () void*))
+  (define c-errno-location
+    (if (memq (machine-type) '(a6fb ta6fb i3fb ti3fb arm64fb))
+      (foreign-procedure "__error" () void*)
+      (foreign-procedure "__errno_location" () void*)))
   (define (get-errno) (foreign-ref 'int (c-errno-location) 0))
 
   (define AF_INET 2)