mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
25 lines
555 B
C++
25 lines
555 B
C++
#include "utils.hpp"
|
|
|
|
#include <fstream>
|
|
#include <linux/limits.h>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
std::string readFile(const std::string &path) {
|
|
std::string string_rpath(PATH_MAX, '\0');
|
|
|
|
if (realpath(path.c_str(), string_rpath.data()) == nullptr) {
|
|
throw std::runtime_error("Failed to resolve the realpath to file " + path);
|
|
}
|
|
|
|
std::ifstream file(string_rpath);
|
|
|
|
if (!file.is_open()) {
|
|
throw std::runtime_error("Failed to open file: " + path);
|
|
}
|
|
|
|
std::stringstream buffer;
|
|
buffer << file.rdbuf();
|
|
|
|
return buffer.str();
|
|
} |