// open a RAM-based "file" using the given data and length (read-only) /*------------------------------------------------- * open_ram - open a RAM-based buffer for file- * like access and return an error code * -------------------------------------------------*/ public static std.error_condition open_ram(MemoryU8 data, size_t length, uint32_t openflags, out core_file file) //std::error_condition open_ram(void const *data, std::size_t length, std::uint32_t openflags, ptr &file) { file = null; // can only do this for read access if ((openflags & OPEN_FLAG_WRITE) != 0 || (openflags & OPEN_FLAG_CREATE) != 0) { return(std.errc.invalid_argument); } // if length is non-zero, data must be non-null if (length != 0 && data == null) { return(std.errc.invalid_argument); } // platforms where size_t is larger than 64 bits are theoretically possible //if (std::uint64_t(length) != length) // return std::errc::file_too_large; core_file result = new core_in_memory_file(openflags, data, length, false); //ptr result = new core_in_memory_file(openflags, data, length, false); if (result == null) { return(std.errc.not_enough_memory); } file = result; return(new std.error_condition()); }
//typedef std::unique_ptr<core_file> ptr; // ----- file open/close ----- // open a file with the specified filename public static std.error_condition open(string filename, uint32_t openflags, out core_file file) { file = null; // attempt to open the file osd_file f; uint64_t length = 0; var filerr = m_osdfile.open(filename, openflags, out f, out length); // FIXME: allow osd_file to accept std::string_view if (filerr) { return(filerr); } try { file = new core_osd_file(openflags, f, length); } catch (Exception) { return(std.errc.not_enough_memory); } return(new std.error_condition()); }