From 77e951cc0940a86e6f9957cf27f52fd0d81981b0 Mon Sep 17 00:00:00 2001 From: Deepak Majeti Date: Mon, 18 Sep 2023 11:26:46 -0400 Subject: [PATCH] Use C style file reading in main.cc --- parser/cpp/main.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/parser/cpp/main.cc b/parser/cpp/main.cc index c46465a..e1e2807 100644 --- a/parser/cpp/main.cc +++ b/parser/cpp/main.cc @@ -1,7 +1,7 @@ -#include #include #include #include +#include #include #include "SqlParserConstants.h" @@ -17,14 +17,21 @@ using namespace commonsql::parser; using namespace std; +static constexpr int kBufferSize = 128; + JAVACC_STRING_TYPE ReadFileFully(char *file_name) { JAVACC_STRING_TYPE s; - ifstream fp_in; - fp_in.open(file_name, ios::in); + // fstream includes math.h and conflicts with the DOMAIN keyword on MacOS. + // See: https://github.com/prestodb/sql/pull/45 + // Use C style file reading to avoid this conflict. + FILE* fp = fopen(file_name, "r"); + assert(fp != NULL); + char buffer[kBufferSize]; // Very inefficient. - while (!fp_in.eof()) { - s += fp_in.get(); + while (!fgets(buffer, kBufferSize, fp )) { + s.append(buffer, kBufferSize); } + s.append(buffer, strlen(buffer)); return s; }