/* * This source code is released into the public domain. */ module; #include #include #include #include #include export module nihil:open_file; import :fd; namespace nihil { /* * Open the given file and return an fd for it. */ auto open_file(std::filesystem::path const &filename, int flags, int mode = 0777) -> std::expected { auto fdno = ::open(filename.c_str(), flags, mode); if (fdno != -1) return fd(fdno); return std::unexpected(std::make_error_code(std::errc(errno))); } } // namespace nihil