/*
 * Copyright 2016 - 2019 gtalent2@gmail.com
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <cstdio>

#include "../media.hpp"

namespace nostalgia::core {

uint8_t *loadRom(const char *path) {
	auto file = fopen(path, "r");
	if (file) {
		fseek(file, 0, SEEK_END);
		const auto size = ftell(file);
		rewind(file);
		auto buff = new uint8_t[size];
		fread(buff, size, 1, file);
		fclose(file);
		return buff;
	} else {
		return nullptr;
	}
}

void unloadRom(uint8_t *rom) {
	delete rom;
}

}

/*
 * Copyright 2016 - 2019 gtalent2@gmail.com
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <fstream>

#include <ox/std/trace.hpp>

#include "../media.hpp"

namespace nostalgia::core {

uint8_t *loadRom(const char *path) {
	std::ifstream file(path, std::ios::binary | std::ios::ate);
	if (!file.good()) {
		oxTrace("nostalgia::core::userland::loadRom") << "Read failed:" << path;
		return nullptr;
	}

	const std::size_t size = file.tellg();
	file.seekg(0, std::ios::beg);
	auto buff = new uint8_t[size];
	file.read(reinterpret_cast<char*>(buff), size);
	return buff;
}

void unloadRom(uint8_t *rom) {
	delete rom;
}

}

Replace C file I/O with C++ file I/O to comply with handbook
[nostalgia/core/userland] Replace C file I/O with C++ file I/O to comply with handbook
