Skip to content

Commit

Permalink
Use C style file reading in main.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
majetideepak committed Sep 18, 2023
1 parent 19f8399 commit 77e951c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions parser/cpp/main.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

#include "SqlParserConstants.h"
Expand All @@ -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;
}

Expand Down

0 comments on commit 77e951c

Please sign in to comment.