Capture errno first during ErrnoErrorf.

Bug: 335967603
Change-Id: I9db3e7ec193e9f84c1effdc9718df0de1d42adf4
Test: Presubmit
diff --git a/include/android-base/result.h b/include/android-base/result.h
index 00abab4..c6cc9fd 100644
--- a/include/android-base/result.h
+++ b/include/android-base/result.h
@@ -126,6 +126,8 @@
   }
 };
 
+static_assert(std::is_trivially_copyable_v<Errno> == true);
+
 template <typename E = Errno, bool include_message = true>
 struct ResultError {
   template <typename T, typename P, typename = std::enable_if_t<std::is_convertible_v<P, E>>>
@@ -308,8 +310,8 @@
 
 template <typename... Args>
 inline ResultError<Errno> ErrnoErrorfImpl(fmt::format_string<Args...> fmt, const Args&... args) {
-  return MakeResultErrorWithCode(fmt::vformat(fmt.get(), fmt::make_format_args(args...)),
-                                 Errno{errno});
+  Errno code{errno};
+  return MakeResultErrorWithCode(fmt::vformat(fmt.get(), fmt::make_format_args(args...)), code);
 }
 
 #define Errorf(fmt, ...) android::base::ErrorfImpl(FMT_STRING(fmt), ##__VA_ARGS__)