fd: Add MMap handle object
This makes it possible to have an RAII managed MMap
Change-Id: Id61cea650a68087ca9d263a57dd780791845eb85
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/fd/mmap.cpp b/test/fd/mmap.cpp
new file mode 100644
index 0000000..3f1ab33
--- /dev/null
+++ b/test/fd/mmap.cpp
@@ -0,0 +1,26 @@
+#include <array>
+#include <gtest/gtest.h>
+#include <stdplus/fd/create.hpp>
+#include <stdplus/fd/mmap.hpp>
+
+namespace stdplus
+{
+namespace fd
+{
+
+TEST(MMap, Basic)
+{
+ auto fd = open("/dev/zero", OpenAccess::ReadOnly);
+ auto map = MMap(fd, 32, ProtFlags().set(ProtFlag::Read),
+ MMapFlags{MMapAccess::Private}, 0);
+ auto sp = map.get();
+ ASSERT_NE(nullptr, sp.data());
+ ASSERT_EQ(32, sp.size());
+ for (size_t i = 0; i < 32; ++i)
+ {
+ EXPECT_EQ(sp[i], std::byte{});
+ }
+}
+
+} // namespace fd
+} // namespace stdplus