l/glrage: replace std::ifstream with FILE*

This commit is contained in:
rr- 2021-11-29 11:51:03 +01:00
parent ac3f4d5029
commit 5150a19cb7
No known key found for this signature in database
GPG key ID: CC65E6FD28CAE42A

View file

@ -4,8 +4,6 @@
#include <glrage_util/ErrorUtils.hpp> #include <glrage_util/ErrorUtils.hpp>
#include <glrage_util/StringUtils.hpp> #include <glrage_util/StringUtils.hpp>
#include <fstream>
#include <sstream>
#include <string> #include <string>
namespace glrage { namespace glrage {
@ -31,21 +29,21 @@ void Shader::bind()
Shader& Shader::fromFile(const std::string& path) Shader& Shader::fromFile(const std::string& path)
{ {
// open and check shader file FILE* fp = fopen(path.c_str(), "rb");
std::ifstream file; if (!fp) {
file.open(path.c_str());
if (!file.good()) {
throw std::runtime_error("Can't open shader file '" + path + throw std::runtime_error("Can't open shader file '" + path +
"': " + ErrorUtils::getSystemErrorString()); "': " + ErrorUtils::getSystemErrorString());
} }
// read file to a string stream fseek(fp, 0, SEEK_END);
std::stringstream stream; const auto size = ftell(fp);
stream << file.rdbuf(); fseek(fp, 0, SEEK_SET);
file.close();
// convert stream to string std::string content(size + 1, '\0');
fromString(stream.str()); fread(&content[0], 1, size, fp);
fclose(fp);
fromString(content.c_str());
return *this; return *this;
} }