blob: 8efcb1e1c6b62847b4aa540c7007723239c4911e [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "fidl/source_manager.h"
namespace fidl {
bool SourceManager::CreateSource(StringView filename) {
FILE* file = fopen(filename.data(), "rb");
if (!file)
return false;
// The lexer requires zero terminated data.
std::string data;
fseek(file, 0, SEEK_END);
auto filesize = ftell(file);
data.resize(filesize + 1);
rewind(file);
fread(&data[0], 1, filesize, file);
data[filesize] = 0;
fclose(file);
sources_.push_back(std::make_unique<SourceFile>(filename, std::move(data)));
return true;
}
} // namespace fidl