treewide: Switch to std::format

Reduce our dependence on fmtlib.

Change-Id: I1cc9b372aa366ae26d846470c8ab9d1d52e8db70
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include/stdplus/raw.hpp b/include/stdplus/raw.hpp
index 4f6c076..77bcf5d 100644
--- a/include/stdplus/raw.hpp
+++ b/include/stdplus/raw.hpp
@@ -1,9 +1,8 @@
 #pragma once
-#include <fmt/format.h>
-
 #include <stdplus/concepts.hpp>
 
 #include <algorithm>
+#include <format>
 #include <span>
 #include <stdexcept>
 #include <string_view>
@@ -84,7 +83,7 @@
         if (bytes comp sizeof(ret))                                            \
         {                                                                      \
             throw std::runtime_error(                                          \
-                fmt::format(#func ": {} < {}", bytes, sizeof(ret)));           \
+                std::format(#func ": {} < {}", bytes, sizeof(ret)));           \
         }                                                                      \
         const auto c_bytes = reinterpret_cast<const std::byte*>(std::data(c)); \
         const auto ret_bytes = reinterpret_cast<std::byte*>(&ret);             \
@@ -119,7 +118,7 @@
         if (bytes comp sizeof(Tp))                                             \
         {                                                                      \
             throw std::runtime_error(                                          \
-                fmt::format(#func ": {} < {}", bytes, sizeof(Tp)));            \
+                std::format(#func ": {} < {}", bytes, sizeof(Tp)));            \
         }                                                                      \
         return *reinterpret_cast<Tp*>(std::data(c));                           \
     }
diff --git a/src/dl.cpp b/src/dl.cpp
index 050f25c..98ecae0 100644
--- a/src/dl.cpp
+++ b/src/dl.cpp
@@ -1,8 +1,9 @@
 #include <dlfcn.h>
-#include <fmt/format.h>
 
 #include <stdplus/dl.hpp>
 
+#include <format>
+
 namespace stdplus
 {
 
@@ -30,7 +31,7 @@
     void* ret = ::dlopen(file, flags);
     if (ret == nullptr)
     {
-        throw std::runtime_error(fmt::format(
+        throw std::runtime_error(std::format(
             "dlopen `{}`: {}", file ? file : "<nullptr>", dlerror()));
     }
     return ret;
diff --git a/src/fd/atomic.cpp b/src/fd/atomic.cpp
index ce9dff2..5299789 100644
--- a/src/fd/atomic.cpp
+++ b/src/fd/atomic.cpp
@@ -1,5 +1,5 @@
-#include <fmt/format.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 #include <stdplus/fd/atomic.hpp>
 #include <stdplus/fd/managed.hpp>
@@ -7,6 +7,7 @@
 
 #include <cstdlib>
 #include <filesystem>
+#include <format>
 #include <system_error>
 #include <utility>
 
@@ -19,7 +20,7 @@
 {
     auto name = filename.filename();
     auto path = filename.parent_path() /
-                fmt::format(".{}.XXXXXX", name.native());
+                std::format(".{}.XXXXXX", name.native());
     return path.native();
 }
 
@@ -30,7 +31,7 @@
     umask(old);
     return CHECK_ERRNO(fd, [&](int error) {
         throw std::system_error(error, std::generic_category(),
-                                fmt::format("mkstemp({})", tmpl));
+                                std::format("mkstemp({})", tmpl));
     });
 }
 
diff --git a/src/fd/create.cpp b/src/fd/create.cpp
index bfef66f..d9b90f0 100644
--- a/src/fd/create.cpp
+++ b/src/fd/create.cpp
@@ -1,10 +1,11 @@
 #include <fcntl.h>
-#include <fmt/format.h>
 #include <sys/socket.h>
 
 #include <stdplus/fd/create.hpp>
 #include <stdplus/util/cexec.hpp>
 
+#include <format>
+
 namespace stdplus
 {
 namespace fd
@@ -14,7 +15,7 @@
 {
     return DupableFd(
         CHECK_ERRNO(::open(pathname, static_cast<int>(flags), mode),
-                    fmt::format("open `{}`", pathname)));
+                    std::format("open `{}`", pathname)));
 }
 
 DupableFd socket(SocketDomain domain, SocketType type, SocketProto protocol)
diff --git a/src/fd/impl.cpp b/src/fd/impl.cpp
index 1272fc8..40ce7b3 100644
--- a/src/fd/impl.cpp
+++ b/src/fd/impl.cpp
@@ -1,5 +1,4 @@
 #include <fcntl.h>
-#include <fmt/format.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <unistd.h>
@@ -8,6 +7,7 @@
 #include <stdplus/fd/impl.hpp>
 #include <stdplus/util/cexec.hpp>
 
+#include <format>
 #include <string_view>
 
 namespace stdplus
@@ -102,12 +102,12 @@
 size_t FdImpl::lseek(off_t offset, Whence whence)
 {
     return CHECK_ERRNO(::lseek(get(), offset, static_cast<int>(whence)),
-                       fmt::format("lseek {}B {}", offset, whenceStr(whence)));
+                       std::format("lseek {}B {}", offset, whenceStr(whence)));
 }
 
 void FdImpl::truncate(off_t size)
 {
-    CHECK_ERRNO(::ftruncate(get(), size), fmt::format("ftruncate {}B", size));
+    CHECK_ERRNO(::ftruncate(get(), size), std::format("ftruncate {}B", size));
 }
 
 void FdImpl::bind(std::span<const std::byte> sockaddr)
@@ -156,7 +156,7 @@
 int FdImpl::constIoctl(unsigned long id, void* data) const
 {
     return CHECK_ERRNO(::ioctl(get(), id, data),
-                       fmt::format("ioctl {:#x}", id));
+                       std::format("ioctl {:#x}", id));
 }
 
 void FdImpl::fcntlSetfd(FdFlags flags)
diff --git a/src/fd/ops.cpp b/src/fd/ops.cpp
index e8f3636..b0f2bef 100644
--- a/src/fd/ops.cpp
+++ b/src/fd/ops.cpp
@@ -1,8 +1,7 @@
-#include <fmt/format.h>
-
 #include <stdplus/exception.hpp>
 #include <stdplus/fd/ops.hpp>
 
+#include <format>
 #include <utility>
 
 namespace stdplus
@@ -22,7 +21,7 @@
         if (ret.size() == 0)
         {
             throw exception::WouldBlock(
-                fmt::format("{} missing {}B", name, data.size()));
+                std::format("{} missing {}B", name, data.size()));
         }
         data = data.subspan(ret.size());
     }
@@ -61,7 +60,7 @@
         if (ret.size() != 0 && r.size() == 0)
         {
             throw exception::WouldBlock(
-                fmt::format("{} is {}B/{}B", name, ret.size() % align, align));
+                std::format("{} is {}B/{}B", name, ret.size() % align, align));
         }
         ret = data.subspan(0, ret.size() + r.size());
     } while (ret.size() % align != 0);
diff --git a/src/gtest/tmp.cpp b/src/gtest/tmp.cpp
index 4d06de5..d5e2ab2 100644
--- a/src/gtest/tmp.cpp
+++ b/src/gtest/tmp.cpp
@@ -1,8 +1,7 @@
-#include <fmt/format.h>
-
 #include <stdplus/gtest/tmp.hpp>
 
 #include <filesystem>
+#include <format>
 
 namespace stdplus
 {
@@ -10,7 +9,7 @@
 {
 
 TestWithTmp::TestWithTmp() :
-    casedir(fmt::format(
+    casedir(std::format(
         "{}/{}", SuiteTmpDir(),
         ::testing::UnitTest::GetInstance()->current_test_info()->name()))
 {
@@ -39,7 +38,7 @@
     {
         dir = "/tmp";
     }
-    return fmt::format(
+    return std::format(
         "{}/{}-{}", dir,
         ::testing::UnitTest::GetInstance()->current_test_suite()->name(),
         getpid());
diff --git a/src/net/addr/subnet.cpp b/src/net/addr/subnet.cpp
index 90fb702..1feb000 100644
--- a/src/net/addr/subnet.cpp
+++ b/src/net/addr/subnet.cpp
@@ -1,7 +1,6 @@
-#include <fmt/format.h>
-
 #include <stdplus/net/addr/subnet.hpp>
 
+#include <format>
 #include <stdexcept>
 
 namespace stdplus
@@ -12,7 +11,7 @@
 
 void invalidSubnetPfx(std::size_t pfx)
 {
-    throw std::invalid_argument(fmt::format("Invalid subnet prefix {}", pfx));
+    throw std::invalid_argument(std::format("Invalid subnet prefix {}", pfx));
 }
 
 template class Subnet46<In4Addr, uint8_t>;
diff --git a/test/fd/atomic.cpp b/test/fd/atomic.cpp
index b49112c..c503a99 100644
--- a/test/fd/atomic.cpp
+++ b/test/fd/atomic.cpp
@@ -3,6 +3,7 @@
 #include <stdplus/gtest/tmp.hpp>
 
 #include <filesystem>
+#include <format>
 #include <memory>
 #include <string_view>
 
@@ -19,7 +20,7 @@
     std::string filename;
     std::unique_ptr<AtomicWriter> file;
 
-    AtomicWriterTest() : filename(fmt::format("{}/out", CaseTmpDir())) {}
+    AtomicWriterTest() : filename(std::format("{}/out", CaseTmpDir())) {}
 
     ~AtomicWriterTest() noexcept
     {
@@ -45,7 +46,7 @@
 
 TEST_F(AtomicWriterTest, BadCommit)
 {
-    auto tmp = fmt::format("{}/tmp.XXXXXX", CaseTmpDir());
+    auto tmp = std::format("{}/tmp.XXXXXX", CaseTmpDir());
     ASSERT_NO_THROW(
         file = std::make_unique<AtomicWriter>("/dev/null", 0644, tmp));
     writeExact(*file, "hi\n"sv);