Moved read_file to a general base library

This commit is contained in:
2024-04-15 04:53:42 +06:30
parent 0385d4bb8d
commit f661438c93
4 changed files with 54 additions and 19 deletions

View File

@@ -20,28 +20,11 @@
#include <lib/inst.h>
#include "./base.hpp"
#include "./lexer.hpp"
using std::pair, std::string, std::string_view, std::vector;
std::optional<string> read_file(const char *filename)
{
FILE *fp = fopen(filename, "rb");
if (fp)
{
string contents;
fseek(fp, 0, SEEK_END);
contents.resize(ftell(fp));
rewind(fp);
fread(&contents[0], 1, contents.size(), fp);
fclose(fp);
return contents;
}
else
return std::nullopt;
}
void usage(const char *program_name, FILE *fp)
{
fprintf(fp,