diff --git a/src/unix/bsd/freebsdlike/dragonfly/errno.rs b/src/unix/bsd/freebsdlike/dragonfly/errno.rs
new file mode 100644
index 0000000000000000000000000000000000000000..434ac63a3c3e5490e54d54339d843aeffe03dcd7
--- /dev/null
+++ b/src/unix/bsd/freebsdlike/dragonfly/errno.rs
@@ -0,0 +1,13 @@
+// DragonFlyBSD's __error function is declared with "static inline", so it must
+// be implemented in the libc crate, as a pointer to a static thread_local.
+f! {
+    #[deprecated(since = "0.2.77", "Use `__errno_location()` instead")]
+    pub fn __error() -> *mut ::c_int {
+        &mut errno
+    }
+}
+
+extern "C" {
+    #[thread_local]
+    pub static mut errno: ::c_int;
+}
diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs
index 26799e618f780836bb0938f4a22b257cdd9aed5d..47e3b7c1524b6048dc77ec83eb6ada71767b1b71 100644
--- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs
+++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs
@@ -1078,3 +1078,10 @@ extern "C" {
         needlelen: ::size_t,
     ) -> *mut ::c_void;
 }
+
+cfg_if! {
+    if #[cfg(libc_thread_local)] {
+        mod errno;
+        pub use self::errno::*;
+    }
+}